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(); }
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(); }
/** * 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); }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a row-compressed form. This method creates a new object (not a view), so * changes in the returned matrix are NOT reflected in this matrix. * * @param sortColumnIndexes * if true, then column indexes in row compressed matrix are * sorted * * @return this matrix in a row-compressed form */ public SparseRCDoubleMatrix2D getRowCompressed(boolean sortColumnIndexes) { int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); final int[] rowIndexes = new int[nnz]; final 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 SparseRCDoubleMatrix2D(rows, columns, rowIndexes, columnIndexes, values, false, false, sortColumnIndexes); }
/** * 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); }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a row-compressed form. This method creates a new object (not a view), so * changes in the returned matrix are NOT reflected in this matrix. * * @param sortColumnIndexes * if true, then column indexes in row compressed matrix are * sorted * * @return this matrix in a row-compressed form */ public SparseRCDoubleMatrix2D getRowCompressed(boolean sortColumnIndexes) { int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); final int[] rowIndexes = new int[nnz]; final 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 SparseRCDoubleMatrix2D(rows, columns, rowIndexes, columnIndexes, values, false, false, sortColumnIndexes); }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a row-compressed modified form. This method creates a new object (not a * view), so changes in the returned matrix are NOT reflected in this * matrix. * * @return this matrix in a row-compressed modified form */ public SparseRCMDoubleMatrix2D getRowCompressedModified() { SparseRCMDoubleMatrix2D A = new SparseRCMDoubleMatrix2D(rows, columns); int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); for (int i = 0; i < nnz; i++) { int row = (int) (keys[i] / columns); int column = (int) (keys[i] % columns); A.setQuick(row, column, values[i]); } return A; }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a column-compressed modified form. This method creates a new object (not * a view), so changes in the returned matrix are NOT reflected in this * matrix. * * @return this matrix in a column-compressed modified form */ public SparseCCMDoubleMatrix2D getColumnCompressedModified() { SparseCCMDoubleMatrix2D A = new SparseCCMDoubleMatrix2D(rows, columns); int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); for (int i = 0; i < nnz; i++) { int row = (int) (keys[i] / columns); int column = (int) (keys[i] % columns); A.setQuick(row, column, values[i]); } return A; }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a row-compressed modified form. This method creates a new object (not a * view), so changes in the returned matrix are NOT reflected in this * matrix. * * @return this matrix in a row-compressed modified form */ public SparseRCMDoubleMatrix2D getRowCompressedModified() { SparseRCMDoubleMatrix2D A = new SparseRCMDoubleMatrix2D(rows, columns); int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); for (int i = 0; i < nnz; i++) { int row = (int) (keys[i] / columns); int column = (int) (keys[i] % columns); A.setQuick(row, column, values[i]); } return A; }
/** * Returns a new matrix that has the same elements as this matrix, but is in * a column-compressed modified form. This method creates a new object (not * a view), so changes in the returned matrix are NOT reflected in this * matrix. * * @return this matrix in a column-compressed modified form */ public SparseCCMDoubleMatrix2D getColumnCompressedModified() { SparseCCMDoubleMatrix2D A = new SparseCCMDoubleMatrix2D(rows, columns); int nnz = cardinality(); long[] keys = elements.keys().elements(); double[] values = elements.values().elements(); for (int i = 0; i < nnz; i++) { int row = (int) (keys[i] / columns); int column = (int) (keys[i] % columns); A.setQuick(row, column, values[i]); } return A; }