Search in sources :

Example 6 with Int2FloatOpenHashMap

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);
    }
}
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)

Example 7 with Int2FloatOpenHashMap

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;
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 8 with Int2FloatOpenHashMap

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;
}
Also used : Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 9 with Int2FloatOpenHashMap

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();
    }
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

Example 10 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, 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;
}
Also used : Int2FloatOpenHashMap(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap)

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