/** * {@inheritDoc} */ public double get(int row, int col) { checkIndices(row, col, false); Double val = matrixEntries.get(new Entry(row, col)); return (val == null) ? 0 : val; }
/** * {@inheritDoc} */ public double get(int row, int col) { checkIndices(row, col, false); Double val = matrixEntries.get(new Entry(row, col)); return (val == null) ? 0 : val; }
/** * {@inheritDoc} */ public void set(int row, int col, double val) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; 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 if (!present) modifications.incrementAndGet(); } else if (present) { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); }
/** * {@inheritDoc} */ public void set(int row, int col, double val) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; 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 if (!present) modifications.incrementAndGet(); } else if (present) { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); }
/** * {@inheritDoc} */ public double addAndGet(int row, int col, double delta) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; Double val = matrixEntries.get(e); double newVal = (val == null) ? delta : delta + val; if (newVal != 0) { matrixEntries.put(e, newVal); // Only invalidate the cache if the number of rows or columns // containing data has changed if (val == null) modifications.incrementAndGet(); } else { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); return newVal; }
/** * {@inheritDoc} */ public double getAndAdd(int row, int col, double delta) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; Double val = matrixEntries.get(e); double newVal = (val == null) ? delta : delta + val; if (newVal != 0) { matrixEntries.put(e, newVal); // Only invalidate the cache if the number of rows or columns // containing data has changed if (val == null) modifications.incrementAndGet(); } else { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); return (val == null) ? 0 : val; }
/** * {@inheritDoc} */ public double add(int row, int col, double delta) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; Double val = matrixEntries.get(e); double newVal = (val == null) ? delta : delta + val; if (newVal != 0) { matrixEntries.put(e, newVal); // Only invalidate the cache if the number of rows or columns // containing data has changed if (val == null) modifications.incrementAndGet(); } else { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); return (val == null) ? 0 : val; }
/** * {@inheritDoc} */ public double addAndGet(int row, int col, double delta) { checkIndices(row, col, true); Entry e = new Entry(row, col); // Spin waiting for the entry to be unlocked while (lockedEntries.putIfAbsent(e, new Object()) != null) ; Double val = matrixEntries.get(e); double newVal = (val == null) ? delta : delta + val; if (newVal != 0) { matrixEntries.put(e, newVal); // Only invalidate the cache if the number of rows or columns // containing data has changed if (val == null) modifications.incrementAndGet(); } else { matrixEntries.remove(e); modifications.incrementAndGet(); } lockedEntries.remove(e); return newVal; }
/** * {@inheritDoc} */ public void setRow(int row, DoubleVector colValues) { checkIndices(row, colValues.length(), true); int c = cols.get(); lockRow(row, c); boolean modified = false; for (int col = 0; col < c; ++col) { double val = colValues.get(col); Entry e = new Entry(row, col); 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(); unlockRow(row, c); }
/** * {@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); }
/** * {@inheritDoc} */ public void setRow(int row, DoubleVector colValues) { checkIndices(row, colValues.length(), true); int c = cols.get(); lockRow(row, c); boolean modified = false; for (int col = 0; col < c; ++col) { double val = colValues.get(col); Entry e = new Entry(row, col); 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(); unlockRow(row, c); }