use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.
the class StreamSerdeUtils method deserializeIntFloatVector.
private static IntFloatVector deserializeIntFloatVector(DataInputStream in, long dim) throws IOException {
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);
}
}
use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.
the class SparseFloatVector method deserialize.
@Override
public void deserialize(ByteBuf buf) {
int dim = buf.readInt();
int length = buf.readInt();
Int2FloatOpenHashMap data = new Int2FloatOpenHashMap(length);
IntStream.range(0, length).forEach(i -> data.put(buf.readInt(), buf.readFloat()));
this.dim = dim;
this.hashMap = data;
}
use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.
the class SparseFloatVector method dot.
private double dot(SparseFloatVector other) {
double dot = 0.0;
Int2FloatOpenHashMap smallMap = this.hashMap;
Int2FloatOpenHashMap largeMap = other.hashMap;
if (smallMap.size() > largeMap.size()) {
smallMap = other.hashMap;
largeMap = this.hashMap;
}
ObjectIterator<Int2FloatMap.Entry> iter = smallMap.int2FloatEntrySet().fastIterator();
Int2FloatMap.Entry entry = null;
while (iter.hasNext()) {
entry = iter.next();
if (largeMap.containsKey(entry.getIntKey())) {
dot += entry.getFloatValue() * largeMap.get(entry.getIntKey());
}
}
return dot;
}
use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.
the class ServerSparseFloatRow method deserialize.
@Override
public void deserialize(ByteBuf buf) {
try {
lock.writeLock().lock();
super.deserialize(buf);
int elemNum = buf.readInt();
if (data == null) {
data = new Int2FloatOpenHashMap(elemNum);
}
for (int i = 0; i < elemNum; i++) {
data.put(buf.readInt(), buf.readFloat());
}
} finally {
lock.writeLock().unlock();
}
}
use of it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap in project angel by Tencent.
the class ModelLoader method loadSparseFloatRowFromPartition.
public static Int2FloatOpenHashMap loadSparseFloatRowFromPartition(FSDataInputStream input, MatrixPartitionMeta 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;
}
Aggregations