Search in sources :

Example 16 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition 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 17 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition 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)

Example 18 with RowBasedPartition

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

the class GetSort method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = row.getStorage().iterator();
    row.startWrite();
    try {
        while (it.hasNext()) {
            Long2ObjectMap.Entry<IElement> next = it.next();
            DynamicNeighborElement ele = (DynamicNeighborElement) next.getValue();
            if (ele != null) {
                ele.trans();
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) DynamicNeighborElement(com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 19 with RowBasedPartition

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

the class GetOutDegreeFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetOutDegreeParam param = (PartGetOutDegreeParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongIntRow row = (ServerLongIntRow) (((RowBasedPartition) part).getRow(0));
    long[] nodeIds = param.getNodeIds();
    int[] outDegrees = new int[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        outDegrees[i] = row.get(nodeIds[i]);
    }
    return new PartGetOutDegreeResult(part.getPartitionKey().getPartitionId(), outDegrees);
}
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 20 with RowBasedPartition

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

the class QuantifyDoubleFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
    if (part != null) {
        QuantifyDoublePartUParam cp = (QuantifyDoublePartUParam) partParam;
        ServerRow row = part.getRow(cp.getRowId());
        if (row != null) {
            update(row, cp.getArraySlice());
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) QuantifyDoublePartUParam(com.tencent.angel.ml.psf.compress.QuantifyDoubleParam.QuantifyDoublePartUParam) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition)

Aggregations

RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)38 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)6 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 Vector (com.tencent.angel.ml.math2.vector.Vector)2 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)1 NeighborsAliasTableElement (com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)1 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)1 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)1