Search in sources :

Example 6 with LongIntSparseVectorStorage

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

the class MixedBinaryOutAllExecutor method apply.

private static Vector apply(CompLongIntVector v1, LongDummyVector v2, Binary op) {
    LongIntVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (!op.isKeepStorage()) {
        for (int i = 0; i < parts.length; i++) {
            if (parts[i].getStorage() instanceof LongIntSortedVectorStorage) {
                resParts[i] = new LongIntSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
            }
        }
    }
    long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
    for (int i = 0; i < v1.getDim(); i++) {
        int pidx = (int) (i / subDim);
        long subidx = i % subDim;
        ((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
    }
    LongIntVector[] res = new LongIntVector[parts.length];
    int i = 0;
    for (LongIntVector part : parts) {
        res[i] = new LongIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongIntVectorStorage) resParts[i]);
        i++;
    }
    return new CompLongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Also used : CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) LongLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage) IntDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) LongDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) IntIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) IntLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage) IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) LongLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSortedVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) IntIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)

Example 7 with LongIntSparseVectorStorage

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

the class ByteBufSerdeUtils method deserializeLongIntVector.

private static LongIntVector deserializeLongIntVector(ByteBuf in, long dim) {
    int storageType = deserializeInt(in);
    switch(storageType) {
        case SPARSE_STORAGE_TYPE:
            int len = deserializeInt(in);
            Long2IntOpenHashMap idToValueMap = new Long2IntOpenHashMap(len);
            for (int i = 0; i < len; i++) {
                idToValueMap.put(deserializeInt(in), deserializeInt(in));
            }
            return new LongIntVector((int) dim, new LongIntSparseVectorStorage((int) dim, idToValueMap));
        case SORTED_STORAGE_TYPE:
            return VFactory.sortedLongKeyIntVector((int) dim, deserializeLongs(in), deserializeInts(in));
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageType);
    }
}
Also used : Long2IntOpenHashMap(it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)

Example 8 with LongIntSparseVectorStorage

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

the class CompLongIntRowUpdateSplit method serialize.

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

Example 9 with LongIntSparseVectorStorage

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

the class RangeRouterUtils method splitLongIntVector.

public static KeyValuePart[] splitLongIntVector(MatrixMeta matrixMeta, LongIntVector vector) {
    LongIntVectorStorage storage = vector.getStorage();
    if (storage.isSparse()) {
        // Get keys and values
        LongIntSparseVectorStorage sparseStorage = (LongIntSparseVectorStorage) storage;
        long[] keys = sparseStorage.getIndices();
        int[] values = sparseStorage.getValues();
        return split(matrixMeta, vector.getRowId(), keys, values, false);
    } else {
        // Key and value array pair
        LongIntSortedVectorStorage sortStorage = (LongIntSortedVectorStorage) storage;
        long[] keys = sortStorage.getIndices();
        int[] values = sortStorage.getValues();
        return split(matrixMeta, vector.getRowId(), keys, values, true);
    }
}
Also used : LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)

Example 10 with LongIntSparseVectorStorage

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

the class HashRouterUtils method splitLongIntVector.

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

Aggregations

LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)20 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)15 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)15 LongIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage)11 CompLongIntVector (com.tencent.angel.ml.math2.vector.CompLongIntVector)9 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)8 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)8 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)8 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)8 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)8 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)8 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)8 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)8 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)8 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)8 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)8 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)8 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)8 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)8 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)8