def test_simplify_kron(self): A = pybamm.Matrix(np.eye(2)) b = pybamm.Vector(np.array([[4], [5]])) kron = pybamm.Kron(A, b) kron_simp = kron.simplify() self.assertIsInstance(kron_simp, pybamm.Matrix) np.testing.assert_array_equal(kron_simp.evaluate().toarray(), np.kron(A.entries, b.entries))
def _jac(self, variable): """ See :meth:`pybamm.Symbol._jac()`. """ # right cannot be a StateVector, so no need for product rule left, right = self.orphans if left.evaluates_to_number(): # Return zeros of correct size return pybamm.Matrix( csr_matrix((self.size, variable.evaluation_array.count(True)))) else: return pybamm.Kron(left.jac(variable), right)
def _outer_jac(self, left_jac, right_jac, variable): """ Calculate jacobian of outer product. See :meth:`pybamm.Jacobian._jac()`. """ # right cannot be a StateVector, so no need for product rule left, right = self.orphans if left.evaluates_to_number(): # Return zeros of correct size return pybamm.Matrix( csr_matrix((self.size, variable.evaluation_array.count(True)))) else: return pybamm.Kron(left_jac, right)
def test_kron(self): # Kron class A = pybamm.Matrix(np.eye(2)) b = pybamm.Vector(np.array([[4], [5]])) kron = pybamm.Kron(A, b) np.testing.assert_array_equal(kron.evaluate().toarray(), np.kron(A.entries, b.entries)) # failures with self.assertRaises(NotImplementedError): kron.diff(None) with self.assertRaises(NotImplementedError): kron.jac(None)
def _binary_simplify(self, left, right): """ See :meth:`pybamm.BinaryOperator.simplify()`. """ return pybamm.Kron(left, right)