Search in sources :

Example 6 with RowType

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

the class ServerMatrix method init.

public void init() {
    MatrixMeta matrixMeta = context.getMatrixMetaManager().getMatrixMeta(matrixId);
    Map<Integer, PartitionMeta> partMetas = matrixMeta.getPartitionMetas();
    String sourceClass = matrixMeta.getAttribute(AngelConf.ANGEL_PS_PARTITION_SOURCE_CLASS, AngelConf.DEFAULT_ANGEL_PS_PARTITION_SOURCE_CLASS);
    // Get server partition class
    Class<? extends IServerPartition> partClass;
    try {
        partClass = matrixMeta.getPartitionClass();
        // If partition class is not set, just use the default partition class
        if (partClass == null) {
            partClass = MatrixConf.DEFAULT_SERVER_PARTITION_CLASS;
        }
    } catch (Throwable e) {
        LOG.fatal("Server partition class failed ", e);
        throw new RuntimeException(e);
    }
    // Get server partition storage class type
    Class<? extends IServerPartitionStorage> storageClass;
    try {
        storageClass = matrixMeta.getPartitionStorageClass();
    } catch (Throwable e) {
        LOG.fatal("Server partition class failed ", e);
        throw new RuntimeException(e);
    }
    RowType rowType = matrixMeta.getRowType();
    // Get value class
    Class<? extends IElement> valueClass = null;
    if (rowType.isComplexValue()) {
        try {
            valueClass = matrixMeta.getValueClass();
        } catch (Throwable e) {
            LOG.fatal("Init value class failed ", e);
            throw new RuntimeException(e);
        }
        if (valueClass == null) {
            throw new RuntimeException("Complex type must set value type class!!");
        }
    }
    for (PartitionMeta partMeta : partMetas.values()) {
        ServerPartition part = ServerPartitionFactory.getPartition(partMeta.getPartitionKey(), partClass, storageClass, matrixMeta.getRowType(), valueClass, matrixMeta.getValidIndexNumInOnePart(), matrixMeta.isHash() ? RouterType.HASH : RouterType.RANGE);
        partitionMaps.put(partMeta.getPartId(), part);
        part.init();
        part.setState(PartitionState.READ_AND_WRITE);
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType) PartitionMeta(com.tencent.angel.ml.matrix.PartitionMeta) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition) IServerPartition(com.tencent.angel.ps.storage.partition.IServerPartition)

Example 7 with RowType

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

the class ServerRowsStorage method update.

@Override
public void update(ByteBuf buf, UpdateOp op) {
    int rowNum = ByteBufSerdeUtils.deserializeInt(buf);
    int rowId;
    RowType rowType;
    for (int i = 0; i < rowNum; i++) {
        // Filter head
        ByteBufSerdeUtils.deserializeBoolean(buf);
        ByteBufSerdeUtils.deserializeInt(buf);
        rowType = RowType.valueOf(ByteBufSerdeUtils.deserializeInt(buf));
        rowId = ByteBufSerdeUtils.deserializeInt(buf);
        ServerRow row = getRow(rowId);
        row.update(rowType, buf, op);
    }
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow)

Example 8 with RowType

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

the class MatrixFormatImpl method initMatrix.

public Matrix initMatrix(MatrixFilesMeta matrixFilesMeta) {
    Map<Integer, MatrixPartitionMeta> partMetas = matrixFilesMeta.getPartMetas();
    Int2LongOpenHashMap rowIdToElemNumMap = new Int2LongOpenHashMap();
    for (MatrixPartitionMeta partMeta : partMetas.values()) {
        Map<Integer, RowPartitionMeta> rowMetas = partMeta.getRowMetas();
        for (Map.Entry<Integer, RowPartitionMeta> rowMetaEntry : rowMetas.entrySet()) {
            rowIdToElemNumMap.addTo(rowMetaEntry.getKey(), rowMetaEntry.getValue().getElementNum());
        }
    }
    RowType rowType = RowType.valueOf(matrixFilesMeta.getRowType());
    RowBasedMatrix matrix = rbMatrix(rowType, matrixFilesMeta.getRow(), matrixFilesMeta.getCol());
    ObjectIterator<Int2LongMap.Entry> iter = rowIdToElemNumMap.int2LongEntrySet().fastIterator();
    Int2LongMap.Entry entry;
    while (iter.hasNext()) {
        entry = iter.next();
        matrix.setRow(entry.getIntKey(), initRow(rowType, matrixFilesMeta.getCol(), entry.getLongValue()));
    }
    return matrix;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) RowBasedMatrix(com.tencent.angel.ml.math2.matrix.RowBasedMatrix) Int2LongOpenHashMap(it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) Map(java.util.Map) Int2LongOpenHashMap(it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap)

Example 9 with RowType

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

the class StreamSerdeUtils method deserializeVector.

public static Vector deserializeVector(DataInputStream in) throws IOException {
    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 10 with RowType

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

the class DotMatrixExecutor method apply.

public static Matrix apply(Matrix mat1, boolean trans1, Matrix mat2, boolean trans2, Boolean parallel) {
    if (mat1 instanceof BlasDoubleMatrix && mat2 instanceof BlasDoubleMatrix) {
        if (parallel) {
            return applyParallel((BlasDoubleMatrix) mat1, trans1, (BlasDoubleMatrix) mat2, trans2);
        } else {
            return apply((BlasDoubleMatrix) mat1, trans1, (BlasDoubleMatrix) mat2, trans2);
        }
    } else if (mat1 instanceof BlasFloatMatrix && mat2 instanceof BlasFloatMatrix) {
        if (parallel) {
            return applyParallel((BlasFloatMatrix) mat1, trans1, (BlasFloatMatrix) mat2, trans2);
        } else {
            return apply((BlasFloatMatrix) mat1, trans1, (BlasFloatMatrix) mat2, trans2);
        }
    } else if (mat1 instanceof BlasDoubleMatrix && mat2 instanceof RBIntDoubleMatrix) {
        return apply((BlasDoubleMatrix) mat1, trans1, (RBIntDoubleMatrix) mat2, trans2);
    } else if (mat1 instanceof BlasDoubleMatrix && mat2 instanceof RBLongDoubleMatrix) {
        return apply((BlasDoubleMatrix) mat1, trans1, (RBLongDoubleMatrix) mat2, trans2);
    } else if (mat1 instanceof BlasFloatMatrix && mat2 instanceof RBIntFloatMatrix) {
        return apply((BlasFloatMatrix) mat1, trans1, (RBIntFloatMatrix) mat2, trans2);
    } else if (mat1 instanceof BlasFloatMatrix && mat2 instanceof RBLongFloatMatrix) {
        return apply((BlasFloatMatrix) mat1, trans1, (RBLongFloatMatrix) mat2, trans2);
    } else if (mat1 instanceof RBIntDoubleMatrix && mat2 instanceof BlasDoubleMatrix) {
        return apply((RBIntDoubleMatrix) mat1, trans1, (BlasDoubleMatrix) mat2, trans2);
    } else if (mat1 instanceof RBIntFloatMatrix && mat2 instanceof BlasFloatMatrix) {
        return apply((RBIntFloatMatrix) mat1, trans1, (BlasFloatMatrix) mat2, trans2);
    } else if (mat1 instanceof RowBasedMatrix && mat2 instanceof RowBasedMatrix) {
        if (!trans1 && trans2) {
            int outputRow = mat1.getNumRows();
            int outputCol = mat2.getNumRows();
            RowType type1 = mat1.getRow(0).getStorage().getType();
            RowType type2 = mat2.getRow(0).getStorage().getType();
            if (type1.isDouble() && type2.isDouble()) {
                BlasDoubleMatrix res = MFactory.denseDoubleMatrix(outputRow, outputCol);
                for (int i = 0; i < outputCol; i++) {
                    Vector row = mat2.getRow(i);
                    Vector col = mat1.dot(row);
                    res.setCol(i, col);
                }
                return res;
            } else if (type1.isFloat() && type2.isFloat()) {
                BlasFloatMatrix res = MFactory.denseFloatMatrix(outputRow, outputCol);
                for (int i = 0; i < outputCol; i++) {
                    Vector row = mat2.getRow(i);
                    Vector col = mat1.dot(row);
                    res.setCol(i, col);
                }
                return res;
            } else {
                throw new AngelException("the operation is not supported!");
            }
        } else {
            throw new AngelException("the operation is not supported!");
        }
    } else {
        throw new AngelException("the operation is not supported!");
    }
}
Also used : RBLongDoubleMatrix(com.tencent.angel.ml.math2.matrix.RBLongDoubleMatrix) AngelException(com.tencent.angel.exception.AngelException) RBLongFloatMatrix(com.tencent.angel.ml.math2.matrix.RBLongFloatMatrix) RBIntFloatMatrix(com.tencent.angel.ml.math2.matrix.RBIntFloatMatrix) RowBasedMatrix(com.tencent.angel.ml.math2.matrix.RowBasedMatrix) RBIntDoubleMatrix(com.tencent.angel.ml.math2.matrix.RBIntDoubleMatrix) RowType(com.tencent.angel.ml.matrix.RowType) BlasDoubleMatrix(com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix) BlasFloatMatrix(com.tencent.angel.ml.math2.matrix.BlasFloatMatrix) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntDummyVector(com.tencent.angel.ml.math2.vector.IntDummyVector)

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