use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.
the class ModelLoader method loadSparseDoubleLongKeyPartition.
private static void loadSparseDoubleLongKeyPartition(SparseDoubleLongKeyModel model, FSDataInputStream input, ModelPartitionMeta partMeta) throws IOException {
int rowNum = input.readInt();
int rowId = 0;
int nnz = 0;
int totalNNZ = 0;
Long2DoubleOpenHashMap 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.readLong(), input.readDouble());
}
}
}
use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.
the class ModelLoader method loadSparseDoubleLongKeyRowFromPartition.
public static Long2DoubleOpenHashMap loadSparseDoubleLongKeyRowFromPartition(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();
Long2DoubleOpenHashMap row = new Long2DoubleOpenHashMap();
for (int j = 0; j < num; j++) {
row.put(input.readLong(), input.readDouble());
}
return row;
}
use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.
the class SparseLongKeyDoubleVector method deserialize.
@Override
public void deserialize(ByteBuf buf) {
int dim = buf.readInt();
int length = buf.readInt();
Long2DoubleOpenHashMap data = new Long2DoubleOpenHashMap(dim);
IntStream.range(0, length).forEach(i -> data.put(buf.readLong(), buf.readDouble()));
this.dim = dim;
this.indexToValueMap = data;
}
use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project elki by elki-project.
the class FileBasedSparseDoubleDistanceFunction method loadCache.
/**
* Fill cache from an input stream.
*
* @param size Expected size
* @param in Input stream
* @throws IOException
*/
protected void loadCache(int size, InputStream in) throws IOException {
// Expect a sparse matrix here.
cache = new Long2DoubleOpenHashMap(size * 20);
cache.defaultReturnValue(Double.POSITIVE_INFINITY);
min = Integer.MAX_VALUE;
max = Integer.MIN_VALUE;
parser.parse(in, new DistanceCacheWriter() {
@Override
public void put(int id1, int id2, double distance) {
if (id1 < id2) {
min = id1 < min ? id1 : min;
max = id2 > max ? id2 : max;
} else {
min = id2 < min ? id2 : min;
max = id1 > max ? id1 : max;
}
cache.put(makeKey(id1, id2), distance);
}
});
if (min != 0 && LOG.isVerbose()) {
LOG.verbose("Distance matrix is supposed to be 0-indexed. Choosing offset " + min + " to compensate.");
}
if (max + 1 - min != size) {
LOG.warning("ID range is not consistent with relation size.");
}
}
use of it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap in project angel by Tencent.
the class ModelMergeAndConvert method convertSparseDoubleLongKeyModel.
private static void convertSparseDoubleLongKeyModel(Configuration conf, FSDataOutputStream output, String modelInputDir, ModelLineConvert lineConvert) throws IOException {
Long2DoubleOpenHashMap[] data = ModelLoader.loadToDoubleLongKeyMaps(modelInputDir, conf);
for (int i = 0; i < data.length; i++) {
Long2DoubleOpenHashMap row = data[i];
data[i] = null;
if (row == null) {
continue;
}
lineConvert.convertRowIndex(output, i);
long[] indexes = row.keySet().toLongArray();
double[] values = row.values().toDoubleArray();
row = null;
Sort.quickSort(indexes, values, 0, indexes.length - 1);
for (int j = 0; j < indexes.length; j++) {
lineConvert.convertDoubleLongKey(output, indexes[j], values[j]);
}
}
}
Aggregations