Exemplo n.º 1
0
 public void testOne() {
   DenseMatrix A = ones(3, 3);
   System.out.println(A);
   DenseMatrix B = ones(3, 3);
   System.out.println(B);
   DenseMatrix C = A.mmul(B);
   System.out.println(C);
   assertEquals(3.0, C.get(0, 0));
   assertEquals(3.0, C.get(0, 2));
   assertEquals(3.0, C.get(2, 0));
   assertEquals(3.0, C.get(2, 2));
 }
Exemplo n.º 2
0
  public void testVarOverRows() {
    SparseMatrixLil A = new SparseMatrixLil("1 5 3; 2 8 5");
    DenseMatrix B = meanOverRows(A);
    assertEquals(3, B.cols);
    assertEquals(1, B.rows);
    assertEquals(1.5, B.get(0, 0));
    assertEquals(6.5, B.get(0, 1));

    B = varOverRows(A);
    assertEquals(3, B.cols);
    assertEquals(1, B.rows);
    assertEquals(0.5, B.get(0, 0));
    assertEquals(4.5, B.get(0, 1));
  }
Exemplo n.º 3
0
  public void testVarOverCols() {
    SparseMatrixLil A = new SparseMatrixLil("1 5 3; 2 8 5");
    DenseMatrix B = meanOverCols(A);
    assertEquals(1, B.cols);
    assertEquals(2, B.rows);
    assertEquals(3.0, B.get(0, 0));
    assertEquals(5.0, B.get(1, 0));

    B = varOverCols(A);
    assertEquals(1, B.cols);
    assertEquals(2, B.rows);
    assertEquals(4.0, B.get(0, 0));
    assertEquals(9.0, B.get(1, 0));
  }
Exemplo n.º 4
0
 public void testConstructorByString() {
   DenseMatrix foo = new DenseMatrix("1 3; 5 7; 3 5");
   assertEquals(3, foo.rows);
   assertEquals(2, foo.cols);
   assertTrue(foo.equals(new DenseMatrix(new double[][] {{1, 3}, {5, 7}, {3, 5}})));
   assertEquals(5.0, foo.get(1, 0));
   assertEquals(7.0, foo.get(1, 1));
 }