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.

35 lines
1.2 KiB

6 months ago
  1. from sympy.core.singleton import S
  2. from sympy.core.symbol import symbols
  3. from sympy.matrices import Matrix
  4. from sympy.matrices.expressions.matexpr import MatrixSymbol
  5. from sympy.matrices.expressions.sets import MatrixSet
  6. from sympy.matrices.expressions.special import ZeroMatrix
  7. from sympy.testing.pytest import raises
  8. def test_MatrixSet():
  9. n, m = symbols('n m', integer=True)
  10. A = MatrixSymbol('A', n, m)
  11. C = MatrixSymbol('C', n, n)
  12. M = MatrixSet(2, 2, set=S.Reals)
  13. assert M.shape == (2, 2)
  14. assert M.set == S.Reals
  15. X = Matrix([[1, 2], [3, 4]])
  16. assert X in M
  17. X = ZeroMatrix(2, 2)
  18. assert X in M
  19. raises(TypeError, lambda: A in M)
  20. raises(TypeError, lambda: 1 in M)
  21. M = MatrixSet(n, m, set=S.Reals)
  22. assert A in M
  23. raises(TypeError, lambda: C in M)
  24. raises(TypeError, lambda: X in M)
  25. M = MatrixSet(2, 2, set={1, 2, 3})
  26. X = Matrix([[1, 2], [3, 4]])
  27. Y = Matrix([[1, 2]])
  28. assert (X in M) == S.false
  29. assert (Y in M) == S.false
  30. raises(ValueError, lambda: MatrixSet(2, -2, S.Reals))
  31. raises(ValueError, lambda: MatrixSet(2.4, -1, S.Reals))
  32. raises(TypeError, lambda: MatrixSet(2, 2, (1, 2, 3)))