def wrapper(expr, **kwargs): try: result = timeout_exception_simplify(expr, **kwargs) except TimeoutError: result = expr print "simplification stopped for expr.count_ops:" print st.count_ops(expr) return result
def test_count_ops(self): a, b, t = sp.symbols("a, b, t") x1 = a + b x2 = a + b - 3 + sp.pi M1 = sp.Matrix([x2, t, a**2]) M2 = sp.ImmutableDenseMatrix(M1) self.assertEqual(st.count_ops(a), a.co) self.assertEqual(st.count_ops(x1), x1.co) self.assertEqual(st.count_ops(x2), x2.co) self.assertEqual(st.count_ops(M1), M1.co) self.assertEqual(st.count_ops(M2), M2.co)
def count_ops(self, *args, **kwargs): """Utility that returns a form of the same basis and degree as self where the coeffs are numbers corresponding to the application of count_ops to self.coeff. """ coeff_co = st.count_ops(self.coeff, *args, **kwargs) return DifferentialForm(self.degree, self.basis, coeff=coeff_co)
def wrapper(expr, **kwargs): try: result = timeout_exception_simplify(expr, **kwargs) except TimeoutError: result = expr print("simplification stopped for expr.count_ops:") print(st.count_ops(expr)) return result
def test_count_ops2(self): a, b, t = sp.symbols("a, b, t") x1 = a + b x2 = a + b - 3 + sp.pi M1 = sp.Matrix([x2, t, a**2, 0, 1]) M2 = sp.ImmutableDenseMatrix(M1) self.assertEqual(st.count_ops(0), 0) self.assertEqual(st.count_ops(a), 1) self.assertEqual(st.count_ops(1.3), 1) self.assertEqual(st.count_ops(x1), 2) self.assertEqual(st.count_ops(x2), 4) self.assertEqual(st.count_ops(M1), sp.Matrix([4, 1, 2, 0, 1])) self.assertEqual(st.count_ops(M2), sp.Matrix([4, 1, 2, 0, 1]))