Search in sources :

Example 1 with TIntVector

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

the class DenseIntMatrixTest method plusBy3.

@Test
public void plusBy3() throws Exception {
    int[][] value = { { 1, 2 }, { 3, 4 } };
    DenseIntMatrix mat = new DenseIntMatrix(2, 2, value);
    TIntVector vec = new DenseIntVector(2, new int[] { 1, 2 });
    vec.setRowId(0);
    mat.plusBy(vec);
    assertEquals(2, mat.get(0, 0));
    assertEquals(4, mat.get(0, 1));
    assertEquals(3, mat.get(1, 0));
    assertEquals(4, mat.get(1, 1));
    DenseIntMatrix mat_1 = new DenseIntMatrix(2, 2);
    mat_1.plusBy(vec);
    assertEquals(1, mat_1.get(0, 0));
    assertEquals(2, mat_1.get(0, 1));
    assertEquals(0, mat_1.get(1, 0));
    assertEquals(0, mat_1.get(1, 1));
}
Also used : TIntVector(com.tencent.angel.ml.math.vector.TIntVector) DenseIntVector(com.tencent.angel.ml.math.vector.DenseIntVector) Test(org.junit.Test)

Example 2 with TIntVector

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

the class DenseIntMatrixTest method getTIntVector.

@Test
public void getTIntVector() throws Exception {
    int[][] value = { { 1, 2 }, { 3, 4 } };
    DenseIntMatrix mat = new DenseIntMatrix(2, 2, value);
    TIntVector vec = (TIntVector) mat.getRow(0);
    assertEquals(1, vec.get(0));
    assertEquals(2, vec.get(1));
    DenseIntMatrix mat_1 = new DenseIntMatrix(2, 2);
    mat_1.plusBy(vec);
    TIntVector vec_1 = (TIntVector) mat_1.getRow(1);
    assertEquals(0, vec_1.get(0));
    assertEquals(0, vec_1.get(1));
}
Also used : TIntVector(com.tencent.angel.ml.math.vector.TIntVector) Test(org.junit.Test)

Aggregations

TIntVector (com.tencent.angel.ml.math.vector.TIntVector)2 Test (org.junit.Test)2 DenseIntVector (com.tencent.angel.ml.math.vector.DenseIntVector)1