Search in sources :

Example 91 with IntDoubleVector

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

the class CooIntDoubleMatrix method getRow.

@Override
public Vector getRow(int idx) {
    IntArrayList cols = new IntArrayList();
    DoubleArrayList data = new DoubleArrayList();
    for (int i = 0; i < rowIndices.length; i++) {
        if (rowIndices[i] == idx) {
            cols.add(colIndices[i]);
            data.add(values[i]);
        }
    }
    IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[1], cols.toIntArray(), data.toDoubleArray());
    return new IntDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 92 with IntDoubleVector

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

the class CooIntDoubleMatrix method getCol.

@Override
public Vector getCol(int idx) {
    IntArrayList cols = new IntArrayList();
    DoubleArrayList data = new DoubleArrayList();
    for (int i = 0; i < colIndices.length; i++) {
        if (colIndices[i] == idx) {
            cols.add(rowIndices[i]);
            data.add(values[i]);
        }
    }
    IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[0], cols.toIntArray(), data.toDoubleArray());
    return new IntDoubleVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 93 with IntDoubleVector

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

the class CsrDoubleMatrix method getRow.

@Override
public Vector getRow(int idx) {
    IntArrayList cols = new IntArrayList();
    DoubleArrayList data = new DoubleArrayList();
    int rowNum = indptr.length - 1;
    assert (idx < rowNum);
    for (int i = indptr[idx]; i < indptr[idx + 1]; i++) {
        cols.add(indices[i]);
        data.add(values[i]);
    }
    IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[1], cols.toIntArray(), data.toDoubleArray());
    return new IntDoubleVector(getMatrixId(), idx, getClock(), shape[1], storage);
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 94 with IntDoubleVector

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

the class CsrDoubleMatrix method getCol.

@Override
public Vector getCol(int idx) {
    IntArrayList cols = new IntArrayList();
    DoubleArrayList data = new DoubleArrayList();
    int[] rows = new int[indices.length];
    int i = 0;
    int j = 0;
    while (i < indptr.length - 1 && j < indptr.length - 1) {
        int r = indptr[i + 1] - indptr[i];
        for (int p = j; p < j + r; p++) {
            rows[p] = i;
        }
        if (r != 0) {
            j++;
        }
        i++;
    }
    for (int id = 0; id < indices.length; id++) {
        if (indices[id] == idx) {
            cols.add(rows[id]);
            data.add(values[id]);
        }
    }
    IntDoubleSparseVectorStorage storage = new IntDoubleSparseVectorStorage(shape[0], cols.toIntArray(), data.toDoubleArray());
    return new IntDoubleVector(getMatrixId(), 0, getClock(), shape[0], storage);
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 95 with IntDoubleVector

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

the class RBLongDoubleMatrix method diag.

@Override
public Vector diag() {
    double[] resArr = new double[rows.length];
    for (int i = 0; i < rows.length; i++) {
        if (null == rows[i]) {
            resArr[i] = 0;
        } else {
            resArr[i] = rows[i].get(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)

Aggregations

IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)95 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)55 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)51 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)51 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)40 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)32 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)32 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)32 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 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)26 IntDoubleDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage)23 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20