Exemplo n.º 1
0
 /// <summary>
 /// Test if two vectors are component-wise close using a symmetric tolerance interval.
 /// </summary>
 public static bool Close(IVector a, IVector b, double eps)
 {
     for (int i = 0; i < a.Dimensions; ++i)
     {
         if (!FloatComparison.Close(a[i], b[i], eps))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Normalize the given vector using the L2 norm.
        /// </summary>
        public static double Normalize <T>(IVector a, ref T dest) where T : IVector
        {
            double len = VectorReductions.L2Norm(a);

            if (FloatComparison.CloseZero(len, FloatComparison.DefaultEps))
            {
                throw new DivideByZeroException();
            }
            double inv_len = 1.0 / len;

            for (int i = 0; i < a.Dimensions; ++i)
            {
                dest[i] = a[i] * inv_len;
            }
            return(len);
        }