Search in sources :

Example 11 with CompLongIntVector

use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.

the class CompLongIntVectorSplitter method split.

@Override
public Map<PartitionKey, RowUpdateSplit> split(Vector vector, List<PartitionKey> parts) {
    LongIntVector[] vecParts = ((CompLongIntVector) vector).getPartitions();
    assert vecParts.length == parts.size();
    Map<PartitionKey, RowUpdateSplit> updateSplitMap = new HashMap<>(parts.size());
    for (int i = 0; i < vecParts.length; i++) {
        updateSplitMap.put(parts.get(i), new CompLongIntRowUpdateSplit(vector.getRowId(), vecParts[i]));
    }
    return updateSplitMap;
}
Also used : LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) CompLongIntRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompLongIntRowUpdateSplit) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) CompLongIntRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompLongIntRowUpdateSplit)

Example 12 with CompLongIntVector

use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.

the class MixedBinaryOutNonZAExecutor 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();
    long[] v2Indices = v2.getIndices();
    for (int i = 0; i < v2Indices.length; i++) {
        long gidx = v2Indices[i];
        int pidx = (int) (gidx / subDim);
        long subidx = gidx % subDim;
        ((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
    }
    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 13 with CompLongIntVector

use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.

the class MixedBinaryInZAExecutor method apply.

private static Vector apply(CompLongIntVector v1, LongIntVector v2, Binary op) {
    LongIntVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v2.isSparse()) {
        ObjectIterator<Long2IntMap.Entry> iter = v2.getStorage().entryIterator();
        if (v1.size() > v2.size()) {
            long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
            while (iter.hasNext()) {
                Long2IntMap.Entry entry = iter.next();
                long idx = entry.getLongKey();
                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), entry.getIntValue()));
                }
            }
        } 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();
            }
        }
    } else {
        // sorted
        if (v1.size() > v2.size()) {
            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 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), v2Values[i]));
                }
            }
        } 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++;
    }
    v1.setPartitions(res);
    return v1;
}
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)

Example 14 with CompLongIntVector

use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.

the class MixedBinaryInNonZAExecutor method apply.

private static Vector apply(CompLongIntVector v1, LongIntVector v2, Binary op) {
    LongIntVector[] 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 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();
        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;
            ((LongIntVectorStorage) 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 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();
        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;
            ((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2Values[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++;
    }
    v1.setPartitions(res);
    return v1;
}
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) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage) 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)

Example 15 with CompLongIntVector

use of com.tencent.angel.ml.math2.vector.CompLongIntVector in project angel by Tencent.

the class CompReduceExecutor method apply.

private static UnionEle apply(CompLongIntVector v, ReduceOP op, int start, int end) {
    UnionEle res = new UnionEle();
    LongIntVector[] parts = v.getPartitions();
    switch(op) {
        case Sum:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
            }
            break;
        case Avg:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Std:
            for (int i = start; i <= end; i++) {
                res.setDouble1(res.getDouble1() + parts[i].sum());
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
                res.setLong1(res.getLong1() + parts[i].getDim());
            }
            break;
        case Norm:
            for (int i = start; i <= end; i++) {
                double norm = parts[i].norm();
                res.setDouble2(res.getDouble2() + norm * norm);
            }
            break;
        case Min:
            res.setDouble1(Double.MAX_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.min(res.getDouble1(), parts[i].min()));
            }
            break;
        case Max:
            res.setDouble1(Double.MIN_VALUE);
            for (int i = start; i <= end; i++) {
                res.setDouble1(Math.max(res.getDouble1(), parts[i].max()));
            }
            break;
        case Size:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].size());
            }
            break;
        case Numzeros:
            for (int i = start; i <= end; i++) {
                res.setLong1(res.getLong1() + parts[i].numZeros());
            }
            break;
    }
    return res;
}
Also used : UnionEle(com.tencent.angel.ml.math2.utils.UnionEle) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector)

Aggregations

CompLongIntVector (com.tencent.angel.ml.math2.vector.CompLongIntVector)16 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)16 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 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)12 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)12 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)12 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)12 Storage (com.tencent.angel.ml.math2.storage.Storage)12 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)9 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)8 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)8 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)8 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)8 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)8 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)8 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)8 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)8