Search in sources :

Example 6 with Long2DoubleOpenHashMap

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

the class Equal method doProcessRow.

@Override
protected double doProcessRow(ServerSparseDoubleLongKeyRow row1, ServerSparseDoubleLongKeyRow row2) {
    Long2DoubleOpenHashMap data1 = row1.getIndex2ValueMap();
    Long2DoubleOpenHashMap data2 = row2.getIndex2ValueMap();
    if (data1.defaultReturnValue() != data2.defaultReturnValue()) {
        return 0.0;
    }
    LongSet keys = data1.keySet();
    keys.addAll(data2.keySet());
    if (keys.size() != data1.keySet().size() || keys.size() != data2.keySet().size()) {
        return 0.0;
    }
    for (long key : keys) {
        if (Math.abs(data1.get(key) - data2.get(key)) > 1e-10) {
            return 0.0;
        }
    }
    return 1.0;
}
Also used : LongSet(it.unimi.dsi.fastutil.longs.LongSet) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 7 with Long2DoubleOpenHashMap

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

the class Max method doProcessRow.

@Override
protected double doProcessRow(ServerSparseDoubleLongKeyRow row) {
    Long2DoubleOpenHashMap data = row.getIndex2ValueMap();
    double amax = data.defaultReturnValue();
    for (Map.Entry<Long, Double> entry : data.long2DoubleEntrySet()) {
        amax = Math.max(amax, entry.getValue());
    }
    return amax;
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 8 with Long2DoubleOpenHashMap

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

the class Sum method doProcessRow.

@Override
protected double doProcessRow(ServerSparseDoubleLongKeyRow row) {
    long entireSize = row.getEndCol() - row.getStartCol();
    Long2DoubleOpenHashMap data = row.getData();
    double asum = 0.0;
    for (Map.Entry<Long, Double> entry : data.long2DoubleEntrySet()) {
        asum += entry.getValue();
    }
    asum += data.defaultReturnValue() * (entireSize - data.size());
    return asum;
}
Also used : Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap) Map(java.util.Map)

Example 9 with Long2DoubleOpenHashMap

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

the class Increment method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] partRows, PartitionUpdateParam param) {
    CommonParam.PSFPartitionUpdateParam partParam = (CommonParam.PSFPartitionUpdateParam) param;
    int[] rows = partParam.getInts();
    long[] cols = partParam.getLongs();
    double[] values = partParam.getDoubles();
    for (ServerSparseDoubleLongKeyRow partRow : partRows) {
        int rowId = partRow.getRowId();
        ArrayList<Integer> indics = new ArrayList<Integer>();
        for (int i = 0; i < rows.length; i++) {
            if (rowId == rows[i] && cols[i] >= partRow.getStartCol() && cols[i] < partRow.getEndCol()) {
                indics.add(i);
            }
        }
        try {
            partRow.getLock().writeLock().lock();
            Long2DoubleOpenHashMap rowData = partRow.getData();
            for (Integer i : indics) {
                if (rowData.containsKey(cols[i])) {
                    rowData.addTo(cols[i], values[i]);
                } else {
                    rowData.put(cols[i], values[i]);
                }
            }
        } finally {
            partRow.getLock().writeLock().unlock();
        }
    }
}
Also used : ServerSparseDoubleLongKeyRow(com.tencent.angel.ps.impl.matrix.ServerSparseDoubleLongKeyRow) ArrayList(java.util.ArrayList) Long2DoubleOpenHashMap(it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)

Example 10 with Long2DoubleOpenHashMap

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

the class Add method doUpdate.

@Override
protected void doUpdate(ServerSparseDoubleLongKeyRow[] rows) {
    Long2DoubleOpenHashMap from1 = rows[0].getIndex2ValueMap();
    Long2DoubleOpenHashMap from2 = rows[1].getIndex2ValueMap();
    Long2DoubleOpenHashMap to = from1.clone();
    to.defaultReturnValue(from1.defaultReturnValue() + from2.defaultReturnValue());
    for (Map.Entry<Long, Double> entry : from2.long2DoubleEntrySet()) {
        to.addTo(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)

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