Search in sources :

Example 6 with IntDummyVector

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;
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) LongLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage) IntDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) LongDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) IntIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) IntLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage) IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) LongLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSortedVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) IntIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 7 with IntDummyVector

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);
    }
}
Also used : BlasFloatMatrix(com.tencent.angel.ml.math2.matrix.BlasFloatMatrix)

Example 8 with IntDummyVector

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);
    }
}
Also used : BlasDoubleMatrix(com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix)

Example 9 with IntDummyVector

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;
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) LongLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage) IntDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage) LongDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage) LongDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) IntIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage) LongIntSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSortedVectorStorage) IntLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage) IntLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage) LongIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) LongLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSortedVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) IntIntSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) LongFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage) LongFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 10 with IntDummyVector

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);
    }
}
Also used : BlasDoubleMatrix(com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix)

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)26 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)26 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)26 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)26 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)24 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)24 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)24 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)24 Storage (com.tencent.angel.ml.math2.storage.Storage)24 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)18 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)16 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)16 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)16 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)16 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)16 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)16 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)16 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)16 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)16 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)16