use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method argmax.
public long argmax() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
long maxval = Long.MIN_VALUE;
long maxidx = -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 > maxval) {
maxval = val;
maxidx = 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] > maxval) {
maxval = val[i];
maxidx = idx;
}
}
}
return maxidx;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method numZeros.
public long numZeros() {
LongLongVectorStorage dstorage = (LongLongVectorStorage) storage;
if (dstorage.size() == 0)
return (long) dim;
long numZero = 0;
if (dstorage.isSparse()) {
LongIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextLong() != 0) {
numZero += 1;
}
}
} else {
for (long val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (long) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class LongLongVector method std.
public double std() {
LongLongVectorStorage dstorage = (LongLongVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
double sumval2 = 0.0;
if (dstorage.isSparse()) {
LongIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
double val = iter.nextLong();
sumval += val;
sumval2 += val * val;
}
} else {
for (double val : dstorage.getValues()) {
sumval += val;
sumval2 += val * val;
}
}
sumval /= getDim();
sumval2 /= getDim();
return Math.sqrt(sumval2 - sumval * sumval);
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class CompLongLongRowUpdateSplit method serialize.
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
LongLongVectorStorage storage = split.getStorage();
buf.writeInt(storage.size());
if (storage instanceof LongLongSparseVectorStorage) {
ObjectIterator<Long2LongMap.Entry> iter = storage.entryIterator();
Long2LongMap.Entry entry;
while (iter.hasNext()) {
entry = iter.next();
buf.writeLong(entry.getLongKey());
buf.writeLong(entry.getLongValue());
}
} else if (storage instanceof LongLongSortedVectorStorage) {
long[] indices = storage.getIndices();
long[] values = storage.getValues();
for (int i = 0; i < indices.length; i++) {
buf.writeLong(indices[i]);
buf.writeLong(values[i]);
}
} else {
throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
}
}
use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.
the class MixedBinaryOutZAExecutor method apply.
private static Vector apply(CompLongLongVector v1, LongDummyVector v2, Binary op) {
LongLongVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (v1.size() > v2.size()) {
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
long[] v2Indices = v2.getIndices();
for (int i = 0; i < v2Indices.length; i++) {
long idx = v2Indices[i];
int pidx = (int) (idx / subDim);
long subidx = idx % subDim;
if (parts[pidx].hasKey(subidx)) {
((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
}
} else {
long base = 0;
for (int i = 0; i < parts.length; i++) {
LongLongVector part = parts[i];
LongLongVectorStorage resPart = (LongLongVectorStorage) resParts[i];
if (part.isDense()) {
long[] partValues = part.getStorage().getValues();
long[] resPartValues = resPart.getValues();
for (int j = 0; j < partValues.length; j++) {
if (v2.hasKey(j + base)) {
resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
}
}
} else if (part.isSparse()) {
ObjectIterator<Long2LongMap.Entry> piter = part.getStorage().entryIterator();
while (piter.hasNext()) {
Long2LongMap.Entry entry = piter.next();
long idx = entry.getLongKey();
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(entry.getLongValue(), v2.get(idx + base)));
}
}
} else {
// sorted
if (op.isKeepStorage()) {
long[] partIndices = part.getStorage().getIndices();
long[] partValues = part.getStorage().getValues();
long[] resPartIndices = resPart.getIndices();
long[] resPartValues = resPart.getValues();
for (int j = 0; j < partIndices.length; j++) {
long idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPartIndices[j] = idx;
resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
}
}
} else {
long[] partIndices = part.getStorage().getIndices();
long[] partValues = part.getStorage().getValues();
for (int j = 0; j < partIndices.length; j++) {
long idx = partIndices[j];
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
}
}
}
}
base += part.getDim();
}
}
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