compat.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. """Compatibility helpers for dependencies."""
  2. from packaging.version import parse
  3. import numpy as np
  4. import scipy as sp
  5. __all__ = [
  6. "NP_COPY_IF_NEEDED",
  7. "SCIPY_CG_TOL_PARAM_NAME",
  8. ]
  9. NUMPY_LT_2_0_0 = parse(np.__version__) < parse('2.0.0.dev0')
  10. # With NumPy 2.0.0, `copy=False` now raises a ValueError if the copy cannot be
  11. # made. The previous behavior to only copy if needed is provided with `copy=None`.
  12. # During the transition period, use this symbol instead.
  13. # Remove once NumPy 2.0.0 is the minimal required version.
  14. # https://numpy.org/devdocs/release/2.0.0-notes.html#new-copy-keyword-meaning-for-array-and-asarray-constructors
  15. # https://github.com/numpy/numpy/pull/25168
  16. NP_COPY_IF_NEEDED = False if NUMPY_LT_2_0_0 else None
  17. SCIPY_LT_1_12 = parse(sp.__version__) < parse('1.12')
  18. # Starting in SciPy v1.12, 'scipy.sparse.linalg.cg' keyword argument `tol` is
  19. # deprecated in favor of `rtol`.
  20. SCIPY_CG_TOL_PARAM_NAME = "tol" if SCIPY_LT_1_12 else "rtol"
  21. SCIPY_GE_1_17_0_DEV0 = parse('1.17.0.dev0') <= parse(sp.__version__)