test_array_derivatives.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from sympy.core.symbol import symbols
  2. from sympy.matrices.dense import Matrix
  3. from sympy.matrices.expressions.matexpr import MatrixSymbol
  4. from sympy.tensor.array.ndim_array import NDimArray
  5. from sympy.matrices.common import MatrixCommon
  6. from sympy.tensor.array.array_derivatives import ArrayDerivative
  7. x, y, z, t = symbols("x y z t")
  8. m = Matrix([[x, y], [z, t]])
  9. M = MatrixSymbol("M", 3, 2)
  10. N = MatrixSymbol("N", 4, 3)
  11. def test_array_derivative_construction():
  12. d = ArrayDerivative(x, m, evaluate=False)
  13. assert d.shape == (2, 2)
  14. expr = d.doit()
  15. assert isinstance(expr, MatrixCommon)
  16. assert expr.shape == (2, 2)
  17. d = ArrayDerivative(m, m, evaluate=False)
  18. assert d.shape == (2, 2, 2, 2)
  19. expr = d.doit()
  20. assert isinstance(expr, NDimArray)
  21. assert expr.shape == (2, 2, 2, 2)
  22. d = ArrayDerivative(m, x, evaluate=False)
  23. assert d.shape == (2, 2)
  24. expr = d.doit()
  25. assert isinstance(expr, MatrixCommon)
  26. assert expr.shape == (2, 2)
  27. d = ArrayDerivative(M, N, evaluate=False)
  28. assert d.shape == (4, 3, 3, 2)
  29. expr = d.doit()
  30. assert isinstance(expr, ArrayDerivative)
  31. assert expr.shape == (4, 3, 3, 2)
  32. d = ArrayDerivative(M, (N, 2), evaluate=False)
  33. assert d.shape == (4, 3, 4, 3, 3, 2)
  34. expr = d.doit()
  35. assert isinstance(expr, ArrayDerivative)
  36. assert expr.shape == (4, 3, 4, 3, 3, 2)
  37. d = ArrayDerivative(M.as_explicit(), (N.as_explicit(), 2), evaluate=False)
  38. assert d.doit().shape == (4, 3, 4, 3, 3, 2)
  39. expr = d.doit()
  40. assert isinstance(expr, ArrayDerivative)
  41. assert expr.shape == (4, 3, 4, 3, 3, 2)