Exemplo n.º 1
0
 def test_jacobian(self):
     a = w.Symbol('a')
     b = w.Symbol('b')
     m = w.Matrix([a + b, a**2, b**2])
     jac = w.jacobian(m, [a, b])
     expected = w.Matrix([[1, 1], [2 * a, 0], [0, 2 * b]])
     for i in range(expected.shape[0]):
         for j in range(expected.shape[1]):
             assert w.equivalent(jac[i, j], expected[i, j])
Exemplo n.º 2
0
 def test_matrix(self, x_dim):
     data = list(range(x_dim))
     m = w.Matrix(data)
     self.assertEqual(m[0], 0)
     self.assertEqual(m[-1], x_dim - 1)
Exemplo n.º 3
0
 def test_is_matrix(self):
     self.assertFalse(w.is_matrix(w.Symbol('a')))
     self.assertTrue(w.is_matrix(w.Matrix([[0, 0]])))
Exemplo n.º 4
0
 def test_matrix3(self, x_dim, y_dim):
     data = [[(i) + (j * x_dim) for j in range(y_dim)]
             for i in range(x_dim)]
     m = w.Matrix(data)
     self.assertEqual(float(m[0, 0]), 0)
     self.assertEqual(float(m[x_dim - 1, y_dim - 1]), (x_dim * y_dim) - 1)