Search in sources :

Example 36 with LongFloatVectorStorage

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

the class MixedBinaryOutNonZAExecutor method apply.

private static Vector apply(CompLongFloatVector v1, LongIntVector v2, Binary op) {
    LongFloatVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v2.isSparse()) {
        if (!op.isKeepStorage()) {
            for (int i = 0; i < parts.length; i++) {
                if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
                    resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
                }
            }
        }
        long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
        ObjectIterator<Long2IntMap.Entry> iter = v2.getStorage().entryIterator();
        while (iter.hasNext()) {
            Long2IntMap.Entry entry = iter.next();
            long gidx = entry.getLongKey();
            int pidx = (int) (gidx / subDim);
            long subidx = gidx % subDim;
            ((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), entry.getIntValue()));
        }
    } else {
        // sorted
        if (!op.isKeepStorage()) {
            for (int i = 0; i < parts.length; i++) {
                if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
                    resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
                }
            }
        }
        long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
        long[] v2Indices = v2.getStorage().getIndices();
        int[] v2Values = v2.getStorage().getValues();
        for (int i = 0; i < v2Indices.length; i++) {
            long gidx = v2Indices[i];
            int pidx = (int) (gidx / subDim);
            long subidx = gidx % subDim;
            ((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2Values[i]));
        }
    }
    LongFloatVector[] res = new LongFloatVector[parts.length];
    int i = 0;
    for (LongFloatVector part : parts) {
        res[i] = new LongFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongFloatVectorStorage) resParts[i]);
        i++;
    }
    return new CompLongFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Also used : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) CompLongFloatVector(com.tencent.angel.ml.math2.vector.CompLongFloatVector) CompLongFloatVector(com.tencent.angel.ml.math2.vector.CompLongFloatVector) 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) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)

Example 37 with LongFloatVectorStorage

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

the class LongFloatVector method argmin.

public long argmin() {
    LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    float minval = Float.MAX_VALUE;
    long minidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2FloatMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2FloatMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            float val = entry.getFloatValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        float[] 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 : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap)

Example 38 with LongFloatVectorStorage

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

the class LongFloatVector method numZeros.

public long numZeros() {
    LongFloatVectorStorage dstorage = (LongFloatVectorStorage) storage;
    if (dstorage.size() == 0)
        return (long) dim;
    long numZero = 0;
    if (dstorage.isSparse()) {
        FloatIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            if (iter.nextFloat() != 0) {
                numZero += 1;
            }
        }
    } else {
        for (float val : dstorage.getValues()) {
            if (val != 0) {
                numZero += 1;
            }
        }
    }
    return (long) getDim() - numZero;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)

Example 39 with LongFloatVectorStorage

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

the class LongFloatVector method min.

public float min() {
    LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    float minval = Float.MAX_VALUE;
    if (idstorage.isSparse()) {
        FloatIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            float val = iter.nextFloat();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (float val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)

Example 40 with LongFloatVectorStorage

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

the class LongFloatVector method argmax.

public long argmax() {
    LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    float maxval = Float.MIN_VALUE;
    long maxidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2FloatMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2FloatMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            float val = entry.getFloatValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        float[] 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 : LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) Long2FloatMap(it.unimi.dsi.fastutil.longs.Long2FloatMap)

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