/** {@inheritDoc} */ @Override public T visit(final int row, final int column, final T value) { return getEntry(selectedRows[row], selectedColumns[column]); }
/** {@inheritDoc} */ public T[] getRow(final int row) throws OutOfRangeException { checkRowIndex(row); final int nCols = getColumnDimension(); final T[] out = MathArrays.buildArray(field, nCols); for (int i = 0; i < nCols; ++i) { out[i] = getEntry(row, i); } return out; }
/** {@inheritDoc} */ public T[][] getData() { final T[][] data = MathArrays.buildArray(field, getRowDimension(), getColumnDimension()); for (int i = 0; i < data.length; ++i) { final T[] dataI = data[i]; for (int j = 0; j < dataI.length; ++j) { dataI[j] = getEntry(i, j); } } return data; }
/** {@inheritDoc} */ public T[] getColumn(final int column) throws OutOfRangeException { checkColumnIndex(column); final int nRows = getRowDimension(); final T[] out = MathArrays.buildArray(field, nRows); for (int i = 0; i < nRows; ++i) { out[i] = getEntry(i, column); } return out; }
/** {@inheritDoc} */ public FieldMatrix<T> getSubMatrix(final int startRow, final int endRow, final int startColumn, final int endColumn) throws NumberIsTooSmallException, OutOfRangeException { checkSubMatrixIndex(startRow, endRow, startColumn, endColumn); final FieldMatrix<T> 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 FieldMatrix<T> getColumnMatrix(final int column) throws OutOfRangeException { checkColumnIndex(column); final int nRows = getRowDimension(); final FieldMatrix<T> out = createMatrix(nRows, 1); for (int i = 0; i < nRows; ++i) { out.setEntry(i, 0, getEntry(i, column)); } return out; }
/** {@inheritDoc} */ public FieldMatrix<T> getRowMatrix(final int row) throws OutOfRangeException { 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; }
/** {@inheritDoc} */ public FieldMatrix<T> scalarMultiply(final T d) { final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final FieldMatrix<T> out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col).multiply(d)); } } return out; }
/** {@inheritDoc} */ public FieldMatrix<T> scalarAdd(final T d) { final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final FieldMatrix<T> out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col).add(d)); } } return out; }
/** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor) { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { visitor.visit(row, column, getEntry(row, column)); } } return visitor.end(); }
/** {@inheritDoc} */ public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor) { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int column = 0; column < columns; ++column) { for (int row = 0; row < rows; ++row) { visitor.visit(row, column, getEntry(row, column)); } } return visitor.end(); }
/** {@inheritDoc} */ public T getTrace() throws NonSquareMatrixException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (nRows != nCols) { throw new NonSquareMatrixException(nRows, nCols); } T trace = field.getZero(); for (int i = 0; i < nRows; ++i) { trace = trace.add(getEntry(i, i)); } return trace; }
/** {@inheritDoc} */ public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor) { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int column = 0; column < columns; ++column) { for (int row = 0; row < rows; ++row) { final T oldValue = getEntry(row, column); final T newValue = visitor.visit(row, column, oldValue); setEntry(row, column, newValue); } } return visitor.end(); }
/** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixChangingVisitor<T> visitor) { final int rows = getRowDimension(); final int columns = getColumnDimension(); visitor.start(rows, columns, 0, rows - 1, 0, columns - 1); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { final T oldValue = getEntry(row, column); final T newValue = visitor.visit(row, column, oldValue); setEntry(row, column, newValue); } } return visitor.end(); }
/** {@inheritDoc} */ public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws NumberIsTooSmallException, OutOfRangeException { checkSubMatrixIndex(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) { visitor.visit(row, column, getEntry(row, column)); } } return visitor.end(); }
/** {@inheritDoc} */ public T walkInColumnOrder(final FieldMatrixPreservingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws NumberIsTooSmallException, OutOfRangeException{ checkSubMatrixIndex(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(); }
/** {@inheritDoc} */ public FieldMatrix<T> subtract(final FieldMatrix<T> m) throws MatrixDimensionMismatchException { // safety check checkSubtractionCompatible(m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final FieldMatrix<T> out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col).subtract(m.getEntry(row, col))); } } return out; }
/** {@inheritDoc} */ public FieldMatrix<T> add(FieldMatrix<T> m) throws MatrixDimensionMismatchException { // safety check checkAdditionCompatible(m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final FieldMatrix<T> out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col).add(m.getEntry(row, col))); } } return out; }
/** {@inheritDoc} */ public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor, final int startRow, final int endRow, final int startColumn, final int endColumn) throws NumberIsTooSmallException, OutOfRangeException { checkSubMatrixIndex(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) { final T oldValue = getEntry(row, column); final T newValue = visitor.visit(row, column, oldValue); setEntry(row, column, newValue); } } return visitor.end(); }
/** {@inheritDoc} */ public T[] operate(final T[] v) throws DimensionMismatchException { final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (v.length != nCols) { throw new DimensionMismatchException(v.length, nCols); } final T[] out = MathArrays.buildArray(field, nRows); for (int row = 0; row < nRows; ++row) { T sum = field.getZero(); for (int i = 0; i < nCols; ++i) { sum = sum.add(getEntry(row, i).multiply(v[i])); } out[row] = sum; } return out; }