Search in sources :

Example 46 with LongDoubleVector

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

the class MixedBinaryInNonZAExecutor method apply.

private static Vector apply(CompLongDoubleVector v1, LongDummyVector 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();
    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;
        ((LongDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
    }
    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 47 with LongDoubleVector

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

the class CompReduceExecutor method apply.

private static UnionEle apply(CompLongDoubleVector v, ReduceOP op, int start, int end) {
    UnionEle res = new UnionEle();
    LongDoubleVector[] 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) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector)

Example 48 with LongDoubleVector

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

the class UpdatePSFTest method testSparseDoubleLongKeyUDF.

public void testSparseDoubleLongKeyUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_LONG_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    long[] index = genLongIndexs(feaNum, nnz);
    LongDoubleVector deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < feaNum; i++) {
        deltaVec.set(i, i);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    // client1.clock().get();
    LongDoubleVector row = (LongDoubleVector) client1.getRow(0);
    for (long id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
// Assert.assertTrue(index.length == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector)

Example 49 with LongDoubleVector

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

the class RBCompLongDoubleMatrix method initEmpty.

@Override
public void initEmpty(int idx) {
    int numComp = (int) ((getDim() + subDim - 1) / subDim);
    if (null == rows[idx]) {
        LongDoubleVector[] tmpParts = new LongDoubleVector[numComp];
        for (int i = 0; i < numComp; i++) {
            LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage(subDim);
            tmpParts[i] = new LongDoubleVector(matrixId, idx, clock, (long) getDim(), storage);
        }
        CompLongDoubleVector tmpVect = new CompLongDoubleVector(matrixId, idx, clock, (long) getDim(), tmpParts, subDim);
        rows[idx] = tmpVect;
    }
}
Also used : CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)

Example 50 with LongDoubleVector

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

the class RBLongDoubleMatrix method initEmpty.

@Override
public void initEmpty(int idx) {
    if (null == rows[idx]) {
        LongDoubleSparseVectorStorage storage = new LongDoubleSparseVectorStorage((long) getDim());
        rows[idx] = new LongDoubleVector(matrixId, idx, clock, (long) getDim(), storage);
    }
}
Also used : LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)

Aggregations

LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)55 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)47 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)37 CompLongDoubleVector (com.tencent.angel.ml.math2.vector.CompLongDoubleVector)34 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)32 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)32 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)32 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)30 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)30 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)30 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)26 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)20 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)20