Search in sources :

Example 1 with ServerLongFloatRow

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

the class GetLabels 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();
                ServerLongFloatRow row = (ServerLongFloatRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
                LongArrayList keys = new LongArrayList();
                FloatArrayList vals = new FloatArrayList();
                for (int i = 0; i < nodeIds.length; i++) {
                    if (row.exist(nodeIds[i])) {
                        keys.add(nodeIds[i]);
                        vals.add(row.get(nodeIds[i]));
                    }
                }
                return new GetLabelsPartResult(keys.toLongArray(), vals.toFloatArray());
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList)

Example 2 with ServerLongFloatRow

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

the class RowSplitCombineUtils method combineServerLongFloatRowSplits.

private static Vector combineServerLongFloatRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    long colNum = matrixMeta.getColNum();
    int elemNum = 0;
    int size = rowSplits.size();
    for (int i = 0; i < size; i++) {
        elemNum += rowSplits.get(i).size();
    }
    LongFloatVector row = VFactory.sparseLongKeyFloatVector(colNum, elemNum);
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    Collections.sort(rowSplits, serverRowComp);
    int clock = Integer.MAX_VALUE;
    for (int i = 0; i < size; i++) {
        if (rowSplits.get(i) == null) {
            continue;
        }
        if (rowSplits.get(i).getClock() < clock) {
            clock = rowSplits.get(i).getClock();
        }
        ((ServerLongFloatRow) rowSplits.get(i)).mergeTo(row);
    }
    row.setClock(clock);
    return row;
}
Also used : ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector)

Example 3 with ServerLongFloatRow

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

the class MergeUtils method combineServerLongFloatRowSplits.

private static Vector combineServerLongFloatRowSplits(List<ServerRow> rowSplits, MatrixMeta matrixMeta, int rowIndex) {
    long colNum = matrixMeta.getColNum();
    int elemNum = 0;
    int size = rowSplits.size();
    for (int i = 0; i < size; i++) {
        elemNum += rowSplits.get(i).size();
    }
    LongFloatVector row = VFactory.sparseLongKeyFloatVector(colNum, elemNum);
    row.setMatrixId(matrixMeta.getId());
    row.setRowId(rowIndex);
    Collections.sort(rowSplits, serverRowComp);
    for (int i = 0; i < size; i++) {
        if (rowSplits.get(i) == null) {
            continue;
        }
        ((ServerLongFloatRow) rowSplits.get(i)).mergeTo(row);
    }
    return row;
}
Also used : ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector)

Aggregations

ServerLongFloatRow (com.tencent.angel.ps.storage.vector.ServerLongFloatRow)3 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)1 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)1 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)1 FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)1 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)1