test_adjoint.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. from sympy.core import symbols, S
  2. from sympy.functions import adjoint, conjugate, transpose
  3. from sympy.matrices.expressions import MatrixSymbol, Adjoint, trace, Transpose
  4. from sympy.matrices import eye, Matrix
  5. n, m, l, k, p = symbols('n m l k p', integer=True)
  6. A = MatrixSymbol('A', n, m)
  7. B = MatrixSymbol('B', m, l)
  8. C = MatrixSymbol('C', n, n)
  9. def test_adjoint():
  10. Sq = MatrixSymbol('Sq', n, n)
  11. assert Adjoint(A).shape == (m, n)
  12. assert Adjoint(A*B).shape == (l, n)
  13. assert adjoint(Adjoint(A)) == A
  14. assert isinstance(Adjoint(Adjoint(A)), Adjoint)
  15. assert conjugate(Adjoint(A)) == Transpose(A)
  16. assert transpose(Adjoint(A)) == Adjoint(Transpose(A))
  17. assert Adjoint(eye(3)).doit() == eye(3)
  18. assert Adjoint(S(5)).doit() == S(5)
  19. assert Adjoint(Matrix([[1, 2], [3, 4]])).doit() == Matrix([[1, 3], [2, 4]])
  20. assert adjoint(trace(Sq)) == conjugate(trace(Sq))
  21. assert trace(adjoint(Sq)) == conjugate(trace(Sq))
  22. assert Adjoint(Sq)[0, 1] == conjugate(Sq[1, 0])
  23. assert Adjoint(A*B).doit() == Adjoint(B) * Adjoint(A)