Search in sources :

Example 1 with TypeNeighborElement

use of com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement 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);
}
Also used : Long2IntOpenHashMap(it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp) TypeNeighborElement(com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement) Entry(it.unimi.dsi.fastutil.longs.Long2IntMap.Entry) Random(java.util.Random) PartGetLongsResult(com.tencent.angel.graph.common.psf.result.PartGetLongsResult)

Aggregations

PartGetLongsResult (com.tencent.angel.graph.common.psf.result.PartGetLongsResult)1 TypeNeighborElement (com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)1 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)1 Entry (it.unimi.dsi.fastutil.longs.Long2IntMap.Entry)1 Long2IntOpenHashMap (it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap)1 Random (java.util.Random)1