Esempio n. 1
0
        public static float DotProductSparse(ReadOnlySpan <float> left, ReadOnlySpan <float> right, ReadOnlySpan <int> indices, int count)
        {
            Contracts.AssertNonEmpty(left);
            Contracts.AssertNonEmpty(right);
            Contracts.AssertNonEmpty(indices);
            Contracts.Assert(count > 0);
            Contracts.Assert(count < left.Length);
            Contracts.Assert(count <= right.Length);
            Contracts.Assert(count <= indices.Length);

            if (Avx.IsSupported)
            {
                return(AvxIntrinsics.DotSU(left, right, indices, count));
            }
            else if (Sse.IsSupported)
            {
                return(SseIntrinsics.DotSU(left, right, indices, count));
            }
            else
            {
                float result = 0;
                for (int i = 0; i < count; i++)
                {
                    int index = indices[i];
                    result += left[index] * right[i];
                }
                return(result);
            }
        }
        public static float DotProductSparse(ReadOnlySpan <float> a, ReadOnlySpan <float> b, ReadOnlySpan <int> indices, int count)
        {
            Contracts.AssertNonEmpty(a);
            Contracts.AssertNonEmpty(b);
            Contracts.AssertNonEmpty(indices);
            Contracts.Assert(count > 0);
            Contracts.Assert(count < a.Length);
            Contracts.Assert(count <= b.Length);
            Contracts.Assert(count <= indices.Length);

            if (Avx.IsSupported)
            {
                return(AvxIntrinsics.DotSU(a, b, indices, count));
            }
            else if (Sse.IsSupported)
            {
                return(SseIntrinsics.DotSU(a, b, indices, count));
            }
            else
            {
                float result = 0;
                for (int i = 0; i < count; i++)
                {
                    int index = indices[i];
                    result += a[index] * b[i];
                }
                return(result);
            }
        }
Esempio n. 3
0
 private static float DotProductSparse(Span <float> a, Span <float> b, Span <int> indices)
 {
     if (Sse.IsSupported)
     {
         return(SseIntrinsics.DotSU(a, b, indices));
     }
     else
     {
         float result = 0;
         for (int i = 0; i < indices.Length; i++)
         {
             int index = indices[i];
             result += a[index] * b[i];
         }
         return(result);
     }
 }