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