Search in sources :

Example 6 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class GetNeighbors method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    switch(keyPart.getKeyType()) {
        case LONG:
            {
                // Long type node id
                long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
                ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
                Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
                for (long nodeId : nodeIds) {
                    if (row.get(nodeId) == null) {
                        // If node not exist, just skip
                        continue;
                    }
                    long[] neighbors = ((GraphNode) (row.get(nodeId))).getNeighbors();
                    if (neighbors != null) {
                        nodeIdToNeighbors.put(nodeId, neighbors);
                    }
                }
                return new PartGetNeighborsResult(param.getPartKey().getPartitionId(), nodeIdToNeighbors);
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 7 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart 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 8 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class LongKeysGetParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    // Split
    KeyPart[] nodeIdsParts = RouterUtils.split(meta, 0, nodeIds, false);
    // Generate Part psf get param
    List<PartitionGetParam> partParams = new ArrayList<>(parts.length);
    assert parts.length == nodeIdsParts.length;
    for (int i = 0; i < parts.length; i++) {
        if (nodeIdsParts[i] != null && nodeIdsParts[i].size() > 0) {
            partParams.add(new GeneralPartGetParam(matrixId, parts[i], nodeIdsParts[i]));
        }
    }
    return partParams;
}
Also used : GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 9 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class SampleNeighborParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] partitions = meta.getPartitionKeys();
    // Split nodeIds
    KeyPart[] splits = RouterUtils.split(meta, 0, nodeIds);
    assert partitions.length == splits.length;
    // Generate rpc params
    List<PartitionGetParam> partParams = new ArrayList<>(partitions.length);
    for (int i = 0; i < partitions.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new PartSampleNeighborParam(matrixId, partitions[i], splits[i], count));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 10 with KeyPart

use of com.tencent.angel.psagent.matrix.transport.router.KeyPart in project angel by Tencent.

the class SampleNeighborWithTypeParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] partitions = meta.getPartitionKeys();
    // Split nodeIds
    KeyPart[] splits = RouterUtils.split(meta, 0, nodeIds);
    assert partitions.length == splits.length;
    // Generate node ids
    List<PartitionGetParam> partParams = new ArrayList<>(partitions.length);
    for (int i = 0; i < partitions.length; i++) {
        if (splits[i] != null && splits[i].size() > 0)
            partParams.add(new PartSampleNeighborWithTypeParam(matrixId, partitions[i], splits[i], count, sampleType));
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Aggregations

KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)26 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)13 PartitionKey (com.tencent.angel.PartitionKey)12 ArrayList (java.util.ArrayList)10 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)9 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)9 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)8 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)8 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)7 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)3 PartGetFloatArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetFloatArrayAttrsResult)2 PartGetIntArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetIntArrayAttrsResult)2 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)2 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)2 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)2 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)2 ValuePart (com.tencent.angel.psagent.matrix.transport.router.ValuePart)2 DynamicLongArray (com.tencent.angel.common.collections.DynamicLongArray)1