/** * Initializes a new iterator starting at the first value in the first * row of the matrix * * @param startRow The row to start on * @throws IllegalArgumentException if startRow is outside of [0 .. * numRows] */ public NonZeroEntryIterator( final int startRow) { if (startRow >= getNumRows() || startRow < 0) { throw new IllegalArgumentException("Input row index (" + startRow + ") greater than number of rows: " + getNumRows()); } rowIdx = startRow; columnValueIndex = firstIndicesForRows[rowIdx]; // If there are no-entry rows, we need to skip past them while (columnValueIndex >= firstIndicesForRows[rowIdx + 1]) { ++rowIdx; if (rowIdx >= numRows) { break; } } }
/** * Initializes a new iterator starting at the first value in the first * row of the matrix * * @param startRow The row to start on * @throws IllegalArgumentException if startRow is outside of [0 .. * numRows] */ public NonZeroEntryIterator( final int startRow) { if (startRow >= getNumRows() || startRow < 0) { throw new IllegalArgumentException("Input row index (" + startRow + ") greater than number of rows: " + getNumRows()); } rowIdx = startRow; columnValueIndex = firstIndicesForRows[rowIdx]; // If there are no-entry rows, we need to skip past them while (columnValueIndex >= firstIndicesForRows[rowIdx + 1]) { ++rowIdx; if (rowIdx >= numRows) { break; } } }
/** * Initializes a new iterator starting at the first value in the first * row of the matrix * * @param startRow The row to start on * @throws IllegalArgumentException if startRow is outside of [0 .. * numRows] */ public NonZeroEntryIterator( final int startRow) { if (startRow >= getNumRows() || startRow < 0) { throw new IllegalArgumentException("Input row index (" + startRow + ") greater than number of rows: " + getNumRows()); } rowIdx = startRow; columnValueIndex = firstIndicesForRows[rowIdx]; // If there are no-entry rows, we need to skip past them while (columnValueIndex >= firstIndicesForRows[rowIdx + 1]) { ++rowIdx; if (rowIdx >= numRows) { break; } } }
/** * This method is provided so that the calling programmer can explicitly * declare when a matrix should be decompressed from the compressed Yale * format. Note that the method will be automatically compressed and * decompressed when various methods are called (e.g., decompressed for set* * methods, compressed for times, dotTimes, etc.). */ final public void decompress() { if (!isCompressed()) { return; } for (int i = 0; i < getNumRows(); ++i) { rows[i].clear(); for (int j = firstIndicesForRows[i]; j < firstIndicesForRows[i + 1]; ++j) { rows[i].setElement(columnIndices[j], values[j]); } } values = null; firstIndicesForRows = columnIndices = null; }
/** * This method is provided so that the calling programmer can explicitly * declare when a matrix should be decompressed from the compressed Yale * format. Note that the method will be automatically compressed and * decompressed when various methods are called (e.g., decompressed for set* * methods, compressed for times, dotTimes, etc.). */ final public void decompress() { if (!isCompressed()) { return; } for (int i = 0; i < getNumRows(); ++i) { rows[i].clear(); for (int j = firstIndicesForRows[i]; j < firstIndicesForRows[i + 1]; ++j) { rows[i].setElement(columnIndices[j], values[j]); } } values = null; firstIndicesForRows = columnIndices = null; }
/** * This method is provided so that the calling programmer can explicitly * declare when a matrix should be decompressed from the compressed Yale * format. Note that the method will be automatically compressed and * decompressed when various methods are called (e.g., decompressed for set* * methods, compressed for times, dotTimes, etc.). */ final public void decompress() { if (!isCompressed()) { return; } for (int i = 0; i < getNumRows(); ++i) { rows[i].clear(); for (int j = firstIndicesForRows[i]; j < firstIndicesForRows[i + 1]; ++j) { rows[i].setElement(columnIndices[j], values[j]); } } values = null; firstIndicesForRows = columnIndices = null; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * @return {@inheritDoc} */ @Override public final Matrix times( final DiagonalMatrix other) { this.assertMultiplicationDimensions(other); if (!isCompressed()) { compress(); } SparseMatrix result = new SparseMatrix(getNumRows(), getNumColumns()); result.columnIndices = Arrays.copyOf(columnIndices, columnIndices.length); result.firstIndicesForRows = Arrays.copyOf(firstIndicesForRows, firstIndicesForRows.length); result.values = new double[values.length]; for (int i = 0; i < values.length; ++i) { result.values[i] = values[i] * other.get(columnIndices[i], columnIndices[i]); } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * @return {@inheritDoc} */ @Override public final Matrix times( final DiagonalMatrix other) { this.assertMultiplicationDimensions(other); if (!isCompressed()) { compress(); } SparseMatrix result = new SparseMatrix(getNumRows(), getNumColumns()); result.columnIndices = Arrays.copyOf(columnIndices, columnIndices.length); result.firstIndicesForRows = Arrays.copyOf(firstIndicesForRows, firstIndicesForRows.length); result.values = new double[values.length]; for (int i = 0; i < values.length; ++i) { result.values[i] = values[i] * other.get(columnIndices[i], columnIndices[i]); } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * @return {@inheritDoc} */ @Override public final Matrix times( final DiagonalMatrix other) { this.assertMultiplicationDimensions(other); if (!isCompressed()) { compress(); } SparseMatrix result = new SparseMatrix(getNumRows(), getNumColumns()); result.columnIndices = Arrays.copyOf(columnIndices, columnIndices.length); result.firstIndicesForRows = Arrays.copyOf(firstIndicesForRows, firstIndicesForRows.length); result.values = new double[values.length]; for (int i = 0; i < values.length; ++i) { result.values[i] = values[i] * other.get(columnIndices[i], columnIndices[i]); } return result; }
SparseMatrix result = new SparseMatrix(getNumRows(), getNumColumns()); result.columnIndices = Arrays.copyOf(columnIndices, columnIndices.length); result.firstIndicesForRows = Arrays.copyOf(firstIndicesForRows,
int[] newFirstIdxsForRows = new int[getNumRows() + 1];
int[] newFirstIdxsForRows = new int[getNumRows() + 1];
int[] newFirstIdxsForRows = new int[getNumRows() + 1];
int[] newFirstIdxsForRows = new int[getNumRows() + 1];
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * * @return {@inheritDoc} */ @Override public final Vector preTimes( final DenseVector vector) { vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed()) { compress(); } DenseVector result = new DenseVector(getNumColumns()); int row = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[row + 1]) { ++row; } result.setElement(columnIndices[i], result.get(columnIndices[i]) + vector.get(row) * values[i]); } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * * @return {@inheritDoc} */ @Override public final Vector preTimes( final DenseVector vector) { vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed()) { compress(); } DenseVector result = new DenseVector(getNumColumns()); int row = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[row + 1]) { ++row; } result.setElement(columnIndices[i], result.get(columnIndices[i]) + vector.get(row) * values[i]); } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * * @return {@inheritDoc} */ @Override public final Vector preTimes( final DenseVector vector) { vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed()) { compress(); } DenseVector result = new DenseVector(getNumColumns()); int row = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[row + 1]) { ++row; } result.setElement(columnIndices[i], result.get(columnIndices[i]) + vector.get(row) * values[i]); } return result; }
final SparseVector vector) vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed())
final SparseVector vector) vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed())
final SparseVector vector) vector.assertDimensionalityEquals(this.getNumRows()); if (!isCompressed())