예제 #1
0
 public void testDenseSparseMmul() {
   int K = 60;
   int N = thousandconstant;
   DenseMatrix A = DenseMatrix.rand(K, N);
   SparseMatrixLil B = SparseMatrixLil.rand(N, K);
   Timer timer = new Timer();
   DenseMatrix C = A.mmul(B);
   timer.printTimeCheckMilliseconds();
   DenseMatrix C2 = A.mmul(B.toDense());
   assertTrue(C.equals(C2));
 }
예제 #2
0
 public void testMultBasic() {
   DenseMatrix A = new DenseMatrix(new double[][] {{3, 4}, {5, 6}, {3, 9}});
   DenseMatrix B = new DenseMatrix(new double[][] {{2, 9, 1, 2}, {4, 1, 3, 2}});
   DenseMatrix C = A.mmul(B);
   System.out.println(C);
   DenseMatrix Ccorrect =
       new DenseMatrix(new double[][] {{22, 31, 15, 14}, {34, 51, 23, 22}, {42, 36, 30, 24}});
   assertTrue(C.equals(Ccorrect));
 }
예제 #3
0
 public void testldltsolve() {
   int K = thousandconstant;
   DenseMatrix A_ = rand(K, K);
   DenseMatrix A = A_.t().mmul(A_);
   DenseMatrix B = rand(K, K);
   Timer timer = new Timer();
   DenseMatrix X = A.ldltSolve(B);
   timer.printTimeCheckMilliseconds();
   assertTrue(A.mmul(X).equals(B));
 }
예제 #4
0
 public void testfullpivhouseholderqrsolve() {
   int K = thousandconstant;
   DenseMatrix A = rand(K, K / 2);
   DenseMatrix B = rand(K, K / 3);
   Timer timer = new Timer();
   DenseMatrix X = A.fullPivHouseholderQRSolve(B);
   timer.printTimeCheckMilliseconds();
   DenseMatrix AX = A.mmul(X);
   double diff = AX.sub(B).abs().sum().s();
   assertTrue(diff < 0.01 * K * K / 3);
 }
예제 #5
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));
 }