test_factorizations.py 786 B

1234567891011121314151617181920212223242526272829
  1. from sympy.matrices.expressions.factorizations import lu, LofCholesky, qr, svd
  2. from sympy.assumptions.ask import (Q, ask)
  3. from sympy.core.symbol import Symbol
  4. from sympy.matrices.expressions.matexpr import MatrixSymbol
  5. n = Symbol('n')
  6. X = MatrixSymbol('X', n, n)
  7. def test_LU():
  8. L, U = lu(X)
  9. assert L.shape == U.shape == X.shape
  10. assert ask(Q.lower_triangular(L))
  11. assert ask(Q.upper_triangular(U))
  12. def test_Cholesky():
  13. LofCholesky(X)
  14. def test_QR():
  15. Q_, R = qr(X)
  16. assert Q_.shape == R.shape == X.shape
  17. assert ask(Q.orthogonal(Q_))
  18. assert ask(Q.upper_triangular(R))
  19. def test_svd():
  20. U, S, V = svd(X)
  21. assert U.shape == S.shape == V.shape == X.shape
  22. assert ask(Q.orthogonal(U))
  23. assert ask(Q.orthogonal(V))
  24. assert ask(Q.diagonal(S))