public ParallelColtSparseDoubleMatrix2D(int rows, int columns) { super(rows, columns); this.matrix = new SparseDoubleMatrix2D(rows, columns); }
/** * Constructs a matrix with a copy of the given values. <tt>values</tt> is * required to have the form <tt>values[row][column]</tt> and have exactly * the same number of columns in every row. * <p> * The values are copied. So subsequent changes in <tt>values</tt> are not * reflected in the matrix, and vice-versa. * * @param values * The values to be filled into the new matrix. * @throws IllegalArgumentException * if * <tt>for any 1 <= row < values.length: values[row].length != values[row-1].length</tt> * . */ public SparseDoubleMatrix2D(double[][] values) { this(values.length, values.length == 0 ? 0 : values[0].length); assign(values); }
public void setDouble(double value, int row, int column) { matrix.setQuick(row, column, value); }
public String toString() { StringBuilder builder = new StringBuilder(); builder.append(rows).append(" x ").append(columns).append(" sparse matrix, nnz = ").append(cardinality()) .append('\n'); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { double elem = getQuick(r, c); if (elem != 0) { builder.append('(').append(r).append(',').append(c).append(')').append('\t').append(elem).append( '\n'); } } } return builder.toString(); }
setUp(size.numRows(), size.numColumns()); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) this.elements = new OpenLongDoubleHashMap(rowIndexes.length); insert(rowIndexes, columnIndexes, values); set(columnIndexes[i], rowIndexes[i], values[i]); for (int i = 0; i < numEntries; i++) { if (rowIndexes[i] != columnIndexes[i]) { set(columnIndexes[i], rowIndexes[i], -values[i]);
public double getDouble(long row, long column) { return matrix.getQuick((int) row, (int) column); }
/** * Constructs a matrix with a copy of the given indexes and a single value. * * @param rows * the number of rows the matrix shall have. * @param columns * the number of columns the matrix shall have. * @param rowIndexes * row indexes * @param columnIndexes * column indexes * @param value * numerical value */ public SparseDoubleMatrix2D(int rows, int columns, int[] rowIndexes, int[] columnIndexes, double value) { try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) throw exc; } this.elements = new OpenLongDoubleHashMap(rowIndexes.length); insert(rowIndexes, columnIndexes, value); }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a column-compressed form. This method creates a new object (not a view), * so changes in the returned matrix are NOT reflected in this matrix. * * @param sortRowIndexes * if true, then row indexes in column compressed matrix are * sorted * * @return this matrix in a column-compressed form */ public SparseCCDoubleMatrix2D getColumnCompressed(boolean sortRowIndexes) { int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); int[] rowIndexes = new int[nnz]; int[] columnIndexes = new int[nnz]; for (int k = 0; k < nnz; k++) { long key = keys[k]; rowIndexes[k] = (int) (key / columns); columnIndexes[k] = (int) (key % columns); } return new SparseCCDoubleMatrix2D(rows, columns, rowIndexes, columnIndexes, values, false, false, sortRowIndexes); }
public DoubleMatrix2D assign(DoubleMatrix2D source) { // overriden for performance only if (!(source instanceof SparseDoubleMatrix2D)) { return super.assign(source); } SparseDoubleMatrix2D other = (SparseDoubleMatrix2D) source; if (other == this) return this; // nothing to do checkShape(other); if (this.isNoView && other.isNoView) { // quickest this.elements.assign(other.elements); return this; } return super.assign(source); }
public final void clear() { matrix.elements().clear(); }
public void setDouble(double value, long row, long column) { matrix.setQuick((int) row, (int) column, value); }
public String toString() { StringBuilder builder = new StringBuilder(); builder.append(rows).append(" x ").append(columns).append(" sparse matrix, nnz = ").append(cardinality()) .append('\n'); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { double elem = getQuick(r, c); if (elem != 0) { builder.append('(').append(r).append(',').append(c).append(')').append('\t').append(elem).append( '\n'); } } } return builder.toString(); }
setUp(size.numRows(), size.numColumns()); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) this.elements = new OpenLongDoubleHashMap(rowIndexes.length); insert(rowIndexes, columnIndexes, values); set(columnIndexes[i], rowIndexes[i], values[i]); for (int i = 0; i < numEntries; i++) { if (rowIndexes[i] != columnIndexes[i]) { set(columnIndexes[i], rowIndexes[i], -values[i]);
public double getDouble(long row, long column) { return matrix.getQuick((int) row, (int) column); }
/** * Constructs a matrix with a copy of the given indexes and values. * * @param rows * the number of rows the matrix shall have. * @param columns * the number of columns the matrix shall have. * @param rowIndexes * row indexes * @param columnIndexes * column indexes * @param values * numerical values */ public SparseDoubleMatrix2D(int rows, int columns, int[] rowIndexes, int[] columnIndexes, double[] values) { try { setUp(rows, columns); } catch (IllegalArgumentException exc) { // we can hold rows*columns>Integer.MAX_VALUE cells ! if (!"matrix too large".equals(exc.getMessage())) throw exc; } this.elements = new OpenLongDoubleHashMap(rowIndexes.length); insert(rowIndexes, columnIndexes, values); }