Search in sources :

Example 6 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class CompIntDoubleRowUpdateSplit method serialize.

@Override
public void serialize(ByteBuf buf) {
    super.serialize(buf);
    IntDoubleVectorStorage storage = split.getStorage();
    if (storage instanceof IntDoubleSparseVectorStorage) {
        buf.writeInt(storage.size());
        ObjectIterator<Int2DoubleMap.Entry> iter = storage.entryIterator();
        Int2DoubleMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            buf.writeInt(entry.getIntKey());
            buf.writeDouble(entry.getDoubleValue());
        }
    } else if (storage instanceof IntDoubleSortedVectorStorage) {
        buf.writeInt(storage.size());
        int[] indices = storage.getIndices();
        double[] values = storage.getValues();
        for (int i = 0; i < indices.length; i++) {
            buf.writeInt(indices[i]);
            buf.writeDouble(values[i]);
        }
    } else if (storage instanceof IntDoubleDenseVectorStorage) {
        double[] values = storage.getValues();
        int writeSize = values.length < maxItemNum ? values.length : maxItemNum;
        buf.writeInt(writeSize);
        for (int i = 0; i < writeSize; i++) {
            buf.writeDouble(values[i]);
        }
    } else {
        throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
    }
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) Int2DoubleMap(it.unimi.dsi.fastutil.ints.Int2DoubleMap) IntDoubleSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)

Example 7 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class BlasDoubleMatrix method getRow.

@Override
public Vector getRow(int i) {
    double[] row = new double[numCols];
    System.arraycopy(data, i * numCols, row, 0, numCols);
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(row);
    return new IntDoubleVector(getMatrixId(), i, getClock(), numCols, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 8 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class BlasDoubleMatrix method getCol.

@Override
public Vector getCol(int j) {
    double[] col = new double[numRows];
    for (int i = 0; i < numRows; i++) {
        col[i] = data[i * numCols + j];
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(col);
    return new IntDoubleVector(getMatrixId(), 0, getClock(), numRows, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 9 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class BlasDoubleMatrix method diag.

@Override
public Vector diag() {
    int numDiag = Math.min(numRows, numCols);
    double[] resArr = new double[numDiag];
    for (int i = 0; i < numDiag; i++) {
        resArr[i] = data[i * numRows + i];
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(getMatrixId(), 0, getClock(), resArr.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 10 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class DotMatrixExecutor method apply.

private static Vector apply(BlasDoubleMatrix mat, boolean trans, IntIntVector v) {
    int m = mat.getNumRows(), n = mat.getNumCols();
    double[] resArr;
    if (trans) {
        assert m == v.getDim();
        resArr = new double[n];
    } else {
        assert n == v.getDim();
        resArr = new double[m];
    }
    int r = mat.getNumRows(), c = mat.getNumCols();
    double[] data = mat.getData();
    if (v.isDense()) {
        double[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new double[v.getDim()]);
        if (trans) {
            blas.dgemv("N", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        } else {
            blas.dgemv("T", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        }
    } else if (v.isSparse()) {
        if (trans) {
            for (int j = 0; j < c; j++) {
                ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2IntMap.Entry entry = iter.next();
                    int i = entry.getIntKey();
                    resArr[j] += data[i * c + j] * entry.getIntValue();
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                ObjectIterator<Int2IntMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2IntMap.Entry entry = iter.next();
                    int j = entry.getIntKey();
                    resArr[i] += data[i * c + j] * entry.getIntValue();
                }
            }
        }
    } else {
        // sorted
        if (trans) {
            for (int j = 0; j < r; j++) {
                int[] idxs = v.getStorage().getIndices();
                int[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[j] += data[idxs[k] * c + j] * vals[k];
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                int[] idxs = v.getStorage().getIndices();
                int[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[i] += data[i * c + idxs[k]] * vals[k];
                }
            }
        }
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Aggregations

IntDoubleDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage)24 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)21 PSModel (com.tencent.angel.ml.model.PSModel)4 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)4 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)3 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)3 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)3 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)2 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)2 Worker (com.tencent.angel.worker.Worker)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AngelException (com.tencent.angel.exception.AngelException)1 AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)1 AMTask (com.tencent.angel.master.task.AMTask)1 AMTaskManager (com.tencent.angel.master.task.AMTaskManager)1 SplitEntry (com.tencent.angel.ml.GBDT.algo.tree.SplitEntry)1 GBDTGradHistGetRowFunc (com.tencent.angel.ml.GBDT.psf.GBDTGradHistGetRowFunc)1 HistAggrParam (com.tencent.angel.ml.GBDT.psf.HistAggrParam)1