use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.
the class MixedBinaryOutNonZAExecutor method apply.
private static Vector apply(CompLongFloatVector v1, LongIntVector v2, Binary op) {
LongFloatVector[] parts = v1.getPartitions();
Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
if (v2.isSparse()) {
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
ObjectIterator<Long2IntMap.Entry> iter = v2.getStorage().entryIterator();
while (iter.hasNext()) {
Long2IntMap.Entry entry = iter.next();
long gidx = entry.getLongKey();
int pidx = (int) (gidx / subDim);
long subidx = gidx % subDim;
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), entry.getIntValue()));
}
} else {
// sorted
if (!op.isKeepStorage()) {
for (int i = 0; i < parts.length; i++) {
if (parts[i].getStorage() instanceof LongFloatSortedVectorStorage) {
resParts[i] = new LongFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
long[] v2Indices = v2.getStorage().getIndices();
int[] v2Values = v2.getStorage().getValues();
for (int i = 0; i < v2Indices.length; i++) {
long gidx = v2Indices[i];
int pidx = (int) (gidx / subDim);
long subidx = gidx % subDim;
((LongFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2Values[i]));
}
}
LongFloatVector[] res = new LongFloatVector[parts.length];
int i = 0;
for (LongFloatVector part : parts) {
res[i] = new LongFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongFloatVectorStorage) resParts[i]);
i++;
}
return new CompLongFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.
the class LongFloatVector method argmin.
public long argmin() {
LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
float minval = Float.MAX_VALUE;
long minidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2FloatMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2FloatMap.Entry entry = iter.next();
long idx = entry.getLongKey();
float val = entry.getFloatValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
float[] 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.LongFloatVectorStorage in project angel by Tencent.
the class LongFloatVector method numZeros.
public long numZeros() {
LongFloatVectorStorage dstorage = (LongFloatVectorStorage) storage;
if (dstorage.size() == 0)
return (long) dim;
long numZero = 0;
if (dstorage.isSparse()) {
FloatIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextFloat() != 0) {
numZero += 1;
}
}
} else {
for (float val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (long) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.
the class LongFloatVector method min.
public float min() {
LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
float minval = Float.MAX_VALUE;
if (idstorage.isSparse()) {
FloatIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
float val = iter.nextFloat();
if (val < minval) {
minval = val;
}
}
} else {
for (float val : idstorage.getValues()) {
if (val < minval) {
minval = val;
}
}
}
return minval;
}
use of com.tencent.angel.ml.math2.storage.LongFloatVectorStorage in project angel by Tencent.
the class LongFloatVector method argmax.
public long argmax() {
LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
float maxval = Float.MIN_VALUE;
long maxidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2FloatMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2FloatMap.Entry entry = iter.next();
long idx = entry.getLongKey();
float val = entry.getFloatValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
float[] 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;
}
Aggregations