/** * Returns the column vector, locking the data if {@code shouldLock} is * {@code true}. */ private SparseDoubleVector getColumnVector(int column, boolean shouldLock) { int r = rows.get(); if (shouldLock) lockColumn(column, r); // Ensure that the column data is up to date while (lastVectorCacheUpdate.get() != modifications.get()) updateVectorCache(); int[] rowArr = colToRowsCache[column]; SparseDoubleVector colVec = new SparseHashDoubleVector(r); for (int row : rowArr) colVec.set(row, matrixEntries.get(new Entry(row, column))); if (shouldLock) unlockColumn(column, r); return colVec; }
/** * Returns the column vector, locking the data if {@code shouldLock} is * {@code true}. */ private SparseDoubleVector getColumnVector(int column, boolean shouldLock) { int r = rows.get(); if (shouldLock) lockColumn(column, r); // Ensure that the column data is up to date while (lastVectorCacheUpdate.get() != modifications.get()) updateVectorCache(); int[] rowArr = colToRowsCache[column]; SparseDoubleVector colVec = new SparseHashDoubleVector(r); for (int row : rowArr) colVec.set(row, matrixEntries.get(new Entry(row, column))); if (shouldLock) unlockColumn(column, r); return colVec; }
/** * {@inheritDoc} */ public void setColumn(int column, DoubleVector rowValues) { checkIndices(rowValues.length(), column, true); int r = rows.get(); lockColumn(column, r); boolean modified = false; for (int row = 0; row < r; ++row) { double val = rowValues.get(row); Entry e = new Entry(row, column); boolean present = matrixEntries.containsKey(e); if (val != 0) { matrixEntries.put(e, val); // Only invalidate the cache if the number of rows or columns // containing data has changed modified = modified || !present; } else if (present) { matrixEntries.remove(e); modified = true; } } if (modified) modifications.incrementAndGet(); unlockColumn(column, r); }
/** * {@inheritDoc} */ public void setColumn(int column, DoubleVector rowValues) { checkIndices(rowValues.length(), column, true); int r = rows.get(); lockColumn(column, r); boolean modified = false; for (int row = 0; row < r; ++row) { double val = rowValues.get(row); Entry e = new Entry(row, column); boolean present = matrixEntries.containsKey(e); if (val != 0) { matrixEntries.put(e, val); // Only invalidate the cache if the number of rows or columns // containing data has changed modified = modified || !present; } else if (present) { matrixEntries.remove(e); modified = true; } } if (modified) modifications.incrementAndGet(); unlockColumn(column, r); }