Exemple #1
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));
 }
Exemple #2
0
  public void testThreeSparse() {
    int K = 60;
    int N = thousandconstant;
    SparseMatrixLil A = SparseMatrixLil.rand(N, K);
    SparseMatrixLil B = SparseMatrixLil.rand(K, N);
    //		System.out.println(A.toDense());
    Timer timer = new Timer();
    SparseMatrixLil C = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    SparseMatrixLil C1 = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    SparseMatrixLil C2 = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    DenseMatrix CDense = B.toDense().mmul(A.toDense());
    timer.printTimeCheckMilliseconds("for dense");
    assertTrue(C.equals(CDense));

    K = 400;
    N = thousandconstant;
    A = SparseMatrixLil.rand(N, K);
    B = SparseMatrixLil.rand(K, N);
    //		System.out.println(A.toDense());
    timer = new Timer();
    C = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    C1 = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    C2 = B.mmul(A);
    timer.printTimeCheckMilliseconds();
    CDense = B.toDense().mmul(A.toDense());
    timer.printTimeCheckMilliseconds("for dense");
    assertTrue(C.equals(CDense));
  }
Exemple #3
0
 public void testSparseDenseMmul() {
   int K = 60;
   int N = thousandconstant;
   SparseMatrixLil A = SparseMatrixLil.rand(K, N);
   DenseMatrix B = DenseMatrix.rand(N, K);
   Timer timer = new Timer();
   DenseMatrix C = A.mmul(B);
   timer.printTimeCheckMilliseconds();
   DenseMatrix C2 = A.toDense().mmul(B);
   assertTrue(C.equals(C2));
 }
Exemple #4
0
 public void testSvd() {
   DenseMatrix A = rand(5, 8);
   SvdResult result = A.svd();
   assertEquals(A, result.U.mmul(diag(result.S)).mmul(result.V.t()));
   Timer timer = new Timer();
   A = rand(500, thousandconstant);
   timer.printTimeCheckMilliseconds();
   result = A.svd();
   timer.printTimeCheckMilliseconds();
   assertEquals(A, result.U.mmul(diag(result.S)).mmul(result.V.t()));
 }
Exemple #5
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);
 }
Exemple #6
0
  public void testSortBigMatrixFast() { // you will need to add option -Xmx1400m to run this
    System.out.println("testSortBigMatrixFast");
    SparseMatrixLil B = spzeros(2, 2);

    SparseMatrixLil A = sprand(1000, largematrixsize);
    System.out.println("created A");
    B = A.add(0); // make copy
    System.out.println("created B");
    //		System.out.println(B);
    B.sortFast();
    for (int i = 0; i < B.size; i++) {
      if (i > 0) {
        assertTrue(B.colIdx[i] >= B.colIdx[i - 1]);
        if (B.colIdx[i] == B.colIdx[i - 1]) {
          assertTrue(B.rowIdx[i] >= B.rowIdx[i - 1]);
        }
      }
      assertEquals(A.rowIdx[i], B.rowIdx[i]);
      assertEquals(A.colIdx[i], B.colIdx[i]);
      assertEquals(A.values[i], B.values[i]);
    }
    System.out.println("sorted B");
    //		assertTrue( A.equals(B));
    //		System.out.println("asserted equals");
    //		System.out.println(B);
    B = null;
    SparseMatrixLil Bt = A.t(); // t() is also a copy
    System.out.println("transposed A");
    //		System.out.println(Bt);
    Timer timer = new Timer();
    Bt.sortFast();
    timer.printTimeCheckMilliseconds();
    System.out.println("sorted Bt");
    for (int i = 0; i < Bt.size; i++) {
      if (i > 0) {
        assertTrue(Bt.colIdx[i] >= Bt.colIdx[i - 1]);
        if (Bt.colIdx[i] == Bt.colIdx[i - 1]) {
          assertTrue(Bt.rowIdx[i] >= Bt.rowIdx[i - 1]);
        }
      }
    }
    //		System.out.println(Bt);
    assertTrue(A.toDense().t().equals(Bt));
    System.out.println("checed equal to At");
  }