Search in sources :

Example 46 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.

the class MinV method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows) {
    Long2DoubleOpenHashMap from1 = rows[0].getIndex2ValueMap();
    Long2DoubleOpenHashMap from2 = rows[1].getIndex2ValueMap();
    Long2DoubleOpenHashMap to = from1.clone();
    double defaultValue = Math.min(from1.defaultReturnValue(), from2.defaultReturnValue());
    to.defaultReturnValue(defaultValue);
    for (Map.Entry<Long, Double> entry : to.long2DoubleEntrySet()) {
        if (entry.getValue() > defaultValue) {
            entry.setValue(defaultValue);
        }
    }
    for (Map.Entry<Long, Double> entry : from2.long2DoubleEntrySet()) {
        if (entry.getValue() < to.get(entry.getKey().longValue())) {
            to.put(entry.getKey(), entry.getValue());
        }
    }
    rows[2].setIndex2ValueMap(to);
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 47 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.

the class Mul method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows) {
    Long2DoubleOpenHashMap from1 = rows[0].getIndex2ValueMap();
    Long2DoubleOpenHashMap from2 = rows[1].getIndex2ValueMap();
    Long2DoubleOpenHashMap to;
    if (from1.defaultReturnValue() == 0.0) {
        to = from1.clone();
        for (Map.Entry<Long, Double> entry : to.long2DoubleEntrySet()) {
            double v = from2.get(entry.getKey());
            to.put(entry.getKey().longValue(), entry.getValue() * v);
        }
    } else if (from2.defaultReturnValue() == 0.0) {
        to = from2.clone();
        for (Map.Entry<Long, Double> entry : to.long2DoubleEntrySet()) {
            double v = from1.get(entry.getKey());
            to.put(entry.getKey().longValue(), entry.getValue() * v);
        }
    } else {
        to = from1.clone();
        to.defaultReturnValue(from1.defaultReturnValue() * from2.defaultReturnValue());
        LongSet keys = from1.keySet();
        keys.addAll(from2.keySet());
        for (long key : keys) {
            double value1 = from1.get(key);
            double value2 = from2.get(key);
            to.put(key, value1 * value2);
        }
    }
    rows[2].setIndex2ValueMap(to);
}
Also used : LongSet(it.unimi.dsi.fastutil.longs.LongSet) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 48 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.

the class MulS method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows, double[] scalars) {
    double scalar = scalars[0];
    Long2DoubleOpenHashMap from = rows[0].getData();
    Long2DoubleOpenHashMap to = from.clone();
    to.defaultReturnValue(from.defaultReturnValue() * scalar);
    for (Map.Entry<Long, Double> entry : to.long2DoubleEntrySet()) {
        to.put(entry.getKey().longValue(), scalar * entry.getValue());
    }
    rows[1].setIndex2ValueMap(to);
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 49 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.

the class Scale method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows, double[] values) {
    double scalar = values[0];
    Long2DoubleOpenHashMap rowData = rows[0].getData();
    rowData.defaultReturnValue(rowData.defaultReturnValue() * scalar);
    for (Map.Entry<Long, Double> entry : rowData.long2DoubleEntrySet()) {
        entry.setValue(scalar * entry.getValue());
    }
    rows[1].setIndex2ValueMap(rowData);
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 50 with Long2DoubleOpenHashMap

use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.

the class Signum method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows) {
    Long2DoubleOpenHashMap from = rows[0].getIndex2ValueMap();
    Long2DoubleOpenHashMap to = from.clone();
    to.defaultReturnValue(Math.signum(to.defaultReturnValue()));
    for (Map.Entry<Long, Double> entry : to.long2DoubleEntrySet()) {
        entry.setValue(Math.signum(entry.getValue()));
    }
    rows[1].setIndex2ValueMap(to);
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Aggregations

Long2DoubleOpenHashMap (it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)59 Map (java.util.Map)29 LongSet (it.unimi.dsi.fastutil.longs.LongSet)7 ServerSparseDoubleLongKeyRow (com.tencent.angel.ps.impl.matrix.ServerSparseDoubleLongKeyRow)3 ArrayList (java.util.ArrayList)2 HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)1 CommonParam (com.tencent.angel.ml.matrix.psf.common.CommonParam)1 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)1 RowOffset (com.tencent.angel.model.output.format.ModelPartitionMeta.RowOffset)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)1 Int2DoubleOpenHashMap (it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap)1 Int2FloatOpenHashMap (it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Long2DoubleMap (it.unimi.dsi.fastutil.longs.Long2DoubleMap)1 PrimitiveIterator (java.util.PrimitiveIterator)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1