@Override public int[] getNumNondefaultElements() { return new int[]{rowSize(), columnSize()}; }
@Override public Matrix like() { return matrix.like(rowSize(), columnSize()); }
@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 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 like() { return matrix.like(rowSize(), columnSize()); }
@Override public Matrix like() { return matrix.like(rowSize(), columnSize()); }
@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 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); }
@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 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; }