Search in sources :

Example 26 with IntDoubleSparseVectorStorage

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

the class UpdatePSFTest method testSparseDoubleUDF.

public void testSparseDoubleUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    // genIndexs(feaNum, nnz);
    int[] index = new int[feaNum];
    for (int i = 0; i < index.length; i++) {
        index[i] = i;
    }
    IntDoubleVector deltaVec = new IntDoubleVector(feaNum, new IntDoubleSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < index.length; i++) {
        deltaVec.set(index[i], index[i]);
    }
    // for (int i = 0; i < feaNum; i++) {
    // deltaVec.set(i, i);
    // }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    IntDoubleVector row = (IntDoubleVector) client1.getRow(0);
    for (int id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        Assert.assertEquals(row.get(id), deltaVec.get(id), 0);
    }
    Assert.assertTrue(index.length == row.size());
}
Also used : IntDoubleSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage) IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 27 with IntDoubleSparseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage 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 28 with IntDoubleSparseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage 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 29 with IntDoubleSparseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage 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 30 with IntDoubleSparseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage 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)

Aggregations

IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)33 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)30 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)23 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)23 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)21 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)20 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)20 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)20 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)20 IntLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSparseVectorStorage)20 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)20 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)20 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)20 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)20 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)20 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)20 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)20