Search in sources :

Example 1 with DoubleVectorStorage

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

the class DoubleVector method sum.

@Override
public double sum() {
    DoubleVectorStorage dstorage = (DoubleVectorStorage) storage;
    double sumval = 0.0;
    if (dstorage.isSparse()) {
        DoubleIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            sumval += iter.nextDouble();
        }
    } else {
        for (double val : dstorage.getValues()) {
            sumval += val;
        }
    }
    return sumval;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) DoubleVectorStorage(com.tencent.angel.ml.math2.storage.DoubleVectorStorage)

Example 2 with DoubleVectorStorage

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

the class DoubleVector method norm.

@Override
public double norm() {
    DoubleVectorStorage dstorage = (DoubleVectorStorage) storage;
    double sumval2 = 0.0;
    if (dstorage.isSparse()) {
        DoubleIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextDouble();
            sumval2 += val * val;
        }
    } else {
        for (double val : dstorage.getValues()) {
            sumval2 += val * val;
        }
    }
    return Math.sqrt(sumval2);
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) DoubleVectorStorage(com.tencent.angel.ml.math2.storage.DoubleVectorStorage)

Example 3 with DoubleVectorStorage

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

the class AggrFuncTest method testPull.

@Test
public void testPull() throws InvalidParameterException, InterruptedException, ExecutionException {
    GetFunc func = new Pull(w2Client.getMatrixId(), 1);
    double[] result = ((DoubleVectorStorage) (((GetRowResult) w2Client.get(func)).getRow()).getStorage()).getValues();
    for (int i = 0; i < dim; i++) {
        Assert.assertEquals(result[i], localArray1[i], delta);
    }
}
Also used : GetFunc(com.tencent.angel.ml.matrix.psf.get.base.GetFunc) Pull(com.tencent.angel.ml.matrix.psf.aggr.Pull) DoubleVectorStorage(com.tencent.angel.ml.math2.storage.DoubleVectorStorage)

Aggregations

DoubleVectorStorage (com.tencent.angel.ml.math2.storage.DoubleVectorStorage)3 DoubleIterator (it.unimi.dsi.fastutil.doubles.DoubleIterator)2 Pull (com.tencent.angel.ml.matrix.psf.aggr.Pull)1 GetFunc (com.tencent.angel.ml.matrix.psf.get.base.GetFunc)1