예제 #1
0
        public static float Max(Floatarray a)
        {
            float value = a.At1d(0);

            for (int i = 1; i < a.Length1d(); i++)
            {
                float nvalue = a.At1d(i);
                if (nvalue <= value)
                {
                    continue;
                }
                value = nvalue;
            }
            return(value);
        }
예제 #2
0
 /// <summary>
 /// Division outarray[i] / val
 /// </summary>
 public static void Div(Floatarray outarray, float val)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, outarray.At1d(i) / val);
     }
 }
예제 #3
0
 /// <summary>
 /// Subtraction val - outarray[i]
 /// </summary>
 public static void Sub(float val, Floatarray outarray)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, val - outarray.At1d(i));
     }
 }
예제 #4
0
        /// <summary>
        /// Normalize the Euclidean norm of the array.
        /// </summary>
        public static void Normalize2(Floatarray a)
        {
            double scale = 1.0 / Norm2(a);

            for (int i = 0; i < a.Length1d(); i++)
            {
                a.Put1d(i, (float)(a.At1d(i) * scale));
            }
        }
예제 #5
0
        /// <summary>
        /// Euclidean norm squared.
        /// </summary>
        public static double Norm2Squared(Floatarray a)
        {
            double total = 0.0;

            for (int i = 0; i < a.Length1d(); i++)
            {
                float value = a.At1d(i);
                total += value * value;
            }
            return(total);
        }
예제 #6
0
        public static int ArgMin(Floatarray a)
        {
            if (!(/*a.Rank() == 1 && **/ a.Dim(0) > 0))
            {
                throw new Exception("CHECK_ARG: a.Rank()==1 && a.Dim(0)>0");
            }
            float value = a.At1d(0);
            int   index = 0;

            for (int i = 1; i < a.Length1d(); i++)
            {
                float nvalue = a.At1d(i);
                if (nvalue >= value)
                {
                    continue;
                }
                value = nvalue;
                index = i;
            }
            return(index);
        }
예제 #7
0
        /// <summary>
        /// Euclidean distance squared.
        /// </summary>
        public static double Dist2Squared(Floatarray a, Floatarray b)
        {
            if (!a.SameDims(b))
            {
                throw new Exception("Dist2Squared: !a.SameDims(b)");
            }
            double total = 0.0;

            for (int i = 0; i < a.Length1d(); i++)
            {
                float val = a.At1d(i) - b.At1d(i);
                total += val * val;
            }
            if (double.IsNaN(total))
            {
                throw new Exception("Dist2Squared: total is NaN !");
            }
            return(total);
        }