Search in sources :

Example 1 with RowBasedPartition

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

the class LongIndexGet method partitionGet.

/**
 * Each server partition execute this function and return values of specified index.
 *
 * @param partParam the partition parameter
 * @return values of specified index
 */
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    long startTs = System.currentTimeMillis();
    RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
    if (part == null) {
        throw new RuntimeException("Can not find partition " + partParam.getPartKey().getPartitionId());
    }
    int rowId = ((LongIndexPartGetParam) partParam).getRowId();
    long[] indexes = ((LongIndexPartGetParam) partParam).getIndex();
    ServerRow row = part.getRow(rowId);
    if (row == null) {
        throw new RuntimeException("Can not find row " + rowId + " in partition " + partParam.getPartKey().getPartitionId());
    }
    PartitionGetResult result;
    if (row instanceof ServerLongDoubleRow) {
        result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerLongDoubleRow) row).get(indexes));
    } else if (row instanceof ServerLongFloatRow) {
        result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerLongFloatRow) row).get(indexes));
    } else if (row instanceof ServerLongLongRow) {
        result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerLongLongRow) row).get(indexes));
    } else if (row instanceof ServerLongIntRow) {
        result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerLongIntRow) row).get(indexes));
    } else {
        throw new UnsupportedOperationException("Index get use long type key not support " + row.getClass().getName() + "now");
    }
    LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
    return result;
}
Also used : RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 2 with RowBasedPartition

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

the class Zero method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
    if (part != null) {
        int startRow = part.getPartitionKey().getStartRow();
        int endRow = part.getPartitionKey().getEndRow();
        for (int i = startRow; i < endRow; i++) {
            ServerRow row = part.getRow(i);
            if (row == null) {
                continue;
            }
            zero(row);
        }
    }
}
Also used : ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition)

Example 3 with RowBasedPartition

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

the class GetNodeAttrs method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetNodeAttrsParam param = (PartGetNodeAttrsParam) 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();
    float[][] attrs = new float[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
        FloatArrayElement element = (FloatArrayElement) (row.get(nodeId));
        if (element == null) {
            attrs[i] = null;
        } else {
            float[] nodeAttrs = element.getData();
            if (nodeAttrs == null || nodeAttrs.length == 0) {
                attrs[i] = null;
            } else if (count <= 0 || nodeAttrs.length <= count) {
                attrs[i] = nodeAttrs;
            } else {
                attrs[i] = new float[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()) % nodeAttrs.length;
                if (startPos + count <= nodeAttrs.length) {
                    System.arraycopy(nodeAttrs, startPos, attrs[i], 0, count);
                } else {
                    System.arraycopy(nodeAttrs, startPos, attrs[i], 0, nodeAttrs.length - startPos);
                    System.arraycopy(nodeAttrs, 0, attrs[i], nodeAttrs.length - startPos, count - (nodeAttrs.length - startPos));
                }
            }
        }
    }
    return new PartGetNodeAttrsResult(part.getPartitionKey().getPartitionId(), attrs);
}
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) FloatArrayElement(com.tencent.angel.ps.storage.vector.element.FloatArrayElement) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 4 with RowBasedPartition

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

the class GetNodeFeats method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetNodeFeatsParam param = (PartGetNodeFeatsParam) 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();
    IntFloatVector[] feats = new IntFloatVector[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        if (row.get(nodeIds[i]) == null) {
            continue;
        }
        feats[i] = ((Node) (row.get(nodeIds[i]))).getFeats();
    }
    return new PartGetNodeFeatsResult(part.getPartitionKey().getPartitionId(), feats);
}
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) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 5 with RowBasedPartition

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

the class GetNeighborWithByteAttr method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartSampleNeighborWithAttrParam param = (PartSampleNeighborWithAttrParam) 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();
    NeighborsAttrsCompressedElement[] elementsCompressed = new NeighborsAttrsCompressedElement[nodeIds.length];
    for (int i = 0; i < nodeIds.length; i++) {
        long nodeId = nodeIds[i];
        // Get node neighbors
        NeighborsAttrsCompressedElement elem = (NeighborsAttrsCompressedElement) (row.get(nodeId));
        if (elem == null) {
            elementsCompressed[i] = null;
        } else {
            elementsCompressed[i] = elem;
        }
    }
    return new PartGetNeighborWithAttrResult(part.getPartitionKey().getPartitionId(), elementsCompressed);
}
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)

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