/** * {@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, AtomicVector> e : sparseMatrix.entrySet()) { m[e.getKey()] = toArray(e.getValue(), c); } denseArrayWriteLock.unlock(); rowWriteLock.unlock(); return m; }
/** * {@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, AtomicVector> 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); AtomicVector rowEntry = getRow(row, -1, false); return (rowEntry == null) ? new double[cols.get()] : toArray(rowEntry, cols.get()); }
/** * {@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); AtomicVector rowEntry = getRow(row, -1, false); return (rowEntry == null) ? new double[cols.get()] : toArray(rowEntry, cols.get()); }