use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method max.
public long max() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
long maxval = Long.MIN_VALUE;
if (idstorage.isSparse()) {
LongIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
long val = iter.nextLong();
if (val > maxval) {
maxval = val;
}
}
} else {
for (long val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method average.
public double average() {
LongLongVectorStorage dstorage = (LongLongVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
if (dstorage.isSparse()) {
LongIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
sumval += iter.nextLong();
}
} else {
for (double val : dstorage.getValues()) {
sumval += val;
}
}
sumval /= getDim();
return sumval;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method argmin.
public long argmin() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
long minval = Long.MAX_VALUE;
long minidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2LongMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2LongMap.Entry entry = iter.next();
long idx = entry.getLongKey();
long val = entry.getLongValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
long[] val = idstorage.getValues();
long size = idstorage.size();
for (int i = 0; i < size; i++) {
long idx = indices[i];
if (val[i] < minval) {
minval = val[i];
minidx = idx;
}
}
}
return minidx;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method min.
public long min() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
long minval = Long.MAX_VALUE;
if (idstorage.isSparse()) {
LongIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
long val = iter.nextLong();
if (val < minval) {
minval = val;
}
}
} else {
for (long val : idstorage.getValues()) {
if (val < minval) {
minval = val;
}
}
}
return minval;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class MixedBinaryOutAllExecutor method apply.
private static Vector apply(CompLongLongVector v1, LongIntVector v2, Binary op) {
LongLongVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongLongSortedVectorStorage) {
resParts[i] = new LongLongSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
long subidx = i % subDim;
if (v2.getStorage().hasKey(i)) {
((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
} else {
((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
}
}
LongLongVector[] res = new LongLongVector[parts.length];
int i = 0;
for (LongLongVector part : parts) {
res[i] = new LongLongVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongLongVectorStorage) resParts[i]);
i++;
}
return new CompLongLongVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Aggregations