Skip to content

Do not import JAX at module import time (v3.2.1) (#21)

Choose a tag to compare

@github-actions github-actions released this 01 Jul 22:03
· 6 commits to main since this release
bd1ffb4
`import cvmatrix` previously imported JAX whenever JAX was installed, because
the module-level array/scalar type aliases (`Array`, `Scalar`, `FloatDType`,
`_TRACER_TYPES`) were built from `jax` at import time. This made downstream
packages that only use the NumPy backend pay the JAX import cost.

- Defer annotations with `from __future__ import annotations` (keeping them as
  strings) and keep the aliases NumPy-only at import; `FloatDType` uses
  `npt.DTypeLike` (which already admits JAX scalar dtypes without importing JAX).
- Broaden `Array`/`Scalar`/`_TRACER_TYPES` in-place to admit `jax.Array` via a
  new `_enable_jax_typing()`, called only when the JAX backend is resolved. With
  string annotations, typeguard resolves them against the broadened aliases at
  call time, so `backend="jax"` values still pass runtime type checks.
- JAX is now imported lazily only for `backend="jax"`; `import cvmatrix` stays
  JAX-free even when JAX is installed.

The NumPy and JAX backends are behavior- and result-identical to 3.2.0 (numpy
byte-identical), verified by the existing suite under typeguard for both backends.