Пример #1
0
 public void testCreateSparse() {
   DenseMatrix A = rand(5, 5);
   SparseMatrixLil B = A.toSparseLil();
   assertTrue(B.equals(B.mmul(eye(5))));
   assertTrue(B.equals(B.t().mmul(eye(5)).t()));
   B = spzeros(2, 2);
   B.append(1, 0, 5);
   B.append(0, 1, 7);
   B.append(0, 0, 11);
   System.out.println(B.toDense());
   System.out.println(B.mmul(eye(2)));
   assertTrue(B.equals(B.mmul(eye(2))));
 }
Пример #2
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()));
 }
Пример #3
0
 public void testSum() {
   DenseMatrix A = new DenseMatrix(new double[][] {{1, 9}, {7, 3}});
   assertTrue(new DenseMatrix(new double[][] {{8, 12}}).equals(A.sumOverRows()));
   assertTrue(new DenseMatrix(new double[][] {{10}, {10}}).equals(A.sumOverCols()));
   SparseMatrixLil B = A.toSparseLil();
   assertTrue(new DenseMatrix(new double[][] {{8, 12}}).toSparseLil().equals(B.sumOverRows()));
   assertTrue(new DenseMatrix(new double[][] {{10}, {10}}).toSparseLil().equals(B.sumOverCols()));
   assertTrue(B.sumOverRows().equals(A.sumOverRows()));
   assertTrue(B.sumOverCols().equals(A.sumOverCols()));
   assertEquals(B.sum().sum().s(), A.sum().sum().s());
   SparseMatrixLil C = spzeros(4, 5);
   C.append(1, 2, 5);
   C.append(3, 1, 3);
   C.append(3, 2, 7);
   C.append(1, 4, 11);
   System.out.println(C.sumOverRows());
   assertTrue(new DenseMatrix(new double[][] {{0, 3, 12, 0, 11}}).equals(C.sumOverRows()));
   System.out.println(C.sumOverCols());
   assertTrue(new DenseMatrix(new double[][] {{0}, {16}, {0}, {10}}).equals(C.sumOverCols()));
   assertEquals(26.0, C.sumOverCols().sumOverRows().s());
   assertEquals(26.0, C.sumOverRows().sumOverCols().s());
 }
Пример #4
0
 public void testToSparse() {
   DenseMatrix A = rand(5, 8);
   assertTrue(A.equals(A.toSparseLil().toDense()));
 }