/** * Check if submatrix ranges indices are valid. * Rows and columns are indicated counting from 0 to n-1. * * @param startRow Initial row index * @param endRow Final row index * @param startColumn Initial column index * @param endColumn Final column index * @exception MatrixIndexException if the indices are not valid */ protected void checkSubMatrixIndex(final int startRow, final int endRow, final int startColumn, final int endColumn) { checkRowIndex(startRow); checkRowIndex(endRow); if (startRow > endRow) { throw new MatrixIndexException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW, startRow, endRow); } checkColumnIndex(startColumn); checkColumnIndex(endColumn); if (startColumn > endColumn) { throw new MatrixIndexException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN, startColumn, endColumn); } }
/** {@inheritDoc} */ public T[] getRow(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final T[] out = buildArray(field, nCols); for (int i = 0; i < nCols; ++i) { out[i] = getEntry(row, i); } return out; }
/** {@inheritDoc} */ public T[] getRow(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final T[] out = buildArray(field, nCols); for (int i = 0; i < nCols; ++i) { out[i] = getEntry(row, i); } return out; }
/** {@inheritDoc} */ public void setRow(final int row, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); } }
/** * Check if submatrix ranges indices are valid. * Rows and columns are indicated counting from 0 to n-1. * * @param startRow Initial row index * @param endRow Final row index * @param startColumn Initial column index * @param endColumn Final column index * @exception MatrixIndexException if the indices are not valid */ protected void checkSubMatrixIndex(final int startRow, final int endRow, final int startColumn, final int endColumn) { checkRowIndex(startRow); checkRowIndex(endRow); if (startRow > endRow) { throw new MatrixIndexException("initial row {0} after final row {1}", startRow, endRow); } checkColumnIndex(startColumn); checkColumnIndex(endColumn); if (startColumn > endColumn) { throw new MatrixIndexException("initial column {0} after final column {1}", startColumn, endColumn); } }
/** {@inheritDoc} */ public void setRow(final int row, final T[] array) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (array.length != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, array.length, 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, array[i]); } }
/** {@inheritDoc} */ public FieldMatrix<T> getRowMatrix(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final FieldMatrix<T> out = createMatrix(1, nCols); for (int i = 0; i < nCols; ++i) { out.setEntry(0, i, getEntry(row, i)); } return out; }
/** * Check if submatrix ranges indices are valid. * Rows and columns are indicated counting from 0 to n-1. * * @param selectedRows Array of row indices. * @param selectedColumns Array of column indices. * @exception MatrixIndexException if row or column selections are not valid */ protected void checkSubMatrixIndex(final int[] selectedRows, final int[] selectedColumns) { if (selectedRows.length * selectedColumns.length == 0) { if (selectedRows.length == 0) { throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_ROW_INDEX_ARRAY); } throw new MatrixIndexException(LocalizedFormats.EMPTY_SELECTED_COLUMN_INDEX_ARRAY); } for (final int row : selectedRows) { checkRowIndex(row); } for (final int column : selectedColumns) { checkColumnIndex(column); } }
/** {@inheritDoc} */ public FieldMatrix<T> getRowMatrix(final int row) throws MatrixIndexException { checkRowIndex(row); final int nCols = getColumnDimension(); final FieldMatrix<T> out = createMatrix(1, nCols); for (int i = 0; i < nCols; ++i) { out.setEntry(0, i, getEntry(row, i)); } return out; }
/** * Check if submatrix ranges indices are valid. * Rows and columns are indicated counting from 0 to n-1. * * @param selectedRows Array of row indices. * @param selectedColumns Array of column indices. * @exception MatrixIndexException if row or column selections are not valid */ protected void checkSubMatrixIndex(final int[] selectedRows, final int[] selectedColumns) { if (selectedRows.length * selectedColumns.length == 0) { if (selectedRows.length == 0) { throw new MatrixIndexException("empty selected row index array"); } throw new MatrixIndexException("empty selected column index array"); } for (final int row : selectedRows) { checkRowIndex(row); } for (final int column : selectedColumns) { checkColumnIndex(column); } }
/** {@inheritDoc} */ public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws MatrixIndexException { final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.DIFFERENT_ROWS_LENGTHS, nCols, subMatrix[r].length); } } checkRowIndex(row); checkColumnIndex(column); checkRowIndex(nRows + row - 1); checkColumnIndex(nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } }
/** {@inheritDoc} */ public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws MatrixIndexException { final int nRows = subMatrix.length; if (nRows == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row"); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column"); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw MathRuntimeException.createIllegalArgumentException( "some rows have length {0} while others have length {1}", nCols, subMatrix[r].length); } } checkRowIndex(row); checkColumnIndex(column); checkRowIndex(nRows + row - 1); checkColumnIndex(nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } }
/** {@inheritDoc} */ public void setRowVector(final int row, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } }
/** {@inheritDoc} */ public void setRowVector(final int row, final FieldVector<T> vector) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if (vector.getDimension() != nCols) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", 1, vector.getDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, vector.getEntry(i)); } }
/** {@inheritDoc} */ public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( LocalizedFormats.DIMENSIONS_MISMATCH_2x2, matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } }
/** {@inheritDoc} */ public void setRowMatrix(final int row, final FieldMatrix<T> matrix) throws MatrixIndexException, InvalidMatrixException { checkRowIndex(row); final int nCols = getColumnDimension(); if ((matrix.getRowDimension() != 1) || (matrix.getColumnDimension() != nCols)) { throw new InvalidMatrixException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", matrix.getRowDimension(), matrix.getColumnDimension(), 1, nCols); } for (int i = 0; i < nCols; ++i) { setEntry(row, i, matrix.getEntry(0, i)); } }