Search in sources :

Example 21 with LongFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.

the class CompLongFloatRowUpdateSplit method serialize.

@Override
public void serialize(ByteBuf buf) {
    // TODO:
    super.serialize(buf);
    LongFloatVectorStorage storage = split.getStorage();
    buf.writeInt(storage.size());
    if (storage instanceof LongFloatSparseVectorStorage) {
        ObjectIterator<Long2FloatMap.Entry> iter = storage.entryIterator();
        Long2FloatMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            buf.writeLong(entry.getLongKey());
            buf.writeFloat(entry.getFloatValue());
        }
    } else if (storage instanceof LongFloatSortedVectorStorage) {
        long[] indices = storage.getIndices();
        float[] values = storage.getValues();
        for (int i = 0; i < indices.length; i++) {
            buf.writeLong(indices[i]);
            buf.writeFloat(values[i]);
        }
    } else {
        throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
    }
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)

Example 22 with LongFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.

the class ByteBufSerdeUtils method serializeLongFloatVector.

// LongFloatVector
private static void serializeLongFloatVector(ByteBuf out, LongFloatVector vector) {
    LongFloatVectorStorage storage = vector.getStorage();
    if (storage.isSparse()) {
        serializeInt(out, SPARSE_STORAGE_TYPE);
        serializeInt(out, storage.size());
        ObjectIterator<Long2FloatMap.Entry> iter = storage.entryIterator();
        while (iter.hasNext()) {
            Long2FloatMap.Entry e = iter.next();
            serializeLong(out, e.getLongKey());
            serializeFloat(out, e.getFloatValue());
        }
    } else if (storage.isSorted()) {
        serializeInt(out, SORTED_STORAGE_TYPE);
        long[] indices = vector.getStorage().getIndices();
        float[] values = vector.getStorage().getValues();
        serializeLongs(out, indices);
        serializeFloats(out, values);
    } else {
        throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
    }
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap)

Example 23 with LongFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.

the class ByteBufSerdeUtils method serializedLongFloatVectorLen.

public static int serializedLongFloatVectorLen(LongFloatVector vector) {
    int len = 0;
    LongFloatVectorStorage storage = vector.getStorage();
    if (storage.isSparse()) {
        len += serializedIntLen(SPARSE_STORAGE_TYPE);
        len += serializedIntLen(storage.size());
        len += storage.size() * (INT_LENGTH + FLOAT_LENGTH);
    } else if (storage.isSorted()) {
        len += serializedIntLen(SORTED_STORAGE_TYPE);
        len += serializedLongsLen(vector.getStorage().getIndices());
        len += serializedFloatsLen(vector.getStorage().getValues());
    } else {
        throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
    }
    return len;
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)

Example 24 with LongFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.

the class StreamSerdeUtils method serializeLongFloatVector.

// LongFloatVector
private static void serializeLongFloatVector(DataOutputStream out, LongFloatVector vector) throws IOException {
    LongFloatVectorStorage storage = vector.getStorage();
    if (storage.isSparse()) {
        serializeInt(out, SPARSE_STORAGE_TYPE);
        serializeInt(out, storage.size());
        ObjectIterator<Long2FloatMap.Entry> iter = storage.entryIterator();
        while (iter.hasNext()) {
            Long2FloatMap.Entry e = iter.next();
            serializeLong(out, e.getLongKey());
            serializeFloat(out, e.getFloatValue());
        }
    } else if (storage.isSorted()) {
        serializeInt(out, SORTED_STORAGE_TYPE);
        long[] indices = vector.getStorage().getIndices();
        float[] values = vector.getStorage().getValues();
        serializeLongs(out, indices);
        serializeFloats(out, values);
    } else {
        throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
    }
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Entry(it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap)

Example 25 with LongFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.

the class HashRouterUtils method splitLongFloatVector.

public static void splitLongFloatVector(KeyHash hasher, MatrixMeta matrixMeta, LongFloatVector vector, KeyValuePart[] dataParts) {
    int dataPartNum = dataParts.length;
    int dataPartNumMinus1 = dataPartNum - 1;
    if (isPow2(dataPartNum)) {
        LongFloatVectorStorage storage = vector.getStorage();
        if (storage.isSparse()) {
            // Use iterator
            LongFloatSparseVectorStorage sparseStorage = (LongFloatSparseVectorStorage) storage;
            ObjectIterator<Long2FloatMap.Entry> iter = sparseStorage.entryIterator();
            while (iter.hasNext()) {
                Long2FloatMap.Entry keyValue = iter.next();
                int partId = computeHashCode(hasher, keyValue.getLongKey()) & dataPartNumMinus1;
                ((HashLongKeysFloatValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getFloatValue());
            }
        } else {
            // Key and value array pair
            LongFloatSortedVectorStorage sortStorage = (LongFloatSortedVectorStorage) storage;
            long[] keys = sortStorage.getIndices();
            float[] values = sortStorage.getValues();
            for (int i = 0; i < keys.length; i++) {
                int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
                ((HashLongKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
            }
        }
    } else {
        LongFloatVectorStorage storage = vector.getStorage();
        if (storage.isSparse()) {
            // Use iterator
            LongFloatSparseVectorStorage sparseStorage = (LongFloatSparseVectorStorage) storage;
            ObjectIterator<Long2FloatMap.Entry> iter = sparseStorage.entryIterator();
            while (iter.hasNext()) {
                Long2FloatMap.Entry keyValue = iter.next();
                int partId = computeHashCode(hasher, keyValue.getLongKey()) % dataPartNum;
                ((HashLongKeysFloatValuesPart) dataParts[partId]).add(keyValue.getLongKey(), keyValue.getFloatValue());
            }
        } else {
            // Key and value array pair
            LongFloatSortedVectorStorage sortStorage = (LongFloatSortedVectorStorage) storage;
            long[] keys = sortStorage.getIndices();
            float[] values = sortStorage.getValues();
            for (int i = 0; i < keys.length; i++) {
                int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
                ((HashLongKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
            }
        }
    }
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)

Aggregations

LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)52 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)32 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)27 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)26 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)26 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)26 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)24 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)24 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)24 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)24 Storage (com.tencent.angel.ml.math2.storage.Storage)24 CompLongFloatVector (com.tencent.angel.ml.math2.vector.CompLongFloatVector)24 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)22 Long2FloatMap (it.unimi.dsi.fastutil.longs.Long2FloatMap)20 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)18 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)16 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)16 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)16 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)16 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)16