m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6 KiB

6 months ago
  1. from sympy.matrices.expressions import MatrixSymbol, MatAdd, MatPow, MatMul
  2. from sympy.matrices.expressions.special import GenericZeroMatrix, ZeroMatrix
  3. from sympy.matrices import eye, ImmutableMatrix
  4. from sympy.core import Add, Basic, S
  5. from sympy.core.add import add
  6. from sympy.testing.pytest import XFAIL, raises
  7. X = MatrixSymbol('X', 2, 2)
  8. Y = MatrixSymbol('Y', 2, 2)
  9. def test_evaluate():
  10. assert MatAdd(X, X, evaluate=True) == add(X, X, evaluate=True) == MatAdd(X, X).doit()
  11. def test_sort_key():
  12. assert MatAdd(Y, X).doit().args == add(Y, X).doit().args == (X, Y)
  13. def test_matadd_sympify():
  14. assert isinstance(MatAdd(eye(1), eye(1)).args[0], Basic)
  15. assert isinstance(add(eye(1), eye(1)).args[0], Basic)
  16. def test_matadd_of_matrices():
  17. assert MatAdd(eye(2), 4*eye(2), eye(2)).doit() == ImmutableMatrix(6*eye(2))
  18. assert add(eye(2), 4*eye(2), eye(2)).doit() == ImmutableMatrix(6*eye(2))
  19. def test_doit_args():
  20. A = ImmutableMatrix([[1, 2], [3, 4]])
  21. B = ImmutableMatrix([[2, 3], [4, 5]])
  22. assert MatAdd(A, MatPow(B, 2)).doit() == A + B**2
  23. assert MatAdd(A, MatMul(A, B)).doit() == A + A*B
  24. assert (MatAdd(A, X, MatMul(A, B), Y, MatAdd(2*A, B)).doit() ==
  25. add(A, X, MatMul(A, B), Y, add(2*A, B)).doit() ==
  26. MatAdd(3*A + A*B + B, X, Y))
  27. def test_generic_identity():
  28. assert MatAdd.identity == GenericZeroMatrix()
  29. assert MatAdd.identity != S.Zero
  30. def test_zero_matrix_add():
  31. assert Add(ZeroMatrix(2, 2), ZeroMatrix(2, 2)) == ZeroMatrix(2, 2)
  32. @XFAIL
  33. def test_matrix_Add_with_scalar():
  34. raises(TypeError, lambda: Add(0, ZeroMatrix(2, 2)))