Search in sources :

Example 51 with Storage

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

the class MixedBinaryInAllExecutor method apply.

private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
    IntFloatVector[] 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 IntFloatSortedVectorStorage) {
                resParts[i] = new IntFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
            }
        }
    }
    int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
    for (int i = 0; i < v1.getDim(); i++) {
        int pidx = (int) (i / subDim);
        int subidx = i % subDim;
        ((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
    }
    IntFloatVector[] res = new IntFloatVector[parts.length];
    int i = 0;
    for (IntFloatVector part : parts) {
        res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
        i++;
    }
    v1.setPartitions(res);
    return v1;
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) 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) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 52 with Storage

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

the class StorageSwitch method applyComp.

public static Storage[] applyComp(ComponentVector v1, Vector v2, Binary op) {
    Vector[] parts = v1.getPartitions();
    Storage[] resParts = new Storage[parts.length];
    int k = 0;
    if (op.getOpType() == OpType.UNION) {
        if (v2.isDense()) {
            for (Vector part : parts) {
                if (part.isDense()) {
                    if (op.isInplace()) {
                        resParts[k] = part.getStorage();
                    } else {
                        resParts[k] = part.copy().getStorage();
                    }
                } else if (part.isSparse()) {
                    if (op.isKeepStorage()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
                    } else {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                    }
                } else {
                    if (op.isKeepStorage()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted, part.dim());
                    } else {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                    }
                }
                k++;
            }
        } else {
            for (Vector part : parts) {
                if (op.isInplace()) {
                    resParts[k] = part.getStorage();
                } else {
                    resParts[k] = part.copy().getStorage();
                }
                k++;
            }
        }
    } else if (op.getOpType() == OpType.INTERSECTION) {
        if (v2.isDense()) {
            for (Vector part : parts) {
                if (part.isDense()) {
                    resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                } else if (part.isSparse()) {
                    resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                } else {
                    if (op.isKeepStorage()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
                    } else {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                    }
                }
                k++;
            }
        } else {
            if (((Vector) v1).getSize() > v2.getSize()) {
                for (Vector part : parts) {
                    if (op.isKeepStorage()) {
                        if (part.isDense()) {
                            resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                        } else if (part.isSparse()) {
                            resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                        } else {
                            resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
                        }
                    } else {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                    }
                    k++;
                }
            } else {
                for (Vector part : parts) {
                    if (part.isDense()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                    } else if (part.isSparse()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                    } else {
                        if (op.isKeepStorage()) {
                            resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted);
                        } else {
                            resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse);
                        }
                    }
                    k++;
                }
            }
        }
    } else {
        // OpType.ALL
        for (Vector part : parts) {
            if (part.isDense()) {
                if (op.isInplace()) {
                    resParts[k] = part.getStorage();
                } else {
                    resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                }
            } else {
                if (op.isKeepStorage()) {
                    if (part.isSparse()) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
                    } else {
                        // sorted
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySorted, part.dim());
                    }
                } else {
                    if (part.getStorage() instanceof LongKeyVectorStorage) {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptySparse, part.dim());
                    } else {
                        resParts[k] = emptyStorage(part.getStorage(), StorageMethod.emptyDense);
                    }
                }
            }
            k++;
        }
    }
    return resParts;
}
Also used : LongKeyVectorStorage(com.tencent.angel.ml.math2.storage.LongKeyVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) LongKeyVectorStorage(com.tencent.angel.ml.math2.storage.LongKeyVectorStorage) ComponentVector(com.tencent.angel.ml.math2.vector.ComponentVector) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 53 with Storage

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

the class IntIntVector method max.

public int max() {
    IntIntVectorStorage idstorage = (IntIntVectorStorage) 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 : IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) IntIterator(it.unimi.dsi.fastutil.ints.IntIterator)

Example 54 with Storage

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

the class IntFloatVector method numZeros.

public int numZeros() {
    IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
    if (dstorage.size() == 0)
        return (int) dim;
    int 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 (int) getDim() - numZero;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Example 55 with Storage

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

the class IntFloatVector method max.

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

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)187 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)186 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)185 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)183 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)182 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)181 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)180 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)180 Storage (com.tencent.angel.ml.math2.storage.Storage)169 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)139 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)123 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)123 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)121 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)119 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)119 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)119 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)119 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)118 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)118 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)117