Exemplo n.º 1
0
 /// <summary>
 /// Division outarray[i] / val
 /// </summary>
 public static void Div(Intarray outarray, int val)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, outarray.At1d(i) / val);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Subtraction val - outarray[i]
 /// </summary>
 public static void Sub(int val, Intarray outarray)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.Put1d(i, val - outarray.At1d(i));
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add outarray[i] + val
 /// </summary>
 public static void Add(Intarray outarray, int val)
 {
     for (int i = 0; i < outarray.Length1d(); i++)
     {
         outarray.UnsafePut1d(i, outarray.UnsafeAt1d(i) + val);
     }
 }
Exemplo n.º 4
0
 public static void RPermutation(Intarray index, int n)
 {
     index.Resize(n);
     for (int i = 0; i < n; i++)
     {
         index.UnsafePut1d(i, i);
     }
     Shuffle(index);
 }
Exemplo n.º 5
0
        public static Intarray operator /(Intarray array, int val)
        {
            Intarray res = array;

            for (int i = 0; i < array.Length1d(); i++)
            {
                res.UnsafePut1d(i, array.UnsafeAt1d(i) / val);
            }
            return(res);
        }
Exemplo n.º 6
0
        public static Intarray operator *(Intarray array, int val)
        {
            Intarray res = array;

            check_range(res.Length1d() - 1, array.Length1d());
            for (int i = 0; i < array.Length1d(); i++)
            {
                res.UnsafePut1d(i, array.UnsafeAt1d(i) * val);
            }
            return(res);
        }
Exemplo n.º 7
0
        public static void Shuffle <T>(Narray <T> values)
        {
            Floatarray temp  = new Floatarray(values.Length());
            Intarray   index = new Intarray();

            for (int i = 0; i < temp.Length(); i++)
            {
                temp.UnsafePut1d(i, DRandomizer.Default.drand());
            }
            Quicksort(index, temp);
            Permute(values, index);
        }
Exemplo n.º 8
0
        public static Intarray operator -(Intarray outarray1, Intarray array2)
        {
            if (!SameDims(outarray1, array2))
            {
                throw new Exception("outarray1 and array2 must be same dims!");
            }
            Intarray res = outarray1;

            for (int i = 0; i < outarray1.Length1d(); i++)
            {
                res.UnsafePut1d(i, outarray1.UnsafeAt1d(i) - array2.UnsafeAt1d(i));
            }
            return(res);
        }
Exemplo n.º 9
0
        public static int Max(Intarray a)
        {
            int value = a.At1d(0);

            for (int i = 1; i < a.Length1d(); i++)
            {
                int nvalue = a.At1d(i);
                if (nvalue <= value)
                {
                    continue;
                }
                value = nvalue;
            }
            return(value);
        }
Exemplo n.º 10
0
        public static int ArgMin(Intarray a)
        {
            if (!(/*a.Rank() == 1 && **/ a.Dim(0) > 0))
            {
                throw new Exception("CHECK_ARG: a.Rank()==1 && a.Dim(0)>0");
            }
            int value = a.At1d(0);
            int index = 0;

            for (int i = 1; i < a.Length1d(); i++)
            {
                int nvalue = a.At1d(i);
                if (nvalue >= value)
                {
                    continue;
                }
                value = nvalue;
                index = i;
            }
            return(index);
        }