Search in sources :

Example 11 with IntIntVector

use of com.tencent.angel.ml.math2.vector.IntIntVector in project angel by Tencent.

the class MixedBinaryInAllExecutor method apply.

private static Vector apply(CompIntFloatVector v1, IntIntVector v2, Binary op) {
    IntFloatVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v2.isDense()) {
        int[] v2Values = v2.getStorage().getValues();
        int base = 0, k = 0;
        for (IntFloatVector part : parts) {
            IntFloatVectorStorage resPart = (IntFloatVectorStorage) resParts[k];
            if (part.isDense()) {
                float[] partValue = part.getStorage().getValues();
                float[] resPartValues = resPart.getValues();
                for (int i = 0; i < partValue.length; i++) {
                    int idx = i + base;
                    resPartValues[i] = op.apply(partValue[i], v2Values[idx]);
                }
            } else if (part.isSparse()) {
                float[] resPartValues = resPart.getValues();
                if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                    for (int i = 0; i < part.getDim(); i++) {
                        resPart.set(i, op.apply(0, v2Values[i + base]));
                    }
                    ObjectIterator<Int2FloatMap.Entry> iter = part.getStorage().entryIterator();
                    while (iter.hasNext()) {
                        Int2FloatMap.Entry entry = iter.next();
                        int idx = entry.getIntKey();
                        resPart.set(idx, op.apply(entry.getFloatValue(), v2Values[idx + base]));
                    }
                } else {
                    for (int i = 0; i < resPartValues.length; i++) {
                        if (part.getStorage().hasKey(i)) {
                            resPart.set(i, op.apply(part.get(i), v2Values[i + base]));
                        } else {
                            resPart.set(i, op.apply(0, v2Values[i + base]));
                        }
                    }
                }
            } else {
                // sorted
                int[] resPartIndices = resPart.getIndices();
                float[] resPartValues = resPart.getValues();
                if (op.isKeepStorage()) {
                    if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                        int[] partIndices = part.getStorage().getIndices();
                        float[] partValues = part.getStorage().getValues();
                        for (int i = 0; i < part.getDim(); i++) {
                            resPartIndices[i] = i;
                            resPartValues[i] = op.apply(0, v2Values[i + base]);
                        }
                        int size = part.size();
                        for (int i = 0; i < size; i++) {
                            int idx = partIndices[i];
                            resPartValues[idx] = op.apply(partValues[i], v2Values[idx + base]);
                        }
                    } else {
                        IntFloatVectorStorage partStorage = part.getStorage();
                        for (int i = 0; i < resPartValues.length; i++) {
                            if (partStorage.hasKey(i)) {
                                resPartIndices[i] = i;
                                resPartValues[i] = op.apply(partStorage.get(i), v2Values[i + base]);
                            } else {
                                resPartIndices[i] = i;
                                resPartValues[i] = op.apply(0, v2Values[i + base]);
                            }
                        }
                    }
                } else {
                    if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                        int[] partIndices = part.getStorage().getIndices();
                        float[] partValues = part.getStorage().getValues();
                        for (int i = 0; i < part.getDim(); i++) {
                            resPartValues[i] = op.apply(0, v2Values[i + base]);
                        }
                        int size = part.size();
                        for (int i = 0; i < size; i++) {
                            int idx = partIndices[i];
                            resPartValues[idx] = op.apply(partValues[i], v2Values[idx + base]);
                        }
                    } else {
                        IntFloatVectorStorage partStorage = part.getStorage();
                        for (int i = 0; i < resPartValues.length; i++) {
                            if (partStorage.hasKey(i)) {
                                resPartValues[i] = op.apply(partStorage.get(i), v2Values[i + base]);
                            } else {
                                resPartValues[i] = op.apply(0, v2Values[i + base]);
                            }
                        }
                    }
                }
            }
            base += part.getDim();
            k++;
        }
    } else {
        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;
            if (v2.getStorage().hasKey(i)) {
                ((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
            } else {
                ((IntFloatVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
            }
        }
    }
    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 : IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) 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) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap)

Example 12 with IntIntVector

use of com.tencent.angel.ml.math2.vector.IntIntVector in project angel by Tencent.

the class MixedBinaryInAllExecutor method apply.

private static Vector apply(CompIntDoubleVector v1, IntIntVector v2, Binary op) {
    IntDoubleVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v2.isDense()) {
        int[] v2Values = v2.getStorage().getValues();
        int base = 0, k = 0;
        for (IntDoubleVector part : parts) {
            IntDoubleVectorStorage resPart = (IntDoubleVectorStorage) resParts[k];
            if (part.isDense()) {
                double[] partValue = part.getStorage().getValues();
                double[] resPartValues = resPart.getValues();
                for (int i = 0; i < partValue.length; i++) {
                    int idx = i + base;
                    resPartValues[i] = op.apply(partValue[i], v2Values[idx]);
                }
            } else if (part.isSparse()) {
                double[] resPartValues = resPart.getValues();
                if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                    for (int i = 0; i < part.getDim(); i++) {
                        resPart.set(i, op.apply(0, v2Values[i + base]));
                    }
                    ObjectIterator<Int2DoubleMap.Entry> iter = part.getStorage().entryIterator();
                    while (iter.hasNext()) {
                        Int2DoubleMap.Entry entry = iter.next();
                        int idx = entry.getIntKey();
                        resPart.set(idx, op.apply(entry.getDoubleValue(), v2Values[idx + base]));
                    }
                } else {
                    for (int i = 0; i < resPartValues.length; i++) {
                        if (part.getStorage().hasKey(i)) {
                            resPart.set(i, op.apply(part.get(i), v2Values[i + base]));
                        } else {
                            resPart.set(i, op.apply(0, v2Values[i + base]));
                        }
                    }
                }
            } else {
                // sorted
                int[] resPartIndices = resPart.getIndices();
                double[] resPartValues = resPart.getValues();
                if (op.isKeepStorage()) {
                    if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                        int[] partIndices = part.getStorage().getIndices();
                        double[] partValues = part.getStorage().getValues();
                        for (int i = 0; i < part.getDim(); i++) {
                            resPartIndices[i] = i;
                            resPartValues[i] = op.apply(0, v2Values[i + base]);
                        }
                        int size = part.size();
                        for (int i = 0; i < size; i++) {
                            int idx = partIndices[i];
                            resPartValues[idx] = op.apply(partValues[i], v2Values[idx + base]);
                        }
                    } else {
                        IntDoubleVectorStorage partStorage = part.getStorage();
                        for (int i = 0; i < resPartValues.length; i++) {
                            if (partStorage.hasKey(i)) {
                                resPartIndices[i] = i;
                                resPartValues[i] = op.apply(partStorage.get(i), v2Values[i + base]);
                            } else {
                                resPartIndices[i] = i;
                                resPartValues[i] = op.apply(0, v2Values[i + base]);
                            }
                        }
                    }
                } else {
                    if (part.size() < Constant.denseLoopThreshold * part.getDim()) {
                        int[] partIndices = part.getStorage().getIndices();
                        double[] partValues = part.getStorage().getValues();
                        for (int i = 0; i < part.getDim(); i++) {
                            resPartValues[i] = op.apply(0, v2Values[i + base]);
                        }
                        int size = part.size();
                        for (int i = 0; i < size; i++) {
                            int idx = partIndices[i];
                            resPartValues[idx] = op.apply(partValues[i], v2Values[idx + base]);
                        }
                    } else {
                        IntDoubleVectorStorage partStorage = part.getStorage();
                        for (int i = 0; i < resPartValues.length; i++) {
                            if (partStorage.hasKey(i)) {
                                resPartValues[i] = op.apply(partStorage.get(i), v2Values[i + base]);
                            } else {
                                resPartValues[i] = op.apply(0, v2Values[i + base]);
                            }
                        }
                    }
                }
            }
            base += part.getDim();
            k++;
        }
    } else {
        if (!op.isKeepStorage()) {
            for (int i = 0; i < parts.length; i++) {
                if (parts[i].getStorage() instanceof IntDoubleSortedVectorStorage) {
                    resParts[i] = new IntDoubleSparseVectorStorage(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;
            if (v2.getStorage().hasKey(i)) {
                ((IntDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), v2.get(i)));
            } else {
                ((IntDoubleVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 0));
            }
        }
    }
    IntDoubleVector[] res = new IntDoubleVector[parts.length];
    int i = 0;
    for (IntDoubleVector part : parts) {
        res[i] = new IntDoubleVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (IntDoubleVectorStorage) resParts[i]);
        i++;
    }
    v1.setPartitions(res);
    return v1;
}
Also used : Int2DoubleMap(it.unimi.dsi.fastutil.ints.Int2DoubleMap) CompIntDoubleVector(com.tencent.angel.ml.math2.vector.CompIntDoubleVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) 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) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) IntDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)

Example 13 with IntIntVector

use of com.tencent.angel.ml.math2.vector.IntIntVector in project angel by Tencent.

the class BinaryMatrixExecutor method apply.

private static Matrix apply(BlasDoubleMatrix mat, IntIntVector v, boolean onCol, Binary op) {
    double[] data = mat.getData();
    int m = mat.getNumRows(), n = mat.getNumCols();
    int size = v.size();
    byte[] flag = null;
    if (!v.isDense()) {
        flag = new byte[v.getDim()];
    }
    if (onCol && op.isInplace()) {
        if (v.isDense()) {
            int[] values = v.getStorage().getValues();
            for (int i = 0; i < m; i++) {
                int value = values[i];
                for (int j = 0; j < n; j++) {
                    data[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else if (v.isSparse()) {
            ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int i = entry.getIntKey();
                flag[i] = 1;
                double value = entry.getIntValue();
                for (int j = 0; j < n; j++) {
                    data[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else {
            // sorted
            int[] idxs = v.getStorage().getIndices();
            int[] values = v.getStorage().getValues();
            for (int k = 0; k < size; k++) {
                int i = idxs[k];
                flag[i] = 1;
                int value = values[k];
                for (int j = 0; j < n; j++) {
                    data[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        }
        if (!v.isDense()) {
            switch(op.getOpType()) {
                case INTERSECTION:
                    for (int i = 0; i < m; i++) {
                        if (flag[i] == 0) {
                            for (int j = 0; j < n; j++) {
                                data[i * n + j] = 0;
                            }
                        }
                    }
                case UNION:
                    break;
                case 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);
        }
        if (v.isDense()) {
            int[] values = v.getStorage().getValues();
            for (int i = 0; i < m; i++) {
                int value = values[i];
                for (int j = 0; j < n; j++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else if (v.isSparse()) {
            ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int i = entry.getIntKey();
                flag[i] = 1;
                double value = entry.getIntValue();
                for (int j = 0; j < n; j++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else {
            // sorted
            int[] idxs = v.getStorage().getIndices();
            int[] values = v.getStorage().getValues();
            for (int k = 0; k < size; k++) {
                int i = idxs[k];
                flag[i] = 1;
                int value = values[k];
                for (int j = 0; j < n; j++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        }
        if (!v.isDense()) {
            switch(op.getOpType()) {
                case INTERSECTION:
                    break;
                case UNION:
                    break;
                case 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(data[i * n + j], 0);
                            }
                        }
                    }
            }
        }
        return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
    } else if (!onCol && op.isInplace()) {
        if (v.isDense()) {
            int[] values = v.getStorage().getValues();
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    data[i * n + j] = op.apply(data[i * n + j], values[j]);
                }
            }
        } else if (v.isSparse()) {
            ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                double value = entry.getIntValue();
                flag[j] = 1;
                for (int i = 0; i < m; i++) {
                    data[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else {
            // sorted
            int[] idxs = v.getStorage().getIndices();
            int[] values = v.getStorage().getValues();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                int value = values[k];
                flag[j] = 1;
                for (int i = 0; i < m; i++) {
                    data[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        }
        if (!v.isDense()) {
            switch(op.getOpType()) {
                case INTERSECTION:
                    for (int j = 0; j < n; j++) {
                        if (flag[j] == 0) {
                            for (int i = 0; i < m; i++) {
                                data[i * n + j] = 0;
                            }
                        }
                    }
                case UNION:
                    break;
                case 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);
        }
        if (v.isDense()) {
            int[] values = v.getStorage().getValues();
            for (int j = 0; j < n; j++) {
                int value = values[j];
                for (int i = 0; i < m; i++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else if (v.isSparse()) {
            ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
            while (iter.hasNext()) {
                Int2IntMap.Entry entry = iter.next();
                int j = entry.getIntKey();
                flag[j] = 1;
                double value = entry.getIntValue();
                for (int i = 0; i < m; i++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        } else {
            // sorted
            int[] idxs = v.getStorage().getIndices();
            int[] values = v.getStorage().getValues();
            for (int k = 0; k < size; k++) {
                int j = idxs[k];
                flag[j] = 1;
                int value = values[k];
                for (int i = 0; i < m; i++) {
                    newData[i * n + j] = op.apply(data[i * n + j], value);
                }
            }
        }
        if (!v.isDense()) {
            switch(op.getOpType()) {
                case INTERSECTION:
                    break;
                case UNION:
                    break;
                case 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(data[i * n + j], 0);
                            }
                        }
                    }
            }
        }
        return new BlasDoubleMatrix(mat.getMatrixId(), mat.getClock(), m, n, newData);
    }
}
Also used : BlasDoubleMatrix(com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 14 with IntIntVector

use of com.tencent.angel.ml.math2.vector.IntIntVector in project angel by Tencent.

the class VectorUtils method emptyLike.

private static ComponentVector emptyLike(ComponentVector v) {
    ComponentVector result;
    if (v instanceof CompIntDoubleVector) {
        IntDoubleVector[] parts = new IntDoubleVector[v.getNumPartitions()];
        IntDoubleVector[] refParts = ((CompIntDoubleVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (IntDoubleVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompIntDoubleVector(((CompIntDoubleVector) v).getMatrixId(), ((CompIntDoubleVector) v).getRowId(), ((CompIntDoubleVector) v).getClock(), ((CompIntDoubleVector) v).getDim(), parts, ((CompIntDoubleVector) v).getSubDim());
    } else if (v instanceof CompIntFloatVector) {
        IntFloatVector[] parts = new IntFloatVector[v.getNumPartitions()];
        IntFloatVector[] refParts = ((CompIntFloatVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (IntFloatVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompIntFloatVector(((CompIntFloatVector) v).getMatrixId(), ((CompIntFloatVector) v).getRowId(), ((CompIntFloatVector) v).getClock(), ((CompIntFloatVector) v).getDim(), parts, ((CompIntFloatVector) v).getSubDim());
    } else if (v instanceof CompIntLongVector) {
        IntLongVector[] parts = new IntLongVector[v.getNumPartitions()];
        IntLongVector[] refParts = ((CompIntLongVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (IntLongVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompIntLongVector(((CompIntLongVector) v).getMatrixId(), ((CompIntLongVector) v).getRowId(), ((CompIntLongVector) v).getClock(), ((CompIntLongVector) v).getDim(), parts, ((CompIntLongVector) v).getSubDim());
    } else if (v instanceof CompIntIntVector) {
        IntIntVector[] parts = new IntIntVector[v.getNumPartitions()];
        IntIntVector[] refParts = ((CompIntIntVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (IntIntVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompIntIntVector(((CompIntIntVector) v).getMatrixId(), ((CompIntIntVector) v).getRowId(), ((CompIntIntVector) v).getClock(), ((CompIntIntVector) v).getDim(), parts, ((CompIntIntVector) v).getSubDim());
    } else if (v instanceof CompLongDoubleVector) {
        LongDoubleVector[] parts = new LongDoubleVector[v.getNumPartitions()];
        LongDoubleVector[] refParts = ((CompLongDoubleVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (LongDoubleVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompLongDoubleVector(((CompLongDoubleVector) v).getMatrixId(), ((CompLongDoubleVector) v).getRowId(), ((CompLongDoubleVector) v).getClock(), ((CompLongDoubleVector) v).getDim(), parts, ((CompLongDoubleVector) v).getSubDim());
    } else if (v instanceof CompLongFloatVector) {
        LongFloatVector[] parts = new LongFloatVector[v.getNumPartitions()];
        LongFloatVector[] refParts = ((CompLongFloatVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (LongFloatVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompLongFloatVector(((CompLongFloatVector) v).getMatrixId(), ((CompLongFloatVector) v).getRowId(), ((CompLongFloatVector) v).getClock(), ((CompLongFloatVector) v).getDim(), parts, ((CompLongFloatVector) v).getSubDim());
    } else if (v instanceof CompLongLongVector) {
        LongLongVector[] parts = new LongLongVector[v.getNumPartitions()];
        LongLongVector[] refParts = ((CompLongLongVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (LongLongVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompLongLongVector(((CompLongLongVector) v).getMatrixId(), ((CompLongLongVector) v).getRowId(), ((CompLongLongVector) v).getClock(), ((CompLongLongVector) v).getDim(), parts, ((CompLongLongVector) v).getSubDim());
    } else if (v instanceof CompLongIntVector) {
        LongIntVector[] parts = new LongIntVector[v.getNumPartitions()];
        LongIntVector[] refParts = ((CompLongIntVector) v).getPartitions();
        for (int i = 0; i < refParts.length; i++) {
            if (null != refParts[i]) {
                parts[i] = (LongIntVector) emptyLike((SimpleVector) refParts[i]);
            }
        }
        result = new CompLongIntVector(((CompLongIntVector) v).getMatrixId(), ((CompLongIntVector) v).getRowId(), ((CompLongIntVector) v).getClock(), ((CompLongIntVector) v).getDim(), parts, ((CompLongIntVector) v).getSubDim());
    } else {
        throw new AngelException("The operation is not support!");
    }
    return result;
}
Also used : CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) AngelException(com.tencent.angel.exception.AngelException) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) ComponentVector(com.tencent.angel.ml.math2.vector.ComponentVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) CompIntLongVector(com.tencent.angel.ml.math2.vector.CompIntLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) CompIntIntVector(com.tencent.angel.ml.math2.vector.CompIntIntVector) CompLongFloatVector(com.tencent.angel.ml.math2.vector.CompLongFloatVector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) CompIntIntVector(com.tencent.angel.ml.math2.vector.CompIntIntVector) CompIntDoubleVector(com.tencent.angel.ml.math2.vector.CompIntDoubleVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) CompLongFloatVector(com.tencent.angel.ml.math2.vector.CompLongFloatVector) CompLongDoubleVector(com.tencent.angel.ml.math2.vector.CompLongDoubleVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) CompLongIntVector(com.tencent.angel.ml.math2.vector.CompLongIntVector) SimpleVector(com.tencent.angel.ml.math2.vector.SimpleVector) CompIntDoubleVector(com.tencent.angel.ml.math2.vector.CompIntDoubleVector)

Example 15 with IntIntVector

use of com.tencent.angel.ml.math2.vector.IntIntVector in project angel by Tencent.

the class SnapshotFormat method save.

private void save(ServerIntIntRow row, PSMatrixSaveContext saveContext, MatrixPartitionMeta meta, DataOutputStream out) throws IOException {
    int startCol = (int) meta.getStartCol();
    IntIntVector vector = ServerRowUtils.getVector(row);
    if (vector.isDense()) {
        int[] data = vector.getStorage().getValues();
        for (int i = 0; i < data.length; i++) {
            out.writeInt(data[i]);
        }
    } else if (vector.isSorted()) {
        int[] indices = vector.getStorage().getIndices();
        int[] values = vector.getStorage().getValues();
        for (int i = 0; i < indices.length; i++) {
            out.writeInt(indices[i] + startCol);
            out.writeInt(values[i]);
        }
    } else {
        ObjectIterator<Int2IntMap.Entry> iter = vector.getStorage().entryIterator();
        Int2IntMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            out.writeInt(entry.getIntKey() + startCol);
            out.writeInt(entry.getIntValue());
        }
    }
}
Also used : IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Aggregations

ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)55 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)50 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)44 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)43 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)33 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)33 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)33 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)30 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)30 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)30 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)25 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)23 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)21 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)21 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)21 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)20