示例#1
0
        public NumericMatrix <V> extract(SpreadSheetRange <AI1, AI2> range)
        {
            // Slice a matrix
            AI1 rmin = range.upperLeft.first;
            AI2 cmin = range.upperLeft.second;

            AI1 rmax = range.lowerRight.first;
            AI2 cmax = range.lowerRight.second;

            int Rmin = r[rmin]; int Rmax = r[rmax];
            int Cmin = c[cmin]; int Cmax = c[cmax];

            // Now must find the integer indices corresponding to these
            NumericMatrix <V> result = new NumericMatrix <V>(Rmax - Rmin + 1, Cmax - Cmin + 1, Rmin, Cmin);

            for (int ri = Rmin; ri <= Rmax; ri++)
            {
                for (int ci = Cmin; ci <= Cmax; ci++)
                {
                    result[ri, ci] = mat[ri, ci];
                }
            }

            return(result);
        }
示例#2
0
 public AssocMatrix()
 {
     mat        = new NumericMatrix <V>(10, 10);
     r          = new AssocArray <AI1, int>();
     c          = new AssocArray <AI2, int>();
     keyRows    = new Set <AI1>();
     keyColumns = new Set <AI2>();
 }
示例#3
0
        public AssocMatrix(AssocMatrix <AI1, AI2, V> mat2)
        {
            mat = new NumericMatrix <V>(mat2.mat);
            r   = new AssocArray <AI1, int>(mat2.r);
            c   = new AssocArray <AI2, int>(mat2.c);

            keyRows    = new Set <AI1>(mat2.keyRows);
            keyColumns = new Set <AI2>(mat2.keyColumns);
        }
示例#4
0
        //Default constructor everything starts at 1 and has length 1
        public Tensor()
        {
            m_tensor    = new Array <NumericMatrix <T> >(1, 1);
            m_tensor[1] = new NumericMatrix <T>(1, 1, 1, 1);

            m_rows    = 1;
            m_columns = 1;
            m_depth   = 1;
        }
示例#5
0
        //Constructor with all sizes and startindexes
        public Tensor(int rows, int columns, int nthird, int rowStart, int columnStart, int thirdStart)
        {
            m_tensor = new Array <NumericMatrix <T> >(nthird, thirdStart); // Size nthird, start index

            for (int i = m_tensor.MinIndex; i <= m_tensor.MaxIndex; i++)
            {
                m_tensor[i] = new NumericMatrix <T>(rows, columns, rowStart, columnStart);
            }

            m_rows    = rows;
            m_columns = columns;
            m_depth   = nthird;
        }
示例#6
0
        //Constructor with the ammount of rows, columns and depth, all startindexes are 1.
        public Tensor(int rows, int columns, int nthird)
        {
            m_tensor = new Array <NumericMatrix <T> >(nthird, 1);

            for (int i = m_tensor.MinIndex; i <= m_tensor.MaxIndex; i++)
            {
                m_tensor[i] = new NumericMatrix <T>(rows, columns, 1, 1);
            }

            m_rows    = rows;
            m_columns = columns;
            m_depth   = nthird;
        }
示例#7
0
        // Matrix multiplication
        public static NumericMatrix <T> operator *(NumericMatrix <T> m1, NumericMatrix <T> m2)
        {
            NumericMatrix <T> result = new NumericMatrix <T>(m1.Rows, m2.Columns, m1.MinRowIndex, m1.MinColumnIndex);

            if (mulTT == null)
            {
                mulTT = GenericOperatorFactory <T, T, T, Vector <T> > .Multiply;
            }

            if (addTT == null)
            {
                addTT = GenericOperatorFactory <T, T, T, Vector <T> > .Add;
            }

            /*  OLD int i, j, k, l;
             *
             * for( i = result.MaxRowIndex; i >= result.MinRowIndex; i-- )
             * {
             *    for( j = result.MinColumnIndex; j <= result.MaxColumnIndex; j++ )
             *    {
             *        for( k = m1.MinColumnIndex, l = m2.MaxRowIndex; k <= m1.MaxColumnIndex; k++, l-- )
             *        {
             *            result[ i, j ] = addTT( result[ i, j ], mulTT( m1[ i, k ], m2[ l, j ] ) );
             *        }
             *    }
             * }*/

            // Index variables must be declared at this scope
            int i, j, k;

            for (i = result.MinRowIndex; i <= result.MaxRowIndex; i++)
            {
                for (j = result.MinColumnIndex; j <= result.MaxColumnIndex; j++)
                {
                    result[i, j] = mulTT(m1[i, m1.MinColumnIndex], m2[m2.MinRowIndex, j]);
                    for (k = m1.MinColumnIndex + 1; k <= m1.MaxColumnIndex; k++)
                    {
                        result[i, j] = addTT(result[i, j], mulTT(m1[i, k], m2[k, j]));
                    }
                }
            }

            return(result);
        }
示例#8
0
        //Copy constructor, does not make a deep copy when the internal types aren't primitive
        public Tensor(Tensor <T> tensor)
        {
            m_tensor = new Array <NumericMatrix <T> >(tensor.m_depth, tensor.MinThirdIndex);

            for (int i = m_tensor.MinIndex; i <= m_tensor.MaxIndex; i++)
            {
                m_tensor[i] = new NumericMatrix <T>(tensor.m_rows, tensor.m_columns, tensor.MinFirstIndex, tensor.MinSecondIndex);
            }

            for (int i = tensor.MinThirdIndex; i <= tensor.MaxThirdIndex; i++)
            {
                for (int j = tensor.MinSecondIndex; j <= tensor.MaxSecondIndex; j++)
                {
                    for (int k = tensor.MinFirstIndex; k <= tensor.MaxFirstIndex; k++)
                    {
                        m_tensor[i][k, j] = tensor[i][k, j];
                    }
                }
            }
        }
示例#9
0
        // Subtraction
        public static NumericMatrix <T> operator -(NumericMatrix <T> m1, NumericMatrix <T> m2)
        {
            NumericMatrix <T> temp_matrix = new NumericMatrix <T>(m1.Rows, m1.Columns, m1.MinRowIndex, m1.MinColumnIndex);

            int i, j;

            if (subTT == null)
            {
                subTT = GenericOperatorFactory <T, T, T, Vector <T> > .Subtract;
            }

            for (i = m1.MinColumnIndex; i <= m1.MaxColumnIndex; i++)
            {
                for (j = m1.MinRowIndex; j <= m1.MaxRowIndex; j++)
                {
                    //temp_matrix[ j, i ] = subTT( m1[ j, i ], m2[ j, i ] );
                    temp_matrix[j, i] = subTT(m1[j, i], m2[j, i]);
                }
            }
            return(temp_matrix);
        }
示例#10
0
        // Scalar multiplication
        public static NumericMatrix <T> operator *(T getal, NumericMatrix <T> m)
        {
            NumericMatrix <T> result = new NumericMatrix <T>(m.Rows, m.Columns, m.MinRowIndex, m.MinColumnIndex);

            int i, j;

            if (mulTT == null)
            {
                mulTT = GenericOperatorFactory <T, T, T, Vector <T> > .Multiply;
            }

            for (i = m.MinRowIndex; i <= m.MaxRowIndex; i++)
            {
                for (j = m.MinColumnIndex; j <= m.MaxColumnIndex; j++)
                {
                    result[i, j] = mulTT(getal, m[i, j]);
                }
            }

            return(result);
        }
示例#11
0
        // Operators

        // Addition
        public static NumericMatrix <T> operator +(NumericMatrix <T> m1, NumericMatrix <T> m2)
        {
            NumericMatrix <T> temp_matrix = new NumericMatrix <T>(m1.Rows, m1.Columns, m1.MinRowIndex, m1.MinColumnIndex);

            int i, j;

            if (addTT == null)
            {
                addTT = GenericOperatorFactory <T, T, T, Vector <T> > .Add;
                //addTT = new BinaryOperatorT<T, T, T>(GenericOperatorFactory<T, T, T, Vector<T>>.Add);
            }

            for (i = m1.MinColumnIndex; i <= m1.MaxColumnIndex; i++)
            {
                for (j = m1.MinRowIndex; j <= m1.MaxRowIndex; j++)
                {
                    temp_matrix[j, i] = addTT(m1[j, i], m2[j, i]);
                }
            }

            return(temp_matrix);
        }
示例#12
0
        // V2

        /*
         * // Construct the map from a list of names and a REPEATED val
         * AssocMatrix(V  rowStart, V columnStart,  NumericMatrix<V> matrix)
         * {
         *
         * // Must build the associative arrays, they have the same values as the
         * // indices in the matrix
         *
         * VectorCollectionGenerator<V> rowGenerator = new VectorCollectionGenerator<V>();
         * rowGenerator.Start = rowStart;
         * rowGenerator.Increment = new V();
         * rowGenerator.Size = matrix.Rows;
         *
         * VectorCollectionGenerator<V> columnGenerator = new VectorCollectionGenerator<V>();
         * columnGenerator.Start = columnStart;
         * columnGenerator.Increment = 1;
         * columnGenerator.Size = matrix.Columns;
         *
         * mat = new NumericMatrix<V>(matrix);
         *
         * //	keyRows = new SetCreator<V, int>.createSet(rowGenerator);
         * //keyColumns = new SetCreator<V, int>.createSet(columnGenerator);
         *
         *
         * // Build rows
         * int start = mat.MinRowIndex;
         * r = new AssocArray<AI1, int> ();
         *
         * foreach (AI1 row in keyRows)
         * {
         *    r[row] = start;
         *    start = start + 1;
         * }
         *
         * // Build columns
         * start = mat.MinColumnIndex;
         * c = new AssocArray<AI2, int>();
         *
         * foreach (AI2 col in keyColumns)
         * {
         *  c[col] = start;
         *  start = start + 1;
         * }
         *
         * // NO EXCEPTION HANDLING AT THE MOMENT
         * //print(c);
         * }
         *
         */
        public AssocMatrix(Set <AI1> Rnames, Set <AI2> Cnames,
                           NumericMatrix <V> matrix)
        {
            keyRows    = new Set <AI1>(Rnames);
            keyColumns = new Set <AI2>(Cnames);

            // Must build the associative arrays, they have the same values as the
            // indices in the matrix

            //mat = new NumericMatrix<V>(matrix);
            mat = matrix;

            // Build rows
            int start = mat.MinRowIndex;

            r = new AssocArray <AI1, int>();

            foreach (AI1 row in keyRows)
            {
                r[row] = start;
                start++;
            }

            // Build columns
            start = mat.MinColumnIndex;
            c     = new AssocArray <AI2, int>();

            foreach (AI2 col in keyColumns)
            {
                c[col] = start;
                start++;
            }

            // NO EXCEPTION HANDLING AT THE MOMENT
            //print(c);
        }
示例#13
0
 public NumericMatrix(NumericMatrix <T> source) : base(source)
 {
 }