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

            if (Avx.IsSupported)
            {
                return(AvxIntrinsics.Dist2(left, right, count));
            }
            else if (Sse.IsSupported)
            {
                return(SseIntrinsics.Dist2(left, right, count));
            }
            else
            {
                float norm = 0;
                for (int i = 0; i < count; i++)
                {
                    float distance = left[i] - right[i];
                    norm += distance * distance;
                }
                return(norm);
            }
        }
        public static float L2DistSquared(ReadOnlySpan <float> a, ReadOnlySpan <float> b, int count)
        {
            Contracts.AssertNonEmpty(a);
            Contracts.AssertNonEmpty(b);
            Contracts.Assert(count > 0);
            Contracts.Assert(count <= a.Length);
            Contracts.Assert(count <= b.Length);

            if (Avx.IsSupported)
            {
                return(AvxIntrinsics.Dist2(a, b, count));
            }
            else if (Sse.IsSupported)
            {
                return(SseIntrinsics.Dist2(a, b, count));
            }
            else
            {
                float norm = 0;
                for (int i = 0; i < count; i++)
                {
                    float distance = a[i] - b[i];
                    norm += distance * distance;
                }
                return(norm);
            }
        }
Exemplo n.º 3
0
 private static float L2DistSquared(Span <float> a, Span <float> b)
 {
     if (Sse.IsSupported)
     {
         return(SseIntrinsics.Dist2(a, b));
     }
     else
     {
         float norm = 0;
         for (int i = 0; i < b.Length; i++)
         {
             float distance = a[i] - b[i];
             norm += distance * distance;
         }
         return(norm);
     }
 }