dfm.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. sympy.polys.matrices.dfm
  3. Provides the :class:`DFM` class if ``GROUND_TYPES=flint'``. Otherwise, ``DFM``
  4. is a placeholder class that raises NotImplementedError when instantiated.
  5. """
  6. from sympy.external.gmpy import GROUND_TYPES
  7. if GROUND_TYPES == "flint": # pragma: no cover
  8. # When python-flint is installed we will try to use it for dense matrices
  9. # if the domain is supported by python-flint.
  10. from ._dfm import DFM
  11. else: # pragma: no cover
  12. # Other code should be able to import this and it should just present as a
  13. # version of DFM that does not support any domains.
  14. class DFM_dummy:
  15. """
  16. Placeholder class for DFM when python-flint is not installed.
  17. """
  18. def __init__(*args, **kwargs):
  19. raise NotImplementedError("DFM requires GROUND_TYPES=flint.")
  20. @classmethod
  21. def _supports_domain(cls, domain):
  22. return False
  23. @classmethod
  24. def _get_flint_func(cls, domain):
  25. raise NotImplementedError("DFM requires GROUND_TYPES=flint.")
  26. # mypy really struggles with this kind of conditional type assignment.
  27. # Maybe there is a better way to annotate this rather than type: ignore.
  28. DFM = DFM_dummy # type: ignore