Search in sources :

Example 26 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class IndexGet 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());
    PartitionGetResult result = null;
    if (part != null) {
        int rowId = ((IndexPartGetParam) partParam).getRowId();
        int[] indexes = ((IndexPartGetParam) partParam).getIndexes();
        ServerRow row = part.getRow(rowId);
        RowType rowType = row.getRowType();
        switch(rowType) {
            case T_DOUBLE_DENSE:
            case T_DOUBLE_SPARSE:
            case T_DOUBLE_DENSE_COMPONENT:
            case T_DOUBLE_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerIntDoubleRow) row).get(indexes));
                    break;
                }
            case T_FLOAT_DENSE:
            case T_FLOAT_SPARSE:
            case T_FLOAT_DENSE_COMPONENT:
            case T_FLOAT_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerIntFloatRow) row).get(indexes));
                    break;
                }
            case T_INT_DENSE:
            case T_INT_SPARSE:
            case T_INT_DENSE_COMPONENT:
            case T_INT_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerIntIntRow) row).get(indexes));
                    break;
                }
            case T_LONG_DENSE:
            case T_LONG_SPARSE:
            case T_LONG_DENSE_COMPONENT:
            case T_LONG_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerIntLongRow) row).get(indexes));
                    break;
                }
            default:
                throw new UnsupportedOperationException("Unsupport operation: update " + rowType + " to " + this.getClass().getName());
        }
    }
    LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
    return result;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 27 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class PartitionGetRowResult method deserialize.

@Override
public void deserialize(ByteBuf buf) {
    if (buf.readableBytes() == 0) {
        rowSplit = null;
        return;
    }
    RowType type = RowType.valueOf(buf.readInt());
    rowSplit = ServerRowFactory.createEmptyServerRow(type);
    rowSplit.deserialize(buf);
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType)

Example 28 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class PartitionGetRowsResult method deserialize.

@Override
public void deserialize(ByteBuf buf) {
    int size = buf.readInt();
    rowSplits = new ArrayList<ServerRow>(size);
    for (int i = 0; i < size; i++) {
        RowType type = RowType.valueOf(buf.readInt());
        ServerRow rowSplit = ServerRowFactory.createEmptyServerRow(type);
        rowSplit.deserialize(buf);
        rowSplits.add(rowSplit);
    }
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow)

Example 29 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class MatrixClientImpl method generateEmptyVec.

private Vector generateEmptyVec(int rowId) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    Vector vector;
    if (rowType.isInt()) {
        if (rowType.isLongKey())
            vector = VFactory.sparseLongKeyIntVector(0, 0);
        else
            vector = VFactory.sparseIntVector(0, 0);
    } else if (rowType.isLong()) {
        if (rowType.isLongKey())
            vector = VFactory.sparseLongKeyLongVector(0, 0);
        else
            vector = VFactory.sparseLongVector(0, 0);
    } else if (rowType.isFloat()) {
        if (rowType.isLongKey())
            vector = VFactory.sparseLongKeyFloatVector(0, 0);
        else
            vector = VFactory.sparseFloatVector(0, 0);
    } else if (rowType.isDouble()) {
        if (rowType.isLongKey())
            vector = VFactory.sparseLongKeyDoubleVector(0, 0);
        else
            vector = VFactory.sparseDoubleVector(0, 0);
    } else {
        throw new AngelException("Unsupport row type");
    }
    vector.setRowId(rowId);
    vector.setMatrixId(matrixId);
    return vector;
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 30 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class VectorStorageUtils method deserialize.

public static Vector deserialize(ByteBuf buf) {
    // Row type
    RowType rowType = RowType.valueOf(buf.readInt());
    // Storage method
    StorageMethod storageMethod = StorageMethod.valuesOf(buf.readInt());
    // Key type
    BasicType keyType = BasicType.valuesOf(buf.readInt());
    // Value type
    BasicType valueType = BasicType.valuesOf(buf.readInt());
    // Vector dim
    long dim = buf.readLong();
    // Vector length
    long len = buf.readLong();
    // Init the vector
    Vector vector = VectorFactory.getVector(rowType, storageMethod, keyType, valueType, dim, len);
    // Vector data
    deserializeVector(buf, vector);
    return vector;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) IntKeyVector(com.tencent.angel.ml.math2.vector.IntKeyVector) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) IntVector(com.tencent.angel.ml.math2.vector.IntVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) FloatVector(com.tencent.angel.ml.math2.vector.FloatVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) DoubleVector(com.tencent.angel.ml.math2.vector.DoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) LongVector(com.tencent.angel.ml.math2.vector.LongVector)

Aggregations

RowType (com.tencent.angel.ml.matrix.RowType)38 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 MatrixFilesMeta (com.tencent.angel.model.output.format.MatrixFilesMeta)7 IOException (java.io.IOException)7 Vector (com.tencent.angel.ml.math2.vector.Vector)5 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)4 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)4 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)4 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)3 PartitionKey (com.tencent.angel.PartitionKey)2 AngelException (com.tencent.angel.exception.AngelException)2 RowBasedMatrix (com.tencent.angel.ml.math2.matrix.RowBasedMatrix)2 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)2 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)2 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 BlasDoubleMatrix (com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix)1 BlasFloatMatrix (com.tencent.angel.ml.math2.matrix.BlasFloatMatrix)1 RBIntDoubleMatrix (com.tencent.angel.ml.math2.matrix.RBIntDoubleMatrix)1 RBIntFloatMatrix (com.tencent.angel.ml.math2.matrix.RBIntFloatMatrix)1