Beispiel #1
0
 def test_dot_sparsemat_advec(self):
     x, y = initVariablesADI(np.array([[4,2]]).T, np.array([[2,3]]).T)
     C = sps.csc_matrix(np.array([[2,0],[1,1]]))
     Cx = npad.dot(C, x)
     assert np.array_equal(Cx.val, np.array([[8],[6]]))
     assert np.array_equal(Cx.jac[0].toarray(), np.array([[2,0],[1,1]]))
     assert np.array_equal(Cx.jac[1].toarray(), np.array([[0,0],[0,0]]))
Beispiel #2
0
 def test_dot_ad_ad(self):
     x, y = initVariablesADI(np.array([[4]]).T, np.array([[2]]).T)
     z = x+y
     w = npad.dot(z, x)
     assert isinstance(w, ADI)
     assert np.array_equal(w.val, np.array([[24]]).T)
     assert np.array_equal(w.jac[0].toarray(), np.array([[10]]))
     assert np.array_equal(w.jac[1].toarray(), np.array([[4]]))
Beispiel #3
0
 def test_dot_mat_ad(self):
     x, y = initVariablesADI(np.array([[4,2]]).T, np.array([[2,3]]).T)
     z = x*y #[8; 6] with jac[0] = diag(2,3), jac[1] = diag(4,2)
     A = np.array([[1, 2], [3, 4]])
     w = npad.dot(A, z)
     assert isinstance(w, ADI)
     assert np.array_equal(w.val, np.array([[20, 48]]).T)
     assert np.array_equal(w.jac[0].toarray(), np.array([[2, 6], [6, 12]]))
     assert np.array_equal(w.jac[1].toarray(), np.array([[4, 4], [12, 8]]))
Beispiel #4
0
 def test_dot_mat_vec(self):
     x, y = np.array([[4,2]]).T, np.array([[2,3]])
     w = npad.dot(x, y)
     assert isinstance(w, np.ndarray)
     assert np.array_equal(w, np.array([[8, 12], [4, 6]]))
Beispiel #5
0
 def test_dot_sparsemat_vec(self):
     C = sps.csc_matrix(np.array([[2,0],[1,1]]))
     x = np.array([[1], [2]])
     Cx = npad.dot(C, x)
     assert np.array_equal(Cx, np.array([[2], [3]]))