use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class UpdateHyperLogLog method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
UpdateHyperLogLogPartParam param = (UpdateHyperLogLogPartParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) param.getKeyValuePart();
int p = param.getP();
int sp = param.getSp();
long seed = param.getSeed();
long[] keys = split.getKeys();
IElement[] values = split.getValues();
row.startWrite();
try {
if (keys != null && keys.length > 0 && values != null && values.length > 0) {
for (int i = 0; i < keys.length; i++) {
long key = keys[i];
HyperLogLogPlus value = ((HLLPlusElement) values[i]).getCounter();
if (!row.exist(key))
row.set(key, new HyperLogLogPlusElement(key, p, sp, seed));
HyperLogLogPlusElement hllElem = (HyperLogLogPlusElement) row.get(key);
if (hllElem.isActive()) {
hllElem.merge(value);
}
}
}
} finally {
row.endWrite();
}
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class GetByteNeighbor method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
}
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGeneralGetResult partResult = (PartGeneralGetResult) result;
long[] nodeIds = partResult.getNodeIds();
IElement[] data = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
if (data[i] != null) {
byte[] serializedNeighbors = ((ByteArrayElement) data[i]).getData();
if (serializedNeighbors.length > 0) {
nodeIdToNeighbors.put(nodeIds[i], ScalaKryoInstantiator.defaultPool().fromBytes(serializedNeighbors, long[].class));
} else {
nodeIdToNeighbors.put(nodeIds[i], emptyLongs);
}
} else {
nodeIdToNeighbors.put(nodeIds[i], emptyLongs);
}
}
}
return new GetLongsResult(nodeIdToNeighbors);
}
use of com.tencent.angel.ps.storage.vector.element.IElement in project angel by Tencent.
the class InitNeighbors method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
// Get nodes and features
ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
long[] nodeIds = split.getKeys();
IElement[] neighbors = split.getValues();
row.startWrite();
try {
for (int i = 0; i < nodeIds.length; i++) {
row.set(nodeIds[i], neighbors[i]);
}
} finally {
row.endWrite();
}
}
Aggregations