Search in sources :

Example 16 with RowType

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

the class ModelLoader method loadToDoubleLongKeyMaps.

/**
 * Load dense double model to long->double maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Long2DoubleOpenHashMap[] loadToDoubleLongKeyMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_SPARSE_LONGKEY && rowType != RowType.T_DOUBLE_SPARSE_LONGKEY_COMPONENT) {
        throw new IOException("model row type is not sparse long double, you should check it");
    }
    // Load model
    SparseDoubleLongKeyModel model = new SparseDoubleLongKeyModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 17 with RowType

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

the class ModelLoader method loadToFloatMaps.

/**
 * Load dense double model to int->float maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Int2FloatOpenHashMap[] loadToFloatMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_FLOAT_SPARSE && rowType != rowType.T_FLOAT_SPARSE_COMPONENT) {
        throw new IOException("model row type is not sparse float, you should check it");
    }
    // Load model
    SparseFloatModel model = new SparseFloatModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 18 with RowType

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

the class RowSplitCombineUtils method combineServerRowSplits.

/**
 * Combine row splits of a single matrix row.
 *
 * @param rowSplits row splits
 * @param matrixId matrix id
 * @param rowIndex row index
 * @return TVector merged row
 */
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_SPARSE_LONGKEY:
            return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_SPARSE_LONGKEY:
            return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
        default:
            throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Example 19 with RowType

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

the class MergeUtils method combineServerRowSplits.

/**
 * Combine row splits of a single matrix row.
 *
 * @param rowSplits row splits
 * @param matrixId matrix id
 * @param rowIndex row index
 * @return TVector merged row
 */
public static Vector combineServerRowSplits(List<ServerRow> rowSplits, int matrixId, int rowIndex) {
    MatrixMeta matrixMeta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    RowType rowType = matrixMeta.getRowType();
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_SPARSE:
            return combineServerIntDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_DENSE:
        case T_FLOAT_SPARSE:
            return combineServerIntFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_DENSE:
        case T_INT_SPARSE:
            return combineServerIntIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_DENSE:
        case T_LONG_SPARSE:
            return combineServerIntLongRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_DOUBLE_SPARSE_LONGKEY:
            return combineServerLongDoubleRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_FLOAT_SPARSE_LONGKEY:
            return combineServerLongFloatRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_INT_SPARSE_LONGKEY:
            return combineServerLongIntRowSplits(rowSplits, matrixMeta, rowIndex);
        case T_LONG_SPARSE_LONGKEY:
            return combineServerLongLongRowSplits(rowSplits, matrixMeta, rowIndex);
        default:
            throw new UnsupportedOperationException("Unsupport operation: merge " + rowType + " vector splits");
    }
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) RowType(com.tencent.angel.ml.matrix.RowType)

Example 20 with RowType

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

the class MatrixOpLog method createMatrix.

private Matrix createMatrix(MatrixMeta meta) {
    RowType rowType = meta.getRowType();
    String opLogTypeStr = meta.getAttribute(MatrixConf.MATRIX_OPLOG_TYPE);
    RowType opLogType;
    if (opLogTypeStr == null) {
        opLogType = rowType;
    } else {
        opLogType = RowType.valueOf(opLogTypeStr);
    }
    return MatrixFactory.createRBMatrix(opLogType, meta.getRowNum(), meta.getColNum(), meta.getBlockColNum());
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType)

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