Search in sources :

Example 1 with LongVectorStorage

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

the class LongVector method norm.

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

Example 2 with LongVectorStorage

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

the class LongVector method sum.

@Override
public double sum() {
    LongVectorStorage lstorage = (LongVectorStorage) storage;
    double sumval = 0.0;
    if (lstorage.isSparse()) {
        LongIterator iter = lstorage.valueIterator();
        while (iter.hasNext()) {
            sumval += iter.nextLong();
        }
    } else {
        for (double val : lstorage.getValues()) {
            sumval += val;
        }
    }
    return sumval;
}
Also used : LongVectorStorage(com.tencent.angel.ml.math2.storage.LongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Aggregations

LongVectorStorage (com.tencent.angel.ml.math2.storage.LongVectorStorage)2 LongIterator (it.unimi.dsi.fastutil.longs.LongIterator)2