예제 #1
0
 public static void getd1(Floatarray image, Floatarray slice, int index)
 {
     slice.Resize(image.Dim(0));
     for (int i = 0; i < image.Dim(0); i++)
     {
         slice.UnsafePut(i, image.UnsafeAt(i, index));
     }
 }
예제 #2
0
 public static void putd1 <T, S>(Floatarray image, Floatarray slice, int index)
 {
     if (!(slice.Rank() == 1 && slice.Dim(0) == image.Dim(0)))
     {
         throw new Exception("ASSERT: slice.Rank()==1 && slice.Dim(0)==image.Dim(1)");
     }
     for (int i = 0; i < image.Dim(0); i++)
     {
         image.UnsafePut(i, index, slice.UnsafeAt(i));
     }
 }
예제 #3
0
        protected static void outer_add(Floatarray a, Floatarray u, Floatarray v, float eps)
        {
            int n = a.Dim(0);
            int m = a.Dim(1);

            CHECK_ARG(n == u.Length(), "n == u.Length()");
            CHECK_ARG(m == v.Length(), "m == v.Length()");
            if (count_zeros(u) >= count_zeros(v))
            {
                for (int i = 0; i < n; i++)
                {
                    if (u.UnsafeAt(i) == 0)
                    {
                        continue;
                    }
                    for (int j = 0; j < m; j++)
                    {
                        a.UnsafePut(i, j, a.UnsafeAt(i, j) + (eps * u.UnsafeAt(i) * v.UnsafeAt(j)));
                    }
                }
            }
            else
            {
                for (int j = 0; j < m; j++)
                {
                    if (v.UnsafeAt(j) == 0)
                    {
                        continue;
                    }
                    for (int i = 0; i < n; i++)
                    {
                        a.UnsafePut(i, j, a.UnsafeAt(i, j) + (eps * u.UnsafeAt(i) * v.UnsafeAt(j)));
                    }
                }
            }
        }
예제 #4
0
        protected static void vmmul0(Floatarray result, Floatarray v, Floatarray a)
        {
            int n = a.Dim(0);
            int m = a.Dim(1);

            CHECK_ARG(n == v.Length(), "n == v.Length()");
            result.Resize(m);
            result.Fill(0f);
            for (int i = 0; i < n; i++)
            {
                float value = v.UnsafeAt(i);//v[i];
                if (value == 0f)
                {
                    continue;
                }
                for (int j = 0; j < m; j++)
                {
                    result.UnsafePut(j, result.UnsafeAt(j) + (a.UnsafeAt(i, j) * value));
                }
            }
        }
예제 #5
0
 protected static void vmmul0(Floatarray result, Floatarray v, Floatarray a)
 {
     int n = a.Dim(0);
     int m = a.Dim(1);
     CHECK_ARG(n == v.Length(), "n == v.Length()");
     result.Resize(m);
     result.Fill(0f);
     for (int i = 0; i < n; i++)
     {
         float value = v.UnsafeAt(i);//v[i];
         if (value == 0f)
             continue;
         for (int j = 0; j < m; j++)
             result.UnsafePut(j, result.UnsafeAt(j) + (a.UnsafeAt(i, j) * value));
     }
 }
예제 #6
0
 protected static void outer_add(Floatarray a, Floatarray u, Floatarray v, float eps)
 {
     int n = a.Dim(0);
     int m = a.Dim(1);
     CHECK_ARG(n == u.Length(), "n == u.Length()");
     CHECK_ARG(m == v.Length(), "m == v.Length()");
     if (count_zeros(u) >= count_zeros(v))
     {
         for (int i = 0; i < n; i++)
         {
             if (u.UnsafeAt(i) == 0) continue;
             for (int j = 0; j < m; j++)
             {
                 a.UnsafePut(i, j, a.UnsafeAt(i, j) + (eps * u.UnsafeAt(i) * v.UnsafeAt(j)));
             }
         }
     }
     else
     {
         for (int j = 0; j < m; j++)
         {
             if (v.UnsafeAt(j) == 0) continue;
             for (int i = 0; i < n; i++)
             {
                 a.UnsafePut(i, j, a.UnsafeAt(i, j) + (eps * u.UnsafeAt(i) * v.UnsafeAt(j)));
             }
         }
     }
 }