/// <inheritdoc/>
        public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination)
        {
            MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns);
            int nCols = selectedColumns.Length;

            if ((destination.Length < selectedRows.Length) ||
                (destination[0].Length < nCols))
            {
                throw new MatrixDimensionMismatchException(destination.Length, destination[0].Length,
                                                           selectedRows.Length, selectedColumns.Length);
            }

            for (int i = 0; i < selectedRows.Length; i++)
            {
                double[] destinationI = destination[i];
                if (destinationI.Length < nCols)
                {
                    throw new MatrixDimensionMismatchException(destination.Length, destinationI.Length,
                                                               selectedRows.Length, selectedColumns.Length);
                }
                for (int j = 0; j < selectedColumns.Length; j++)
                {
                    destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]);
                }
            }
        }
        /// <inheritdoc/>
        public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
        {
            MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns);

            RealMatrix subMatrix = createMatrix(selectedRows.Length, selectedColumns.Length);

            subMatrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitorAnonymous1(ref selectedRows, ref selectedColumns, this));

            return(subMatrix);
        }
Beispiel #3
0
 /// <inheritdoc/>
 public new double walkInColumnOrder(RealMatrixPreservingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
 {
     MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
     visitor.start(getRowDimension(), getColumnDimension(),
                   startRow, endRow, startColumn, endColumn);
     for (int j = startColumn; j <= endColumn; ++j)
     {
         for (int i = startRow; i <= endRow; ++i)
         {
             visitor.visit(i, j, data[i][j]);
         }
     }
     return(visitor.end());
 }
 /// <inheritdoc/>
 public double walkInColumnOrder(RealMatrixPreservingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
 {
     MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
     visitor.start(getRowDimension(), getColumnDimension(),
                   startRow, endRow, startColumn, endColumn);
     for (int column = startColumn; column <= endColumn; ++column)
     {
         for (int row = startRow; row <= endRow; ++row)
         {
             visitor.visit(row, column, getEntry(row, column));
         }
     }
     return(visitor.end());
 }
Beispiel #5
0
 /// <inheritdoc/>
 public new double walkInRowOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
 {
     MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
     visitor.start(getRowDimension(), getColumnDimension(),
                   startRow, endRow, startColumn, endColumn);
     for (int i = startRow; i <= endRow; ++i)
     {
         double[] rowI = data[i];
         for (int j = startColumn; j <= endColumn; ++j)
         {
             rowI[j] = visitor.visit(i, j, rowI[j]);
         }
     }
     return(visitor.end());
 }
 /// <inheritdoc/>
 public double walkInRowOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
 {
     MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
     visitor.start(getRowDimension(), getColumnDimension(),
                   startRow, endRow, startColumn, endColumn);
     for (int row = startRow; row <= endRow; ++row)
     {
         for (int column = startColumn; column <= endColumn; ++column)
         {
             double oldValue = getEntry(row, column);
             double newValue = visitor.visit(row, column, oldValue);
             setEntry(row, column, newValue);
         }
     }
     return(visitor.end());
 }
        /// <inheritdoc/>
        public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
        {
            MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);

            RealMatrix subMatrix =
                createMatrix(endRow - startRow + 1, endColumn - startColumn + 1);

            for (int i = startRow; i <= endRow; ++i)
            {
                for (int j = startColumn; j <= endColumn; ++j)
                {
                    subMatrix.setEntry(i - startRow, j - startColumn, getEntry(i, j));
                }
            }

            return(subMatrix);
        }
        /// <inheritdoc/>
        public void copySubMatrix(int startRow, int endRow, int startColumn, int endColumn, double[][] destination)
        {
            MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
            int rowsCount    = endRow + 1 - startRow;
            int columnsCount = endColumn + 1 - startColumn;

            if ((destination.Length < rowsCount) || (destination[0].Length < columnsCount))
            {
                throw new MatrixDimensionMismatchException(destination.Length, destination[0].Length,
                                                           rowsCount, columnsCount);
            }

            for (int i = 1; i < rowsCount; i++)
            {
                if (destination[i].Length < columnsCount)
                {
                    throw new MatrixDimensionMismatchException(destination.Length, destination[i].Length,
                                                               rowsCount, columnsCount);
                }
            }

            walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitorAnonymous1(ref destination), startRow, endRow, startColumn, endColumn);
        }