use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class NumNodes method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
long numNodes = 0;
for (PartitionGetResult result : partResults) {
if (result instanceof ScalarPartitionAggrResult) {
long value = (long) ((ScalarPartitionAggrResult) result).result;
numNodes += value;
}
}
return new NumNodesResult(numNodes);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetClosenessAndCardinality method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
Long2ObjectOpenHashMap<Tuple3<Double, Long, Long>> closenesses = new Long2ObjectOpenHashMap<>();
for (PartitionGetResult r : partResults) {
GetClosenessAndCardinalityPartResult rr = (GetClosenessAndCardinalityPartResult) r;
closenesses.putAll(rr.getClosenesses());
}
return new GetClosenessAndCardinalityResult(closenesses);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetLabels method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int size = 0;
for (PartitionGetResult result : partResults) {
size += ((GetLabelsPartResult) result).size();
}
long dim = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId).getColNum();
LongFloatVector vector = VFactory.sparseLongKeyFloatVector(dim, size);
for (PartitionGetResult result : partResults) {
GetLabelsPartResult r = (GetLabelsPartResult) result;
long[] keys = r.getKeys();
float[] vals = r.getValues();
assert (keys.length == vals.length);
for (int i = 0; i < keys.length; i++) {
vector.set(keys[i], vals[i]);
}
}
return new GetLabelsResult(vector);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult in project angel by Tencent.
the class GetNeighborAliasTable method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
Int2ObjectArrayMap<PartitionGetResult> partIdToResultMap = new Int2ObjectArrayMap<>(partResults.size());
for (PartitionGetResult result : partResults) {
partIdToResultMap.put(((PartGetNeighborAliasTableResult) result).getPartId(), result);
}
GetNeighborAliasTableParam param = (GetNeighborAliasTableParam) getParam();
long[] nodeIds = param.getNodeIds();
List<PartitionGetParam> partParams = param.getPartParams();
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
for (PartitionGetParam partParam : partParams) {
int start = ((PartGetNeighborAliasTableParam) partParam).getStartIndex();
int end = ((PartGetNeighborAliasTableParam) partParam).getEndIndex();
PartGetNeighborAliasTableResult partResult = (PartGetNeighborAliasTableResult) (partIdToResultMap.get(partParam.getPartKey().getPartitionId()));
long[][] results = partResult.getNodeIdToNeighbors();
for (int i = start; i < end; i++) {
nodeIdToNeighbors.put(nodeIds[i], results[i - start]);
}
}
return new GetNeighborAliasTableResult(nodeIdToNeighbors);
}
use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult 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);
}
Aggregations