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);
}
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;
}
Aggregations