Exemplo n.º 1
0
        /**
         * Sets the value of this matrix to be the same as the value of the provided matrix.  Both
         * matrices must have the same shape:<br>
         * <br>
         * a<sub>ij</sub> = b<sub>ij</sub><br>
         * <br>
         *
         * @param b The matrix that this matrix is to be set equal to.
         */
        public void set(DMatrixD1 b)
        {
            this.reshape(b.numRows, b.numCols);

            int dataLength = b.getNumElements();

            Array.Copy(b.data, 0, this.data, 0, dataLength);
        }
Exemplo n.º 2
0
        /**
         * Creates a new iterator for traversing through a submatrix inside this matrix.  It can be traversed
         * by row or by column.  Range of elements is inclusive, e.g. minRow = 0 and maxRow = 1 will include rows
         * 0 and 1.  The iteration starts at (minRow,minCol) and ends at (maxRow,maxCol)
         *
         * @param a the matrix it is iterating through
         * @param rowMajor true means it will traverse through the submatrix by row first, false by columns.
         * @param minRow first row it will start at.
         * @param minCol first column it will start at.
         * @param maxRow last row it will stop at.
         * @param maxCol last column it will stop at.
         */
        public DMatrixIterator(DMatrixD1 a, bool rowMajor,
                               int minRow, int minCol, int maxRow, int maxCol
                               )
        {
            if (maxCol < minCol)
            {
                throw new ArgumentException("maxCol has to be more than or equal to minCol");
            }
            if (maxRow < minRow)
            {
                throw new ArgumentException("maxRow has to be more than or equal to minCol");
            }
            if (maxCol >= a.numCols)
            {
                throw new ArgumentException("maxCol must be < numCols");
            }
            if (maxRow >= a.numRows)
            {
                throw new ArgumentException("maxRow must be < numCRows");
            }

            this.a        = a;
            this.rowMajor = rowMajor;
            this.minCol   = minCol;
            this.minRow   = minRow;

            size = (maxCol - minCol + 1) * (maxRow - minRow + 1);

            if (rowMajor)
            {
                submatrixStride = maxCol - minCol + 1;
            }
            else
            {
                submatrixStride = maxRow - minRow + 1;
            }
        }