/** * {@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} */ 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(); }
/** * {@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} */ public void setRow(int row, double[] columns) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, columns.length - 1, true); denseArrayReadLock.lock(); for (int i = 0; i < columns.length; ++i) rowEntry.set(i, columns[i]); denseArrayReadLock.unlock(); }
/** * {@inheritDoc} */ public void setRow(int row, double[] columns) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, columns.length - 1, true); denseArrayReadLock.lock(); for (int i = 0; i < columns.length; ++i) rowEntry.set(i, columns[i]); denseArrayReadLock.unlock(); }
/** * {@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} 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 void setRow(int row, DoubleVector values) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, values.length() - 1, true); denseArrayReadLock.lock(); Vectors.copy(rowEntry, values); denseArrayReadLock.unlock(); }
/** * {@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 double getAndAdd(int row, int col, double delta) { checkIndices(row, col); AtomicSparseVector rowEntry = getRow(row, col, true); return rowEntry.getAndAdd(col, delta); }
/** * {@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 setRow(int row, DoubleVector values) { checkIndices(row, 0); AtomicSparseVector rowEntry = getRow(row, values.length() - 1, true); denseArrayReadLock.lock(); Vectors.copy(rowEntry, values); denseArrayReadLock.unlock(); }
/** * {@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 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} 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 #rows()} */ public SparseDoubleVector getColumnVector(int column) { checkIndices(0, column); rowReadLock.lock(); SparseDoubleVector values = new SparseHashDoubleVector(rows.get()); for (int row = 0; row < rows.get(); ++row) { AtomicSparseVector rowEntry = getRow(row, -1, false); double value = 0; if (rowEntry != null && (value = rowEntry.get(column)) != 0) values.set(row, value); } rowReadLock.unlock(); return values; }
/** * {@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 #rows()} */ public SparseDoubleVector getColumnVector(int column) { checkIndices(0, column); rowReadLock.lock(); SparseDoubleVector values = new SparseHashDoubleVector(rows.get()); for (int row = 0; row < rows.get(); ++row) { AtomicSparseVector rowEntry = getRow(row, -1, false); double value = 0; if (rowEntry != null && (value = rowEntry.get(column)) != 0) values.set(row, value); } rowReadLock.unlock(); return values; }
/** * Returns an immutable view of the columns's data as a non-atomic vector, * which may present an inconsistent view of the data if this matrix is * being concurrently modified. This method should only be used in special * cases where the vector is being accessed at a time when the matrix (or * this particular row) will not be modified. */ public SparseDoubleVector getColumnVectorUnsafe(int column) { checkIndices(0, column); SparseDoubleVector values = new SparseHashDoubleVector(rows.get()); for (int row = 0; row < rows.get(); ++row) { AtomicSparseVector rowEntry = getRow(row, -1, false); double value = 0; if (rowEntry != null && (value = rowEntry.get(column)) != 0) values.set(row, value); } return values; }
/** * Returns an immutable view of the columns's data as a non-atomic vector, * which may present an inconsistent view of the data if this matrix is * being concurrently modified. This method should only be used in special * cases where the vector is being accessed at a time when the matrix (or * this particular row) will not be modified. */ public SparseDoubleVector getColumnVectorUnsafe(int column) { checkIndices(0, column); SparseDoubleVector values = new SparseHashDoubleVector(rows.get()); for (int row = 0; row < rows.get(); ++row) { AtomicSparseVector rowEntry = getRow(row, -1, false); double value = 0; if (rowEntry != null && (value = rowEntry.get(column)) != 0) values.set(row, value); } return values; }