Search in sources :

Example 16 with LongDoubleSparseVectorStorage

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

the class CompLongDoubleRowUpdateSplit method serialize.

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

Example 17 with LongDoubleSparseVectorStorage

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

the class RangeRouterUtils method splitLongDoubleVector.

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

Example 18 with LongDoubleSparseVectorStorage

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

the class HashRouterUtils method splitLongDoubleVector.

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

Example 19 with LongDoubleSparseVectorStorage

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

the class MixedBinaryInAllExecutor method apply.

private static Vector apply(CompLongDoubleVector v1, LongFloatVector v2, Binary op) {
    LongDoubleVector[] 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 LongDoubleSortedVectorStorage) {
                resParts[i] = new LongDoubleSparseVectorStorage(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;
        if (v2.getStorage().hasKey(i)) {
            ((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
        } else {
            ((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
        }
    }
    LongDoubleVector[] res = new LongDoubleVector[parts.length];
    int i = 0;
    for (LongDoubleVector part : parts) {
        res[i] = new LongDoubleVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongDoubleVectorStorage) resParts[i]);
        i++;
    }
    v1.setPartitions(res);
    return v1;
}
Also used : LongDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage) 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) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Example 20 with LongDoubleSparseVectorStorage

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

the class MixedBinaryInAllExecutor method apply.

private static Vector apply(CompLongDoubleVector v1, LongDoubleVector v2, Binary op) {
    LongDoubleVector[] 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 LongDoubleSortedVectorStorage) {
                resParts[i] = new LongDoubleSparseVectorStorage(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;
        if (v2.getStorage().hasKey(i)) {
            ((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
        } else {
            ((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
        }
    }
    LongDoubleVector[] res = new LongDoubleVector[parts.length];
    int i = 0;
    for (LongDoubleVector part : parts) {
        res[i] = new LongDoubleVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongDoubleVectorStorage) resParts[i]);
        i++;
    }
    v1.setPartitions(res);
    return v1;
}
Also used : LongDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage) 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) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Aggregations

LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)38 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)33 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)30 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)23 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)22 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)22 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)22 CompLongDoubleVector (com.tencent.angel.ml.math2.vector.CompLongDoubleVector)21 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)20 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)20 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)20 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)20 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)20 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)20