Search in sources :

Example 11 with SparseDoubleVector

use of com.tencent.angel.ml.math.vector.SparseDoubleVector in project angel by Tencent.

the class DenseDoubleMatrixTest method plusBy3.

@Test
public void plusBy3() throws Exception {
    double[][] value = { { 1.0, 2.0 }, { 3.0, 4.0 } };
    DenseDoubleMatrix mat = new DenseDoubleMatrix(2, 2, value);
    SparseDoubleVector vec = new SparseDoubleVector(2);
    vec.setRowId(0);
    vec.set(0, 1.0);
    SparseDoubleVector vec_1 = new SparseDoubleVector(2);
    vec_1.setRowId(1);
    vec_1.set(1, 1.0);
    mat.plusBy(vec);
    mat.plusBy(vec_1);
    assertEquals(2.0, mat.get(0, 0));
    assertEquals(2.0, mat.get(0, 1));
    assertEquals(3.0, mat.get(1, 0));
    assertEquals(5.0, mat.get(1, 1));
}
Also used : SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector) Test(org.junit.Test)

Aggregations

SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)11 Test (org.junit.Test)7 AngelException (com.tencent.angel.exception.AngelException)3 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)3 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)3 IndexGetFunc (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc)2 IndexGetParam (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam)2 TVector (com.tencent.angel.ml.math.TVector)1 SparseDummyVector (com.tencent.angel.ml.math.vector.SparseDummyVector)1 TDoubleVector (com.tencent.angel.ml.math.vector.TDoubleVector)1 Random (java.util.Random)1