/** * Distributed matrix set. * * @param a Row or column index. * @param b Row or column index. * @param v New value to set. */ private void matrixSet(int a, int b, double v) { // Remote set on the primary node (where given row or column is stored locally). ignite().compute(getClusterGroupForGivenKey(CACHE_NAME, a)).run(() -> { IgniteCache<RowColMatrixKey, Map<Integer, Double>> cache = Ignition.localIgnite().getOrCreateCache(CACHE_NAME); // Local get. Map<Integer, Double> map = cache.localPeek(getCacheKey(a), CachePeekMode.PRIMARY); if (map == null) { map = cache.get(getCacheKey(a)); //Remote entry get. if (map == null) map = acsMode == SEQUENTIAL_ACCESS_MODE ? new Int2DoubleRBTreeMap() : new Int2DoubleOpenHashMap(); } if (v != 0.0) map.put(b, v); else if (map.containsKey(b)) map.remove(b); // Local put. cache.put(getCacheKey(a), map); }); }
/** * Convenience constructor for tests, use DenseVector for production code * @param data */ public SparseVector(double[] data) { this.underlying = new Int2DoubleRBTreeMap(); this.size = data.length; for(int i = 0; i < data.length; i++) { underlying.put(i, data[i]); } }
public SparseVector(int size) { this.underlying = new Int2DoubleRBTreeMap(); this.size = size; }