def test_doit_args(): A = ImmutableMatrix([[1, 2], [3, 4]]) B = ImmutableMatrix([[2, 3], [4, 5]]) assert MatAdd(A, MatPow(B, 2)).doit() == A + B**2 assert MatAdd(A, MatMul(A, B)).doit() == A + A * B assert (MatAdd(A, X, MatMul(A, B), Y, MatAdd(2 * A, B)).doit() == add( A, X, MatMul(A, B), Y, add(2 * A, B)).doit() == MatAdd( 3 * A + A * B + B, X, Y))
def test_add_dispatcher(): class NewBase(Expr): @property def _add_handler(self): return NewAdd class NewAdd(NewBase, Add): pass add.register_handlerclass((Add, NewAdd), NewAdd) a, b = Symbol('a'), NewBase() # Add called as fallback assert add(1, 2) == Add(1, 2) assert add(a, a) == Add(a, a) # selection by registered priority assert add(a, b, a) == NewAdd(2 * a, b)
def test_matadd_of_matrices(): assert MatAdd(eye(2), 4 * eye(2), eye(2)).doit() == ImmutableMatrix(6 * eye(2)) assert add(eye(2), 4 * eye(2), eye(2)).doit() == ImmutableMatrix(6 * eye(2))
def test_matadd_sympify(): assert isinstance(MatAdd(eye(1), eye(1)).args[0], Basic) assert isinstance(add(eye(1), eye(1)).args[0], Basic)
def test_sort_key(): assert MatAdd(Y, X).doit().args == add(Y, X).doit().args == (X, Y)
def test_evaluate(): assert MatAdd(X, X, evaluate=True) == add(X, X, evaluate=True) == MatAdd( X, X).doit()