use of com.tencent.angel.graph.common.psf.result.PartGetLongsResult in project angel by Tencent.
the class Sample method partitionGet.
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartSampleParam param = (PartSampleParam) partParam;
KeyPart keyPart = param.getIndicesPart();
int sampleType = param.getSampleType();
long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
Long2IntOpenHashMap nodeIdToSizes = new Long2IntOpenHashMap(nodeIds.length);
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToSizes.addTo(nodeIds[i], 1);
}
ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
Random r = new Random();
long[] distinctNodeIds = new long[nodeIdToSizes.size()];
long[][] samples = new long[nodeIdToSizes.size()][];
ObjectIterator<Entry> iter = nodeIdToSizes.long2IntEntrySet().fastIterator();
int index = 0;
while (iter.hasNext()) {
Entry entry = iter.next();
distinctNodeIds[index] = entry.getLongKey();
TypeNeighborElement element = (TypeNeighborElement) row.get(distinctNodeIds[index]);
samples[index] = element.Sample(sampleType, r, distinctNodeIds[index], entry.getIntValue());
index++;
}
return new PartGetLongsResult(distinctNodeIds, samples);
}
use of com.tencent.angel.graph.common.psf.result.PartGetLongsResult in project angel by Tencent.
the class Sample method merge.
@Override
public GetResult merge(List<PartitionGetResult> partResults) {
int resultSize = 0;
for (PartitionGetResult result : partResults) {
resultSize += ((PartGetLongsResult) result).getData().length;
}
Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
for (PartitionGetResult result : partResults) {
PartGetLongsResult partResult = (PartGetLongsResult) result;
long[] nodeIds = partResult.getNodeIds();
long[][] samples = partResult.getData();
for (int i = 0; i < nodeIds.length; i++) {
nodeIdToNeighbors.put(nodeIds[i], samples[i]);
}
}
return new GetLongsResult(nodeIdToNeighbors);
}
Aggregations