Search in sources :

Example 21 with RowType

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

the class ByteBufSerdeUtils method deserializeVector.

public static Vector deserializeVector(ByteBuf in) {
    int rowId = deserializeInt(in);
    long dim = deserializeLong(in);
    RowType type = RowType.valueOf(deserializeInt(in));
    Vector vector;
    switch(type) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            vector = deserializeIntDoubleVector(in, dim);
            break;
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            vector = deserializeIntFloatVector(in, dim);
            break;
        case T_FLOAT_SPARSE_LONGKEY:
            vector = deserializeLongFloatVector(in, dim);
            break;
        case T_INT_SPARSE_LONGKEY:
            vector = deserializeLongIntVector(in, dim);
            break;
        // TODO: other vector type
        default:
            throw new UnsupportedOperationException("Unsupport vector type " + type);
    }
    vector.setRowId(rowId);
    return vector;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 22 with RowType

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

the class ByteBufSerdeUtils method deserializeKeyValuePart.

public static KeyValuePart deserializeKeyValuePart(ByteBuf in) {
    boolean isComp = ByteBufSerdeUtils.deserializeBoolean(in);
    KeyValuePart keyValuePart;
    if (isComp) {
        keyValuePart = new CompStreamKeyValuePart();
    } else {
        RouterType routerType = RouterType.valueOf(deserializeInt(in));
        RowType keyValueType = RowType.valueOf(deserializeInt(in));
        keyValuePart = DataPartFactory.createKeyValuePart(keyValueType, routerType);
    }
    keyValuePart.deserialize(in);
    return keyValuePart;
}
Also used : RouterType(com.tencent.angel.psagent.matrix.transport.router.RouterType) RowType(com.tencent.angel.ml.matrix.RowType) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 23 with RowType

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

the class RowSplitCombineUtils method combineIndexRowSplits.

/**
 * Combine the row splits.
 *
 * @param matrixId Matrix id
 * @param rowId row id
 * @param resultSize keys number
 * @param keyParts keys partitions
 * @param valueParts values partitions
 * @return merged vector
 */
public static Vector combineIndexRowSplits(int matrixId, int rowId, int resultSize, KeyPart[] keyParts, ValuePart[] valueParts) {
    // Get matrix meta
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineIntDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineIntFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineIntIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineIntLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineLongDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineLongFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_INT_SPARSE_LONGKEY:
            return combineLongIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_LONG_SPARSE_LONGKEY:
            return combineLongLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        default:
            throw new UnsupportedOperationException("unsupport row type " + rowType);
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Example 24 with RowType

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

the class MergeUtils method combineIndexRowSplits.

/**
 * Combine the row splits.
 *
 * @param matrixId Matrix id
 * @param rowId row id
 * @param resultSize keys number
 * @param keyParts keys partitions
 * @param valueParts values partitions
 * @return merged vector
 */
public static Vector combineIndexRowSplits(int matrixId, int rowId, int resultSize, KeyPart[] keyParts, ValuePart[] valueParts) {
    // Get matrix meta
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineIntDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineIntFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineIntIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineIntLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineLongDoubleIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineLongFloatIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_INT_SPARSE_LONGKEY:
            return combineLongIntIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        case T_LONG_SPARSE_LONGKEY:
            return combineLongLongIndexRowSplits(matrixId, rowId, resultSize, keyParts, valueParts, matrixMeta);
        default:
            throw new UnsupportedOperationException("unsupport row type " + rowType);
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Example 25 with RowType

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

the class IndexGet method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    long startTs = System.currentTimeMillis();
    RowType rowType = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(param.getMatrixId()).getRowType();
    GetRowResult result;
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseDoubleVector((IndexGetParam) param, partResults));
            break;
        case T_DOUBLE_SPARSE_COMPONENT:
        case T_DOUBLE_DENSE_COMPONENT:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseDoubleCompVector((IndexGetParam) param, partResults));
            break;
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseFloatVector((IndexGetParam) param, partResults));
            break;
        case T_FLOAT_SPARSE_COMPONENT:
        case T_FLOAT_DENSE_COMPONENT:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseFloatCompVector((IndexGetParam) param, partResults));
            break;
        case T_INT_DENSE:
        case T_INT_SPARSE:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseIntVector((IndexGetParam) param, partResults));
            break;
        case T_INT_DENSE_COMPONENT:
        case T_INT_SPARSE_COMPONENT:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseIntCompVector((IndexGetParam) param, partResults));
            break;
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseLongVector((IndexGetParam) param, partResults));
            break;
        case T_LONG_DENSE_COMPONENT:
        case T_LONG_SPARSE_COMPONENT:
            result = new GetRowResult(ResponseType.SUCCESS, ValuesCombineUtils.mergeSparseLongCompVector((IndexGetParam) param, partResults));
            break;
        default:
            throw new UnsupportedOperationException("Unsupport operation: update " + rowType + " to " + this.getClass().getName());
    }
    return result;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) GetRowResult(com.tencent.angel.ml.matrix.psf.get.getrow.GetRowResult)

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