use of com.tencent.angel.ml.math2.storage.LongIntVectorStorage in project angel by Tencent.
the class LongIntVector method max.
public int max() {
LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
int maxval = Integer.MIN_VALUE;
if (idstorage.isSparse()) {
IntIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
int val = iter.nextInt();
if (val > maxval) {
maxval = val;
}
}
} else {
for (int val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.LongIntVectorStorage in project angel by Tencent.
the class LongIntVector method argmin.
public long argmin() {
LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int minval = Integer.MAX_VALUE;
long minidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry entry = iter.next();
long idx = entry.getLongKey();
int val = entry.getIntValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
int[] 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.LongIntVectorStorage in project angel by Tencent.
the class LongIntVector method argmax.
public long argmax() {
LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int maxval = Integer.MIN_VALUE;
long maxidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry entry = iter.next();
long idx = entry.getLongKey();
int val = entry.getIntValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
int[] 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.LongIntVectorStorage in project angel by Tencent.
the class MixedBinaryOutZAExecutor method apply.
private static Vector apply(CompLongIntVector v1, LongDummyVector v2, Binary op) {
LongIntVector[] 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)) {
((LongIntVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
}
} else {
long base = 0;
for (int i = 0; i < parts.length; i++) {
LongIntVector part = parts[i];
LongIntVectorStorage resPart = (LongIntVectorStorage) resParts[i];
if (part.isDense()) {
int[] partValues = part.getStorage().getValues();
int[] 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<Long2IntMap.Entry> piter = part.getStorage().entryIterator();
while (piter.hasNext()) {
Long2IntMap.Entry entry = piter.next();
long idx = entry.getLongKey();
if (v2.hasKey(idx + base)) {
resPart.set(idx, op.apply(entry.getIntValue(), v2.get(idx + base)));
}
}
} else {
// sorted
if (op.isKeepStorage()) {
long[] partIndices = part.getStorage().getIndices();
int[] partValues = part.getStorage().getValues();
long[] resPartIndices = resPart.getIndices();
int[] 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();
int[] 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();
}
}
LongIntVector[] res = new LongIntVector[parts.length];
int i = 0;
for (LongIntVector part : parts) {
res[i] = new LongIntVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongIntVectorStorage) resParts[i]);
i++;
}
return new CompLongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.storage.LongIntVectorStorage in project angel by Tencent.
the class SimpleBinaryOutAllExecutor method apply.
public static Vector apply(LongIntVector v1, LongDummyVector v2, Binary op) {
LongIntVector res;
if (v1.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
// multi-rehash
LongIntVectorStorage newStorage = v1.getStorage().emptySparse((int) (v1.getDim()));
LongIntVectorStorage v1Storage = v1.getStorage();
for (int i = 0; i < v1.getDim(); i++) {
if (v1Storage.hasKey(i)) {
newStorage.set(i, op.apply(v1.get(i), v2.get(i)));
} else {
newStorage.set(i, op.apply(0, v2.get(i)));
}
}
res = new LongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
}
} else {
// sorted
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
LongIntVectorStorage newStorage = new LongIntSparseVectorStorage(v1.getDim());
LongIntVectorStorage v1Storage = v1.getStorage();
for (int i = 0; i < v1.getDim(); i++) {
if (v1Storage.hasKey(i)) {
newStorage.set(i, op.apply(v1.get(i), v2.get(i)));
} else {
newStorage.set(i, op.apply(0, v2.get(i)));
}
}
res = new LongIntVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
}
}
return res;
}
Aggregations