Search in sources :

Example 1 with Int2FloatOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.

the class ServerSparseFloatRow method resizeHashMap.

private void resizeHashMap(int size) {
    if (data.size() < size) {
        Int2FloatOpenHashMap oldMap = data;
        data = new Int2FloatOpenHashMap(size);
        data.putAll(oldMap);
    }
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 2 with Int2FloatOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.

the class ModelLoader method loadSparseFloatPartition.

private static void loadSparseFloatPartition(SparseFloatModel model, FSDataInputStream input, ModelPartitionMeta partMeta) throws IOException {
    int rowNum = input.readInt();
    int rowId = 0;
    int nnz = 0;
    int totalNNZ = 0;
    Int2FloatOpenHashMap row = null;
    for (int i = 0; i < rowNum; i++) {
        rowId = input.readInt();
        nnz = input.readInt();
        totalNNZ = (int) (nnz * (model.col) / (partMeta.getEndCol() - partMeta.getStartCol()));
        row = model.getRow(rowId, partMeta.getPartId(), totalNNZ);
        for (int j = 0; j < nnz; j++) {
            row.put(input.readInt(), input.readFloat());
        }
    }
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 3 with Int2FloatOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.

the class ModelLoader method loadSparseFloatRowFromPartition.

public static Int2FloatOpenHashMap loadSparseFloatRowFromPartition(FSDataInputStream input, ModelPartitionMeta partMeta, int rowId) throws IOException {
    RowOffset rowOffset = partMeta.getRowMetas().get(rowId);
    input.seek(rowOffset.getOffset());
    Preconditions.checkState(input.readInt() == rowId);
    int num = input.readInt();
    Int2FloatOpenHashMap row = new Int2FloatOpenHashMap();
    for (int i = 0; i < num; i++) {
        row.put(input.readInt(), input.readFloat());
    }
    return row;
}
Also used : RowOffset(com.tencent.angel.model.output.format.ModelPartitionMeta.RowOffset) Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 4 with Int2FloatOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.

the class ModelMergeAndConvert method convertSparseFloatModel.

private static void convertSparseFloatModel(Configuration conf, FSDataOutputStream output, String modelInputDir, ModelLineConvert lineConvert) throws IOException {
    Int2FloatOpenHashMap[] data = ModelLoader.loadToFloatMaps(modelInputDir, conf);
    for (int i = 0; i < data.length; i++) {
        Int2FloatOpenHashMap row = data[i];
        data[i] = null;
        if (row == null) {
            continue;
        }
        lineConvert.convertRowIndex(output, i);
        int[] indexes = row.keySet().toIntArray();
        float[] values = row.values().toFloatArray();
        row = null;
        Sort.quickSort(indexes, values, 0, indexes.length - 1);
        for (int j = 0; j < indexes.length; j++) {
            lineConvert.convertFloat(output, indexes[j], values[j]);
        }
    }
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 5 with Int2FloatOpenHashMap

use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.

the class ByteBufSerdeUtils method deserializeIntFloatVector.

private static IntFloatVector deserializeIntFloatVector(ByteBuf in, long dim) {
    int storageType = deserializeInt(in);
    switch(storageType) {
        case DENSE_STORAGE_TYPE:
            return VFactory.denseFloatVector(deserializeFloats(in));
        case SPARSE_STORAGE_TYPE:
            int len = deserializeInt(in);
            Int2FloatOpenHashMap idToValueMap = new Int2FloatOpenHashMap(len);
            for (int i = 0; i < len; i++) {
                idToValueMap.put(deserializeInt(in), deserializeFloat(in));
            }
            return new IntFloatVector((int) dim, new IntFloatSparseVectorStorage((int) dim, idToValueMap));
        case SORTED_STORAGE_TYPE:
            return VFactory.sortedFloatVector((int) dim, deserializeInts(in), deserializeFloats(in));
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageType);
    }
}
Also used : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

Int2FloatOpenHashMap (it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)12 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)2 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 RowOffset (com.tencent.angel.model.output.format.ModelPartitionMeta.RowOffset)1 Int2DoubleOpenHashMap (it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap)1 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Long2DoubleOpenHashMap (it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1