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;
}
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;
}
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;
}
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();
}
}
}
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);
}
Aggregations