Search in sources :

Example 61 with ServerLongAnyRow

use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.

the class SampleNodeFeats method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    SampleNodeFeatsPartParam param = (SampleNodeFeatsPartParam) partParam;
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
    int size = Math.min(row.size(), param.getSize());
    IntFloatVector[] feats = new IntFloatVector[size];
    Random rand = new Random(System.currentTimeMillis());
    // sample continuously beginning from a random index
    int bound = row.size() - size;
    int skip = bound > 0 ? rand.nextInt(bound) : 0;
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = row.getStorage().iterator();
    it.skip(skip);
    for (int i = 0; i < size; i++) {
        feats[i] = ((Node) it.next().getValue()).getFeats();
    }
    return new PartGetNodeFeatsResult(param.getPartKey().getPartitionId(), feats);
}
Also used : PartGetNodeFeatsResult(com.tencent.angel.graph.client.getnodefeats2.PartGetNodeFeatsResult) Random(java.util.Random) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 62 with ServerLongAnyRow

use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.

the class SampleNeighbor method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    SampleNeighborPartParam param = (SampleNeighborPartParam) partParam;
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
    return new SampleNeighborPartResult(param.getPartKey().getPartitionId(), row, param.getKeys(), param.getNumSample(), param.getSampleTypes());
}
Also used : ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 63 with ServerLongAnyRow

use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.

the class NnzEdge method processRow.

@Override
public double processRow(ServerRow row) {
    LongElementStorage storage = ((ServerLongAnyRow) row).getStorage();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = storage.iterator();
    long size = 0;
    while (it.hasNext()) {
        Node node = (Node) (it.next().getValue());
        if (node.getNeighbors() != null) {
            size += node.getNeighbors().length;
        }
    }
    return size;
}
Also used : Node(com.tencent.angel.graph.data.Node) LongElementStorage(com.tencent.angel.ps.storage.vector.storage.LongElementStorage) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 64 with ServerLongAnyRow

use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.

the class NnzNeighbor method processRow.

@Override
public double processRow(ServerRow row) {
    LongElementStorage storage = ((ServerLongAnyRow) row).getStorage();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = storage.iterator();
    int size = 0;
    while (it.hasNext()) {
        Node node = (Node) (it.next().getValue());
        if (node.getNeighbors() != null) {
            size++;
        }
    }
    return size;
}
Also used : Node(com.tencent.angel.graph.data.Node) LongElementStorage(com.tencent.angel.ps.storage.vector.storage.LongElementStorage) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 65 with ServerLongAnyRow

use of com.tencent.angel.ps.storage.vector.ServerLongAnyRow in project angel by Tencent.

the class InitEdgeFeats method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
    // Get nodes and features
    ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
    long[] nodeIds = split.getKeys();
    IElement[] edgeFeatures = split.getValues();
    row.startWrite();
    try {
        for (int i = 0; i < nodeIds.length; i++) {
            GraphNode graphNode = (GraphNode) row.get(nodeIds[i]);
            if (graphNode == null) {
                graphNode = new GraphNode();
                row.set(nodeIds[i], graphNode);
            }
            graphNode.setNeighbors(((LongEdgeFeats) edgeFeatures[i]).getNodeIds());
            graphNode.setEdgeFeatures(((LongEdgeFeats) edgeFeatures[i]).getFeats());
        }
    } finally {
        row.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) GraphNode(com.tencent.angel.graph.data.GraphNode) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyAnyValuePartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)

Aggregations

ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)69 IElement (com.tencent.angel.ps.storage.vector.element.IElement)19 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)15 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)15 ILongKeyAnyValuePartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)13 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)12 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)12 GraphNode (com.tencent.angel.graph.data.GraphNode)11 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)11 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)11 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)9 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)9 Random (java.util.Random)9 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)8 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)8 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)7 Node (com.tencent.angel.graph.data.Node)7 LongElementStorage (com.tencent.angel.ps.storage.vector.storage.LongElementStorage)6 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)3 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)3