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);
}
}
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());
}
}
}
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;
}
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]);
}
}
}
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);
}
}
Aggregations