/** * {@inheritDoc} */ public double get(int row, int col) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, false); return (rowEntry == null) ? 0d : rowEntry.get(col); }
/** * {@inheritDoc} The length of the returned column reflects the size of * matrix at the time of the call, which may be different from earlier calls * to {@link #rows()} */ public double[] getColumn(int column) { checkIndices(0, column); rowReadLock.lock(); double[] values = new double[rows.get()]; for (int row = 0; row < rows.get(); ++row) values[row] = get(row, column); rowReadLock.unlock(); return values; }
/** * {@inheritDoc} */ public void setColumn(int column, double[] values) { checkIndices(0, column); for (int row = 0; row < rows.get(); ++row) set(row, column, values[row]); }
/** * {@inheritDoc} The length of the returned row reflects the size of matrix * at the time of the call, which may be different from earlier calls to * {@link #columns()}. */ public double[] getRow(int row) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, -1, false); return (rowEntry == null) ? new double[cols.get()] : toArray(rowEntry, cols.get()); }
/** * {@inheritDoc} The length of the returned row vector reflects the size of * matrix at the time of the call, which may be different from earlier calls * to {@link #columns()}. */ public SparseDoubleVector getRowVector(int row) { SparseDoubleVector v = getRow(row, -1, false); // If no row was currently assigned in the matrix, then return an empty // vector in its place. Otherwise, return a view on top of the vector // with its current length return (v == null) ? new CompactSparseVector(cols.get()) : Vectors.subview(v, 0, cols.get()); }
/** * {@inheritDoc} */ public double[][] toDenseArray() { // Grab the write lock to prevent any new rows from being updated rowWriteLock.lock(); // Then grab the whole matrix lock to prevent any values from being set // while this method converts the rows into arrays. denseArrayWriteLock.lock(); int c = cols.get(); double[][] m = new double[rows.get()][c]; for (Map.Entry<Integer, AtomicSparseVector> e : sparseMatrix.entrySet()) { m[e.getKey()] = toArray(e.getValue(), c); } denseArrayWriteLock.unlock(); rowWriteLock.unlock(); return m; }
/** * {@inheritDoc} The length of the returned row reflects the size of matrix * at the time of the call, which may be different from earlier calls to * {@link #columns()}. */ public double[] getRow(int row) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, -1, false); return (rowEntry == null) ? new double[cols.get()] : toArray(rowEntry, cols.get()); }
/** * {@inheritDoc} The length of the returned row vector reflects the size of * matrix at the time of the call, which may be different from earlier calls * to {@link #columns()}. */ public SparseDoubleVector getRowVector(int row) { SparseDoubleVector v = getRow(row, -1, false); // If no row was currently assigned in the matrix, then return an empty // vector in its place. Otherwise, return a view on top of the vector // with its current length return (v == null) ? new CompactSparseVector(cols.get()) : Vectors.subview(v, 0, cols.get()); }
/** * {@inheritDoc} */ public double[][] toDenseArray() { // Grab the write lock to prevent any new rows from being updated rowWriteLock.lock(); // Then grab the whole matrix lock to prevent any values from being set // while this method converts the rows into arrays. denseArrayWriteLock.lock(); int c = cols.get(); double[][] m = new double[rows.get()][c]; for (Map.Entry<Integer, AtomicSparseVector> e : sparseMatrix.entrySet()) { m[e.getKey()] = toArray(e.getValue(), c); } denseArrayWriteLock.unlock(); rowWriteLock.unlock(); return m; }
/** * {@inheritDoc} */ public double getAndAdd(int row, int col, double delta) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); return rowEntry.getAndAdd(col, delta); }
/** * {@inheritDoc} */ public void setColumn(int column, double[] values) { checkIndices(0, column); for (int row = 0; row < rows.get(); ++row) set(row, column, values[row]); }
/** * {@inheritDoc} The length of the returned column reflects the size of * matrix at the time of the call, which may be different from earlier calls * to {@link #rows()} */ public double[] getColumn(int column) { checkIndices(0, column); rowReadLock.lock(); double[] values = new double[rows.get()]; for (int row = 0; row < rows.get(); ++row) values[row] = get(row, column); rowReadLock.unlock(); return values; }
/** * {@inheritDoc} */ public double addAndGet(int row, int col, double delta) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); return rowEntry.addAndGet(col, delta); }
/** * {@inheritDoc} */ public void setColumn(int column, DoubleVector values) { checkIndices(0, column); for (int row = 0; row < rows.get(); ++row) set(row, column, values.get(row)); }
/** * {@inheritDoc} */ public double addAndGet(int row, int col, double delta) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); return rowEntry.addAndGet(col, delta); }
/** * {@inheritDoc} */ public void setColumn(int column, DoubleVector values) { checkIndices(0, column); for (int row = 0; row < rows.get(); ++row) set(row, column, values.get(row)); }
/** * {@inheritDoc} */ public double add(int row, int col, double delta) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); return rowEntry.getAndAdd(col, delta); }
/** * {@inheritDoc} */ public double get(int row, int col) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, false); return (rowEntry == null) ? 0d : rowEntry.get(col); }
/** * {@inheritDoc} */ public void set(int row, int col, double val) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); denseArrayReadLock.lock(); rowEntry.set(col, val); denseArrayReadLock.unlock(); }
/** * {@inheritDoc} */ public void set(int row, int col, double val) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); denseArrayReadLock.lock(); rowEntry.set(col, val); denseArrayReadLock.unlock(); }