@Override final public void dotTimesEquals( final Matrix other) { if (other instanceof DiagonalMatrix) { dotTimesEquals((DiagonalMatrix) other); } else if (other instanceof DenseMatrix) { this.dotTimesEquals((DenseMatrix) other); } else if (other instanceof SparseMatrix) { this.dotTimesEquals((SparseMatrix) other); } else { super.dotTimesEquals(other); } }
@Override final public String toString( final NumberFormat format) { StringBuilder sb = new StringBuilder(); int m = getNumRows(); int n = getNumColumns(); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { sb.append(format.format(get(i, j))).append(" "); } sb.append('\n'); } return sb.toString(); }
@Override final public void minusEquals( final Matrix other) { if (other instanceof DiagonalMatrix) { minusEquals((DiagonalMatrix) other); } else if (other instanceof DenseMatrix) { this.minusEquals((DenseMatrix) other); } else if (other instanceof SparseMatrix) { this.minusEquals((SparseMatrix) other); } else { super.minusEquals(other); } }
/** * Helper method checks that the input submatrix range is acceptable for * this matrix, including that the max is greater than or equal to the min. * Note that the input mins and maxs are inclusive. * * @param minRow The minimum row to return (inclusive) * @param maxRow The maximum row to return (inclusive) * @param minCol The minimum column to return (inclusive) * @param maxCol The maximum column to return (inclusive) * @throws ArrayIndexOutOfBoundsException if the input range is illegal or * outside the bounds of this. */ final protected void checkSubmatrixRange( final int minRow, final int maxRow, final int minCol, final int maxCol) { if (maxRow < minRow || maxCol < minCol || minRow < 0 || minCol < 0 || maxRow > getNumRows() || maxCol > getNumColumns()) { throw new ArrayIndexOutOfBoundsException("Input range is invalid: [" + minRow + ", " + maxRow + "], [" + minCol + ", " + maxCol + "]"); } }
return preTimes((DenseVector) vector); return this.preTimes((SparseVector) vector); vector.assertDimensionalityEquals(this.getNumRows()); final Vector result = vector.getVectorFactory().createVector( this.getNumColumns()); for (final MatrixEntry entry : this)
/** * Returns a deep copy of this. * * @return a deep copy of this */ @Override final public Matrix clone() { final DenseMatrix result = (DenseMatrix) super.clone(); result.rows = ObjectUtil.cloneSmartArrayAndElements(this.rows); return result; }
@Override final public boolean hasNext() { return (rowIndex < matrix.getNumRows()); }
/** * Updates this to point to a new location in the matrix (if input is within * bounds). * * @param columnIndex The new column index * @throws IllegalArgumentException if the input columnIndex is out of * bounds */ @Override final public void setColumnIndex( final int columnIndex) { if ((columnIndex < 0) || (columnIndex >= matrix.getNumColumns())) { throw new IllegalArgumentException("Unable to set row index " + "beyond bounds: " + columnIndex + " not within [0, " + matrix.getNumColumns() + ")"); } this.columnIndex = columnIndex; }
@Override final public double getValue() { return this.matrix.get(this.rowIndex, this.columnIndex); }
/** * Sets the value stored at the current location in the matrix * * @param value the value to set */ @Override final public void setValue( final double value) { this.matrix.setElement(this.rowIndex, this.columnIndex, value); }
@Override final public Vector times( final Matrix matrix) { if (matrix instanceof BaseMatrix) { return ((BaseMatrix) matrix).preTimes(this); } else { return super.times(matrix); } }
@Override final public void plusEquals( final Matrix other) { if (other instanceof DiagonalMatrix) { plusEquals((DiagonalMatrix) other); } else if (other instanceof DenseMatrix) { this.plusEquals((DenseMatrix) other); } else if (other instanceof SparseMatrix) { this.plusEquals((SparseMatrix) other); } else { super.plusEquals(other); } }
@Override final public void scaledPlusEquals( final double scaleFactor, final Matrix other) { if (other instanceof DiagonalMatrix) { scaledPlusEquals((DiagonalMatrix) other, scaleFactor); } else if (other instanceof DenseMatrix) { this.scaledPlusEquals((DenseMatrix) other, scaleFactor); } else if (other instanceof SparseMatrix) { this.scaledPlusEquals((SparseMatrix) other, scaleFactor); } else { super.scaledPlusEquals(scaleFactor, other); } }
/** * Helper method checks that the input submatrix range is acceptable for * this matrix, including that the max is greater than or equal to the min. * Note that the input mins and maxs are inclusive. * * @param minRow The minimum row to return (inclusive) * @param maxRow The maximum row to return (inclusive) * @param minCol The minimum column to return (inclusive) * @param maxCol The maximum column to return (inclusive) * @throws ArrayIndexOutOfBoundsException if the input range is illegal or * outside the bounds of this. */ final protected void checkSubmatrixRange( final int minRow, final int maxRow, final int minCol, final int maxCol) { if (maxRow < minRow || maxCol < minCol || minRow < 0 || minCol < 0 || maxRow > getNumRows() || maxCol > getNumColumns()) { throw new ArrayIndexOutOfBoundsException("Input range is invalid: [" + minRow + ", " + maxRow + "], [" + minCol + ", " + maxCol + "]"); } }
return preTimes((DenseVector) vector); return this.preTimes((SparseVector) vector); vector.assertDimensionalityEquals(this.getNumRows()); final Vector result = vector.getVectorFactory().createVector( this.getNumColumns()); for (final MatrixEntry entry : this)
/** * Returns a deep copy of this. * * @return a deep copy of this */ @Override final public Matrix clone() { final DenseMatrix result = (DenseMatrix) super.clone(); result.rows = ObjectUtil.cloneSmartArrayAndElements(this.rows); return result; }
@Override final public boolean hasNext() { return (rowIndex < matrix.getNumRows()); }
/** * Updates this to point to a new location in the matrix (if input is within * bounds). * * @param columnIndex The new column index * @throws IllegalArgumentException if the input columnIndex is out of * bounds */ @Override final public void setColumnIndex( final int columnIndex) { if ((columnIndex < 0) || (columnIndex >= matrix.getNumColumns())) { throw new IllegalArgumentException("Unable to set row index " + "beyond bounds: " + columnIndex + " not within [0, " + matrix.getNumColumns() + ")"); } this.columnIndex = columnIndex; }
@Override final public double getValue() { return this.matrix.get(this.rowIndex, this.columnIndex); }
/** * Sets the value stored at the current location in the matrix * * @param value the value to set */ @Override final public void setValue( final double value) { this.matrix.setElement(this.rowIndex, this.columnIndex, value); }