Search in sources :

Example 1 with ServerLongAnyRow

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

the class GetNodeTypes 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<int[]> nodeIdToTypes = new Long2ObjectOpenHashMap<>(nodeIds.length);
                for (long nodeId : nodeIds) {
                    if (row.get(nodeId) == null) {
                        // If node not exist, just skip
                        continue;
                    }
                    int[] types = ((GraphNode) (row.get(nodeId))).getTypes();
                    if (types != null) {
                        nodeIdToTypes.put(nodeId, types);
                    }
                }
                return new PartGetIntArrayAttrsResult(param.getPartKey().getPartitionId(), nodeIdToTypes);
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : PartGetIntArrayAttrsResult(com.tencent.angel.graph.client.psf.get.utils.PartGetIntArrayAttrsResult) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) 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 2 with ServerLongAnyRow

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

the class InitNodeFeats method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
    // Get node ids and features
    ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
    long[] nodeIds = split.getKeys();
    IElement[] features = 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.setFeats(((Feature) features[i]).getFeatures());
        }
    } 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)

Example 3 with ServerLongAnyRow

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

the class InitLabels method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    GeneralPartUpdateParam param = (GeneralPartUpdateParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    ILongKeyAnyValuePartOp keyValuePart = (ILongKeyAnyValuePartOp) param.getKeyValuePart();
    long[] nodeIds = keyValuePart.getKeys();
    IElement[] neighbors = keyValuePart.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.setLabels(((Labels) neighbors[i]).getWeights());
        }
    } 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)

Example 4 with ServerLongAnyRow

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

the class InitNodes 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[] featuress = split.getValues();
    row.startWrite();
    try {
        for (int i = 0; i < nodeIds.length; i++) {
            row.set(nodeIds[i], featuress[i]);
        }
    } finally {
        row.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyAnyValuePartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)

Example 5 with ServerLongAnyRow

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

the class SampleUtils method sampleNodeFeatByCount.

public static IntFloatVector[] sampleNodeFeatByCount(ServerRow row, int count, long seed) {
    Random r = new Random(seed);
    IntFloatVector[] feats = new IntFloatVector[count];
    int bound = row.size() - count;
    int skip = bound > 0 ? r.nextInt(bound) : 0;
    ObjectIterator<Entry<IElement>> it = (((ServerLongAnyRow) row).getStorage()).iterator();
    it.skip(skip);
    for (int i = 0; i < count; i++) {
        feats[i] = ((GraphNode) it.next().getValue()).getFeats();
    }
    return feats;
}
Also used : Entry(it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry) Random(java.util.Random) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

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