Search in sources :

Example 1 with PartGetLongsResult

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

Example 2 with PartGetLongsResult

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);
}
Also used : PartGetLongsResult(com.tencent.angel.graph.common.psf.result.PartGetLongsResult) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) PartGetLongsResult(com.tencent.angel.graph.common.psf.result.PartGetLongsResult) GetLongsResult(com.tencent.angel.graph.common.psf.result.GetLongsResult)

Aggregations

PartGetLongsResult (com.tencent.angel.graph.common.psf.result.PartGetLongsResult)2 GetLongsResult (com.tencent.angel.graph.common.psf.result.GetLongsResult)1 TypeNeighborElement (com.tencent.angel.graph.model.neighbor.simplewithtype.TypeNeighborElement)1 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)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 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 Random (java.util.Random)1