Search in sources :

Example 26 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GraphMatrixUtils method getPSLongKeyRow.

public static ServerLongAnyRow getPSLongKeyRow(PSContext psContext, GeneralPartUpdateParam 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 27 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GraphMatrixUtils method getPSIntKeyRow.

public static ServerIntAnyRow getPSIntKeyRow(PSContext psContext, GeneralPartUpdateParam 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)

Example 28 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GraphMatrixUtils method getPSIntKeyRow.

public static ServerIntAnyRow getPSIntKeyRow(PSContext psContext, PartitionGetParam 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)

Example 29 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GraphMatrixUtils method getPSLongKeyIntRow.

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

Example 30 with ServerPartition

use of com.tencent.angel.ps.storage.partition.ServerPartition in project angel by Tencent.

the class GetNeighborAliasTable method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetNeighborAliasTableParam param = (PartGetNeighborAliasTableParam) 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
        NeighborsAliasTableElement element = (NeighborsAliasTableElement) (row.get(nodeId));
        if (element == null) {
            neighbors[i] = null;
        } else {
            long[] nodeNeighbors = element.getNeighborIds();
            if (nodeNeighbors == null || nodeNeighbors.length == 0 || count[i] <= 0) {
                neighbors[i] = null;
            } else {
                neighbors[i] = new long[count[i]];
                // start sampling by alias table for count times
                float[] accept = element.getAccept();
                int[] alias = element.getAlias();
                for (int j = 0; j < count[i]; j++) {
                    int index = r.nextInt(nodeNeighbors.length);
                    float ac = r.nextFloat();
                    if (ac < accept[index]) {
                        neighbors[i][j] = nodeNeighbors[index];
                    } else {
                        neighbors[i][j] = nodeNeighbors[alias[index]];
                    }
                }
            }
        }
    }
    return new PartGetNeighborAliasTableResult(part.getPartitionKey().getPartitionId(), neighbors);
}
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) Random(java.util.Random) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Aggregations

ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)30 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)22 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)11 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 Path (org.apache.hadoop.fs.Path)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)2 ObjectNotFoundException (com.tencent.angel.ps.server.data.exception.ObjectNotFoundException)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 IOException (java.io.IOException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 ServiceException (com.google.protobuf.ServiceException)1 PartitionKey (com.tencent.angel.PartitionKey)1 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 FloatVector (com.tencent.angel.ml.math2.vector.FloatVector)1