Search in sources :

Example 16 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class GraphMatrixUtils method getPSAnyKeyRow.

public static ServerAnyAnyRow getPSAnyKeyRow(PSContext psContext, PartitionUpdateParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    return (ServerAnyAnyRow) (((RowBasedPartition) part).getRow(0));
}
Also used : ServerAnyAnyRow(com.tencent.angel.ps.storage.vector.ServerAnyAnyRow) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 17 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class GraphMatrixUtils method getPSLongKeyRow.

public static ServerLongAnyRow getPSLongKeyRow(PSContext psContext, GeneralPartGetParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    return (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 18 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class SampleNeighbor method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartSampleNeighborParam param = (PartSampleNeighborParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
    long[] nodeIds = param.getNodeIds();
    long[][] neighbors = new long[nodeIds.length][];
    int count = param.getCount();
    Random r = new Random(System.currentTimeMillis());
    for (int i = 0; i < nodeIds.length; i++) {
        long nodeId = nodeIds[i];
        // Get node neighbor number
        Node element = (Node) (row.get(nodeId));
        if (element == null) {
            neighbors[i] = null;
        } else {
            long[] nodeNeighbors = element.getNeighbors();
            if (nodeNeighbors == null || nodeNeighbors.length == 0) {
                neighbors[i] = null;
            } else if (count <= 0 || nodeNeighbors.length <= count) {
                neighbors[i] = nodeNeighbors;
            } else {
                neighbors[i] = new long[count];
                // If the neighbor number > count, just copy a range of neighbors to the result array, the copy position is random
                int startPos = Math.abs(r.nextInt()) % nodeNeighbors.length;
                if (startPos + count <= nodeNeighbors.length) {
                    System.arraycopy(nodeNeighbors, startPos, neighbors[i], 0, count);
                } else {
                    System.arraycopy(nodeNeighbors, startPos, neighbors[i], 0, nodeNeighbors.length - startPos);
                    System.arraycopy(nodeNeighbors, 0, neighbors[i], nodeNeighbors.length - startPos, count - (nodeNeighbors.length - startPos));
                }
            }
        }
    }
    return new PartSampleNeighborResult(part.getPartitionKey().getPartitionId(), neighbors);
}
Also used : Random(java.util.Random) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Node(com.tencent.angel.graph.data.Node) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 19 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class SampleNeighbor method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartSampleNeighborParam param = (PartSampleNeighborParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
    long[] nodeIds = param.getNodeIds();
    long[][] neighbors = new long[nodeIds.length][];
    int count = param.getCount();
    Random r = new Random();
    for (int i = 0; i < nodeIds.length; i++) {
        long nodeId = nodeIds[i];
        // Get node neighbor number
        LongArrayElement element = (LongArrayElement) (row.get(nodeId));
        if (element == null) {
            neighbors[i] = null;
        } else {
            long[] nodeNeighbors = element.getData();
            if (nodeNeighbors == null || nodeNeighbors.length == 0) {
                neighbors[i] = null;
            } else if (count <= 0 || nodeNeighbors.length <= count) {
                neighbors[i] = nodeNeighbors;
            } else {
                neighbors[i] = new long[count];
                // If the neighbor number > count, just copy a range of neighbors to the result array, the copy position is random
                int startPos = Math.abs(r.nextInt()) % nodeNeighbors.length;
                if (startPos + count <= nodeNeighbors.length) {
                    System.arraycopy(nodeNeighbors, startPos, neighbors[i], 0, count);
                } else {
                    System.arraycopy(nodeNeighbors, startPos, neighbors[i], 0, nodeNeighbors.length - startPos);
                    System.arraycopy(nodeNeighbors, 0, neighbors[i], nodeNeighbors.length - startPos, count - (nodeNeighbors.length - startPos));
                }
            }
        }
    }
    return new PartSampleNeighborResult(part.getPartitionKey().getPartitionId(), neighbors);
}
Also used : Random(java.util.Random) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 20 with ServerMatrix

use of com.tencent.angel.ps.storage.matrix.ServerMatrix in project angel by Tencent.

the class GraphMatrixUtils method getPSIntKeyRow.

public static ServerIntAnyRow getPSIntKeyRow(PSContext psContext, GeneralPartGetParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    return (ServerIntAnyRow) (((RowBasedPartition) part).getRow(0));
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerIntAnyRow(com.tencent.angel.ps.storage.vector.ServerIntAnyRow) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Aggregations

ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)39 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)22 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 Random (java.util.Random)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 CSRPartition (com.tencent.angel.ps.storage.partition.CSRPartition)3 IntCSRStorage (com.tencent.angel.ps.storage.partition.storage.IntCSRStorage)3 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 AngelException (com.tencent.angel.exception.AngelException)2 MatrixFormat (com.tencent.angel.model.output.format.MatrixFormat)2 Pair (com.tencent.angel.protobuf.generated.MLProtos.Pair)2 ParameterServer (com.tencent.angel.ps.ParameterServer)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 MatrixStorageManager (com.tencent.angel.ps.storage.MatrixStorageManager)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2