Search in sources :

Example 1 with Int2DoubleRBTreeMap

use of it.unimi.dsi.fastutil.ints.Int2DoubleRBTreeMap in project ignite by apache.

the class SparseDistributedMatrixStorage method matrixSet.

/**
 * 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) {
            // Remote entry get.
            map = cache.get(getCacheKey(a));
            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);
    });
}
Also used : Int2DoubleOpenHashMap(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap) RowColMatrixKey(org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey) Int2DoubleRBTreeMap(it.unimi.dsi.fastutil.ints.Int2DoubleRBTreeMap) Int2DoubleRBTreeMap(it.unimi.dsi.fastutil.ints.Int2DoubleRBTreeMap) Int2DoubleOpenHashMap(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap) Map(java.util.Map)

Aggregations

Int2DoubleOpenHashMap (it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap)1 Int2DoubleRBTreeMap (it.unimi.dsi.fastutil.ints.Int2DoubleRBTreeMap)1 Map (java.util.Map)1 RowColMatrixKey (org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey)1