Search in sources :

Example 1 with FloatVectorStorage

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

the class FloatVector method sum.

@Override
public double sum() {
    FloatVectorStorage fstorage = (FloatVectorStorage) storage;
    double sumval = 0.0;
    if (fstorage.isSparse()) {
        FloatIterator iter = fstorage.valueIterator();
        while (iter.hasNext()) {
            sumval += iter.nextFloat();
        }
    } else {
        for (double val : fstorage.getValues()) {
            sumval += val;
        }
    }
    return sumval;
}
Also used : FloatVectorStorage(com.tencent.angel.ml.math2.storage.FloatVectorStorage) FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator)

Example 2 with FloatVectorStorage

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

the class FloatVector method norm.

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

Aggregations

FloatVectorStorage (com.tencent.angel.ml.math2.storage.FloatVectorStorage)2 FloatIterator (it.unimi.dsi.fastutil.floats.FloatIterator)2