Exemplo n.º 1
0
 public static void RowGet <T, S>(Narray <T> outv, Narray <S> data, int row)
 {
     outv.Resize(data.Dim(1));
     for (int i = 0; i < outv.Length(); i++)
     {
         outv[i] = (T)Convert.ChangeType(data[row, i], typeof(T));
     }
 }
Exemplo n.º 2
0
 public static void RowCopy <T>(Narray <T> a, Narray <T> b, int i)
 {
     a.Resize(b.Dim(1));
     for (int k = 0; k < b.Dim(1); k++)
     {
         a[k] = b[i, k];
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Quicksort an array, generating a permutation of the indexes.
 /// </summary>
 public static void Quicksort <T>(Narray <int> outindex, Narray <T> values)
 {
     outindex.Resize(values.Length());
     for (int i = 0; i < values.Length(); i++)
     {
         outindex[i] = i;
     }
     Quicksort(outindex, values, 0, outindex.Length());
 }
Exemplo n.º 4
0
        /// <summary>
        /// Make the first array have the same dimensions as the second array.
        /// </summary>
        public Narray <T> MakeLike <S>(Narray <S> b)
        {
            if (SameDims(b))
            {
                return(this);
            }
            Narray <T> a = this;
            int        r = b.Rank();

            switch (r)
            {
            case 0:
                a.Dealloc();
                break;

            case 1:
                a.Resize(b.Dim(0));
                break;

            case 2:
                a.Resize(b.Dim(0), b.Dim(1));
                break;

            case 3:
                a.Resize(b.Dim(0), b.Dim(1), b.Dim(2));
                break;

            case 4:
                a.Resize(b.Dim(0), b.Dim(1), b.Dim(2), b.Dim(3));
                break;

            default:
                throw new Exception("bad rank");
            }
            return(this);
        }
Exemplo n.º 5
0
 public void Resize(int n)
 {
     data.Dealloc();
     data.Resize(n);
 }