@Override public int[] getNumNondefaultElements() { return new int[]{rowSize(), columnSize()}; }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } for (int col = 0; col < columnSize(); col++) { matrix .setQuick(row + offset[ROW], col + offset[COL], other.getQuick(col)); } return this; }
@Override public Vector viewColumn(int column) { if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } return matrix.viewColumn(column + offset[COL]).viewPart(offset[ROW], rowSize()); }
@Override public Matrix like() { return matrix.like(rowSize(), columnSize()); }
@Override public Vector viewRow(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } return matrix.viewRow(row + offset[ROW]).viewPart(offset[COL], columnSize()); }
@Override public Matrix viewPart(int[] offset, int[] size) { if (offset[ROW] < 0) { throw new IndexException(offset[ROW], 0); } if (offset[ROW] + size[ROW] > rowSize()) { throw new IndexException(offset[ROW] + size[ROW], rowSize()); } if (offset[COL] < 0) { throw new IndexException(offset[COL], 0); } if (offset[COL] + size[COL] > columnSize()) { throw new IndexException(offset[COL] + size[COL], columnSize()); } int[] origin = this.offset.clone(); origin[ROW] += offset[ROW]; origin[COL] += offset[COL]; return new MatrixView(matrix, origin, size); }
/** * Construct a view of the matrix with given offset and cardinality * * @param matrix an underlying Matrix * @param offset the int[2] offset into the underlying matrix * @param size the int[2] size of the view */ public MatrixView(Matrix matrix, int[] offset, int[] size) { super(size[ROW], size[COL]); int rowOffset = offset[ROW]; if (rowOffset < 0) { throw new IndexException(rowOffset, rowSize()); } int rowsRequested = size[ROW]; if (rowOffset + rowsRequested > matrix.rowSize()) { throw new IndexException(rowOffset + rowsRequested, matrix.rowSize()); } int columnOffset = offset[COL]; if (columnOffset < 0) { throw new IndexException(columnOffset, columnSize()); } int columnsRequested = size[COL]; if (columnOffset + columnsRequested > matrix.columnSize()) { throw new IndexException(columnOffset + columnsRequested, matrix.columnSize()); } this.matrix = matrix; this.offset = offset; }
@Override public int[] getNumNondefaultElements() { return new int[]{rowSize(), columnSize()}; }
@Override public int[] getNumNondefaultElements() { return new int[]{rowSize(), columnSize()}; }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } for (int col = 0; col < columnSize(); col++) { matrix .setQuick(row + offset[ROW], col + offset[COL], other.getQuick(col)); } return this; }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } for (int col = 0; col < columnSize(); col++) { matrix .setQuick(row + offset[ROW], col + offset[COL], other.getQuick(col)); } return this; }
@Override public Vector viewColumn(int column) { if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } return matrix.viewColumn(column + offset[COL]).viewPart(offset[ROW], rowSize()); }
@Override public Vector viewColumn(int column) { if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } return new VectorView(matrix.viewColumn(column + offset[COL]), offset[ROW], rowSize()); }
@Override public Matrix like() { return matrix.like(rowSize(), columnSize()); }
@Override public Matrix like() { return matrix.like(rowSize(), columnSize()); }
@Override public Vector viewRow(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } return new VectorView(matrix.viewRow(row + offset[ROW]), offset[COL], columnSize()); }
@Override public Vector viewRow(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } return matrix.viewRow(row + offset[ROW]).viewPart(offset[COL], columnSize()); }
@Override public Matrix viewPart(int[] offset, int[] size) { if (offset[ROW] < 0) { throw new IndexException(offset[ROW], 0); } if (offset[ROW] + size[ROW] > rowSize()) { throw new IndexException(offset[ROW] + size[ROW], rowSize()); } if (offset[COL] < 0) { throw new IndexException(offset[COL], 0); } if (offset[COL] + size[COL] > columnSize()) { throw new IndexException(offset[COL] + size[COL], columnSize()); } int[] origin = this.offset.clone(); origin[ROW] += offset[ROW]; origin[COL] += offset[COL]; return new MatrixView(matrix, origin, size); }
@Override public Matrix viewPart(int[] offset, int[] size) { if (offset[ROW] < ROW) { throw new IndexException(offset[ROW], ROW); } if (offset[ROW] + size[ROW] > rowSize()) { throw new IndexException(offset[ROW] + size[ROW], rowSize()); } if (offset[COL] < ROW) { throw new IndexException(offset[COL], ROW); } if (offset[COL] + size[COL] > columnSize()) { throw new IndexException(offset[COL] + size[COL], columnSize()); } int[] origin = offset.clone(); origin[ROW] += offset[ROW]; origin[COL] += offset[COL]; return new MatrixView(matrix, origin, size); }
/** * Construct a view of the matrix with given offset and cardinality * * @param matrix an underlying Matrix * @param offset the int[2] offset into the underlying matrix * @param size the int[2] size of the view */ public MatrixView(Matrix matrix, int[] offset, int[] size) { super(size[ROW], size[COL]); int rowOffset = offset[ROW]; if (rowOffset < 0) { throw new IndexException(rowOffset, rowSize()); } int rowsRequested = size[ROW]; if (rowOffset + rowsRequested > matrix.rowSize()) { throw new IndexException(rowOffset + rowsRequested, matrix.rowSize()); } int columnOffset = offset[COL]; if (columnOffset < 0) { throw new IndexException(columnOffset, columnSize()); } int columnsRequested = size[COL]; if (columnOffset + columnsRequested > matrix.columnSize()) { throw new IndexException(columnOffset + columnsRequested, matrix.columnSize()); } this.matrix = matrix; this.offset = offset; }