Exemple #1
0
 public void testElements() {
   DenseMatrix A = rand(5, 8);
   DenseMatrix B = rand(5, 8);
   assertTrue(zeros(5, 8).equals(A.sub(A)));
   assertTrue(A.equals(A.add(A).div(2)));
   assertTrue(ones(5, 8).equals(A.div(A)));
   assertTrue(A.equals(A.mul(A).div(A)));
   assertTrue(A.neg().abs().equals(A));
   assertTrue(A.neg().add(A).equals(zeros(5, 8)));
 }
Exemple #2
0
 public void testSlice() {
   DenseMatrix A = rand(5, 8);
   DenseMatrix B = rand(5, 12);
   DenseMatrix C = rand(4, 8);
   DenseMatrix AB = A.concatRight(B);
   assertTrue(A.equals(AB.cols(0, 8)));
   assertTrue(B.equals(AB.cols(8, 20)));
   DenseMatrix AC = A.concatDown(C);
   assertTrue(A.equals(AC.rows(0, 5)));
   assertTrue(C.equals(AC.rows(5, 9)));
 }
Exemple #3
0
 public void testTranspose() {
   DenseMatrix A = rand(5, 8);
   DenseMatrix At = A.t();
   assertEquals(5, At.cols);
   assertEquals(8, At.rows);
   assertTrue(A.equals(At.t()));
   SparseMatrixLil B = A.toSparseLil();
   SparseMatrixLil Bt = B.t();
   assertEquals(5, Bt.cols);
   assertEquals(8, Bt.rows);
   assertTrue(At.equals(Bt));
   assertTrue(A.equals(Bt.t()));
 }
Exemple #4
0
 public void testColsIndexeddense() {
   DenseMatrix A = new DenseMatrix("1 5 3; 2 8 5; 1 9 4; 2 5 3").t();
   DenseMatrix indexes = new DenseMatrix("2; 1; 1");
   DenseMatrix B = A.cols(indexes);
   System.out.println(B);
   assertTrue(B.equals(new DenseMatrix("1 9 4; 2 8 5; 2 8 5").t()));
 }
Exemple #5
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));
 }
Exemple #6
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));
 }
Exemple #7
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 #8
0
 public void testminovercols() {
   DenseMatrix A = new DenseMatrix("1 5 3; 2 8 5; 1 9 4; 2 5 3");
   DenseMatrix B = A.minOverCols();
   assertTrue(B.equals(new DenseMatrix("1; 2; 1; 2")));
 }
Exemple #9
0
 public void testmaxovercols() {
   DenseMatrix A = new DenseMatrix("1 5 3; 2 8 5; 1 9 4; 2 5 3");
   DenseMatrix B = A.maxOverCols();
   assertTrue(B.equals(new DenseMatrix("5; 8; 9; 5")));
 }
Exemple #10
0
 public void testmaxoverrows() {
   DenseMatrix A = new DenseMatrix("1 5 3; 2 8 5; 1 9 4; 2 5 3");
   DenseMatrix B = A.maxOverRows();
   assertTrue(B.equals(new DenseMatrix("2 9 5")));
 }
Exemple #11
0
 public void testnonzerocols() {
   DenseMatrix A = new DenseMatrix("1 2 0 3 5 0");
   DenseMatrix B = A.nonZeroCols();
   assertTrue(B.equals(new DenseMatrix("0; 1; 3; 4")));
 }
Exemple #12
0
 public void testnonzerorows() {
   DenseMatrix A = new DenseMatrix("1; 2; 0; 3; 5; 0");
   DenseMatrix B = A.nonZeroRows();
   assertTrue(B.equals(new DenseMatrix("0; 1; 3; 4")));
 }
Exemple #13
0
 public void testToSparse() {
   DenseMatrix A = rand(5, 8);
   assertTrue(A.equals(A.toSparseLil().toDense()));
 }