use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryInNonZAExecutor method apply.
private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector[] 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 IntFloatSortedVectorStorage) {
resParts[i] = new IntFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
int[] v2Indices = v2.getIndices();
for (int i = 0; i < v2Indices.length; i++) {
int gidx = v2Indices[i];
int pidx = (int) (gidx / subDim);
int subidx = gidx % subDim;
((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
}
IntFloatVector[] res = new IntFloatVector[parts.length];
int i = 0;
for (IntFloatVector part : parts) {
res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasFloatMatrix mat, IntDummyVector v, boolean onCol, Binary op) {
float[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = new byte[v.getDim()];
if (onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == INTERSECTION) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = 0;
}
}
}
} else if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
float[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new float[m * n];
} else {
newData = ArrayCopy.copy(data);
}
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(newData[i * n + j], 0);
}
}
}
}
return new BlasFloatMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int i = 0; i < n; i++) {
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
data[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == INTERSECTION) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = 0;
}
}
}
} else if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
return mat;
} else {
float[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new float[m * n];
} else {
newData = ArrayCopy.copy(data);
}
int[] idxs = v.getIndices();
for (int i = 0; i < n; i++) {
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
newData[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(newData[i * n + j], 0);
}
}
}
}
return new BlasFloatMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasDoubleMatrix mat, IntDummyVector v, boolean onCol, Binary op) {
double[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = new byte[v.getDim()];
if (onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == INTERSECTION) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = 0;
}
}
}
} else if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
for (int j = 0; j < n; j++) {
newData[i * n + j] = op.apply(newData[i * n + j], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int i = 0; i < n; i++) {
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
data[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == INTERSECTION) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = 0;
}
}
}
} else if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
data[i * n + j] = op.apply(data[i * n + j], 0);
}
}
}
}
return mat;
} else {
double[] newData;
if (op.getOpType() == INTERSECTION) {
newData = new double[m * n];
} else {
newData = ArrayCopy.copy(data);
}
int[] idxs = v.getIndices();
for (int i = 0; i < n; i++) {
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
newData[i * n + j] = op.apply(data[i * n + j], 1);
}
}
if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
for (int i = 0; i < m; i++) {
newData[i * n + j] = op.apply(newData[i * n + j], 0);
}
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class MixedBinaryInAllExecutor method apply.
private static Vector apply(CompIntFloatVector v1, IntDummyVector v2, Binary op) {
IntFloatVector[] 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 IntFloatSortedVectorStorage) {
resParts[i] = new IntFloatSparseVectorStorage(parts[i].getDim(), parts[i].getStorage().getIndices(), parts[i].getStorage().getValues());
}
}
}
int subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
for (int i = 0; i < v1.getDim(); i++) {
int pidx = (int) (i / subDim);
int subidx = i % subDim;
((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
}
IntFloatVector[] res = new IntFloatVector[parts.length];
int i = 0;
for (IntFloatVector part : parts) {
res[i] = new IntFloatVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntFloatVectorStorage) resParts[i]);
i++;
}
v1.setPartitions(res);
return v1;
}
use of com.tencent.angel.ml.math2.vector.IntDummyVector in project angel by Tencent.
the class BinaryMatrixExecutor method apply.
private static Matrix apply(BlasDoubleMatrix mat, IntDummyVector v, int idx, boolean onCol, Binary op) {
double[] data = mat.getData();
int m = mat.getNumRows(), n = mat.getNumCols();
int size = v.size();
byte[] flag = new byte[v.getDim()];
if (onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
data[i * n + idx] = op.apply(data[i * n + idx], 1);
}
if (op.getOpType() == INTERSECTION) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = 0;
}
}
} else if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
data[i * n + idx] = op.apply(data[i * n + idx], 0);
}
}
}
return mat;
} else if (onCol && !op.isInplace()) {
double[] newData = ArrayCopy.copy(data);
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int i = idxs[k];
flag[i] = 1;
newData[i * n + idx] = op.apply(data[i * n + idx], 1);
}
if (op.getOpType() == INTERSECTION) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
newData[i * n + idx] = 0;
}
}
} else if (op.getOpType() == ALL) {
for (int i = 0; i < m; i++) {
if (flag[i] == 0) {
newData[i * n + idx] = op.apply(newData[i * n + idx], 0);
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
} else if (!onCol && op.isInplace()) {
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
data[idx * n + j] = op.apply(data[idx * n + j], 1);
}
if (op.getOpType() == INTERSECTION) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = 0;
}
}
} else if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
data[idx * n + j] = op.apply(data[idx * n + j], 0);
}
}
}
return mat;
} else {
double[] newData = ArrayCopy.copy(data);
int[] idxs = v.getIndices();
for (int k = 0; k < size; k++) {
int j = idxs[k];
flag[j] = 1;
newData[idx * n + j] = op.apply(data[idx * n + j], 1);
}
if (op.getOpType() == INTERSECTION) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
newData[idx * n + j] = 0;
}
}
} else if (op.getOpType() == ALL) {
for (int j = 0; j < n; j++) {
if (flag[j] == 0) {
newData[idx * n + j] = op.apply(newData[idx * n + j], 0);
}
}
}
return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
}
}
Aggregations