Search in sources :

Example 11 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator 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 12 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator 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

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