Search in sources :

Example 26 with LongIntVectorStorage

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

the class LongIntVector method max.

public int max() {
    LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    int maxval = Integer.MIN_VALUE;
    if (idstorage.isSparse()) {
        IntIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            int val = iter.nextInt();
            if (val > maxval) {
                maxval = val;
            }
        }
    } else {
        for (int val : idstorage.getValues()) {
            if (val > maxval) {
                maxval = val;
            }
        }
    }
    return maxval;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage)

Example 27 with LongIntVectorStorage

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

the class LongIntVector method argmin.

public long argmin() {
    LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    int minval = Integer.MAX_VALUE;
    long minidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2IntMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2IntMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            int val = entry.getIntValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        int[] val = idstorage.getValues();
        long size = idstorage.size();
        for (int i = 0; i < size; i++) {
            long idx = indices[i];
            if (val[i] < minval) {
                minval = val[i];
                minidx = idx;
            }
        }
    }
    return minidx;
}
Also used : LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap)

Example 28 with LongIntVectorStorage

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

the class LongIntVector method argmax.

public long argmax() {
    LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    int maxval = Integer.MIN_VALUE;
    long maxidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2IntMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2IntMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            int val = entry.getIntValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        int[] val = idstorage.getValues();
        long size = idstorage.size();
        for (int i = 0; i < size; i++) {
            long idx = indices[i];
            if (val[i] > maxval) {
                maxval = val[i];
                maxidx = idx;
            }
        }
    }
    return maxidx;
}
Also used : LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap)

Example 29 with LongIntVectorStorage

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

the class MixedBinaryOutZAExecutor method apply.

private static Vector apply(CompLongIntVector v1, LongDummyVector v2, Binary op) {
    LongIntVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v1.size() > v2.size()) {
        long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
        long[] v2Indices = v2.getIndices();
        for (int i = 0; i < v2Indices.length; i++) {
            long idx = v2Indices[i];
            int pidx = (int) (idx / subDim);
            long subidx = idx % subDim;
            if (parts[pidx].hasKey(subidx)) {
                ((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
            }
        }
    } else {
        long base = 0;
        for (int i = 0; i < parts.length; i++) {
            LongIntVector part = parts[i];
            LongIntVectorStorage resPart = (LongIntVectorStorage) resParts[i];
            if (part.isDense()) {
                int[] partValues = part.getStorage().getValues();
                int[] resPartValues = resPart.getValues();
                for (int j = 0; j < partValues.length; j++) {
                    if (v2.hasKey(j + base)) {
                        resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
                    }
                }
            } else if (part.isSparse()) {
                ObjectIterator<Long2IntMap.Entry> piter = part.getStorage().entryIterator();
                while (piter.hasNext()) {
                    Long2IntMap.Entry entry = piter.next();
                    long idx = entry.getLongKey();
                    if (v2.hasKey(idx + base)) {
                        resPart.set(idx, op.apply(entry.getIntValue(), v2.get(idx + base)));
                    }
                }
            } else {
                // sorted
                if (op.isKeepStorage()) {
                    long[] partIndices = part.getStorage().getIndices();
                    int[] partValues = part.getStorage().getValues();
                    long[] resPartIndices = resPart.getIndices();
                    int[] resPartValues = resPart.getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        long idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPartIndices[j] = idx;
                            resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
                        }
                    }
                } else {
                    long[] partIndices = part.getStorage().getIndices();
                    int[] partValues = part.getStorage().getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        long idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
                        }
                    }
                }
            }
            base += part.getDim();
        }
    }
    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) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector)

Example 30 with LongIntVectorStorage

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

the class SimpleBinaryOutAllExecutor method apply.

public static Vector apply(LongIntVector v1, LongDummyVector v2, Binary op) {
    LongIntVector res;
    if (v1.isSparse()) {
        if (op.isKeepStorage()) {
            throw new AngelException("operation is not support!");
        } else {
            // multi-rehash
            LongIntVectorStorage newStorage = v1.getStorage().emptySparse((int) (v1.getDim()));
            LongIntVectorStorage v1Storage = v1.getStorage();
            for (int i = 0; i < v1.getDim(); i++) {
                if (v1Storage.hasKey(i)) {
                    newStorage.set(i, op.apply(v1.get(i), v2.get(i)));
                } else {
                    newStorage.set(i, op.apply(0, v2.get(i)));
                }
            }
            res = new LongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
        }
    } else {
        // sorted
        if (op.isKeepStorage()) {
            throw new AngelException("operation is not support!");
        } else {
            LongIntVectorStorage newStorage = new LongIntSparseVectorStorage(v1.getDim());
            LongIntVectorStorage v1Storage = v1.getStorage();
            for (int i = 0; i < v1.getDim(); i++) {
                if (v1Storage.hasKey(i)) {
                    newStorage.set(i, op.apply(v1.get(i), v2.get(i)));
                } else {
                    newStorage.set(i, op.apply(0, v2.get(i)));
                }
            }
            res = new LongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
        }
    }
    return res;
}
Also used : AngelException(com.tencent.angel.exception.AngelException) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)

Aggregations

LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)38 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)16 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)15 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)14 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)14 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)14 Long2IntMap (it.unimi.dsi.fastutil.longs.Long2IntMap)14 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)12 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)12 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)12 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)12 LongIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage)12 Storage (com.tencent.angel.ml.math2.storage.Storage)12 CompLongIntVector (com.tencent.angel.ml.math2.vector.CompLongIntVector)12 AngelException (com.tencent.angel.exception.AngelException)11 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)10 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)10 LongLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage)10 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)8 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)8