use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class SimpleBinaryOutAllExecutor method apply.
public static Vector apply(IntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector res;
if (v1.isDense()) {
res = v1.copy();
float[] resValues = res.getStorage().getValues();
for (int i = 0; i < v1.getDim(); i++) {
resValues[i] = op.apply(resValues[i], v2.get(i));
}
} else if (v1.isSparse()) {
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
ObjectIterator<Int2FloatMap.Entry> iter1 = v1.getStorage().entryIterator();
while (iter1.hasNext()) {
Int2FloatMap.Entry entry = iter1.next();
int idx = entry.getIntKey();
resValues[idx] = entry.getFloatValue();
}
for (int i = 0; i < v1.getDim(); i++) {
resValues[i] = op.apply(resValues[i], v2.get(i));
}
res = new IntFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
}
} else {
// sorted
if (op.isKeepStorage()) {
throw new AngelException("operation is not support!");
} else {
IntFloatVectorStorage newStorage = v1.getStorage().emptyDense();
float[] resValues = newStorage.getValues();
int[] v1Indices = v1.getStorage().getIndices();
float[] v1Values = v1.getStorage().getValues();
int size = v1.size();
for (int i = 0; i < size; i++) {
int idx = v1Indices[i];
resValues[idx] = v1Values[i];
}
for (int i = 0; i < v1.getDim(); i++) {
resValues[i] = op.apply(resValues[i], v2.get(i));
}
res = new IntFloatVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), newStorage);
}
}
return res;
}
Aggregations