Skip to content

perf: defer scipy imports to reduce import time#259

Merged
Jammy2211 merged 2 commits intomainfrom
feature/lazy-imports
Apr 7, 2026
Merged

perf: defer scipy imports to reduce import time#259
Jammy2211 merged 2 commits intomainfrom
feature/lazy-imports

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Defer all scipy imports from module level to local function scope across convolver, delaunay interpolator, mask utilities, cholesky, and fnnls modules. This avoids loading scipy during import autoarray, reducing the import floor for downstream packages.

Part of PyAutoLabs/PyAutoLens#426.

API Changes

None — internal changes only.

Test Plan

  • pytest test_autoarray/ -x — 722 passed
  • Smoke tests via downstream /smoke-test
Full API Changes (for automation & release notes)

No public API changes. All modifications are internal import reorganization:

  • autoarray/operators/convolver.pyimport scipy moved into ConvolverState.__init__
  • autoarray/inversion/mesh/interpolator/delaunay.pyscipy.spatial imports moved into functions
  • autoarray/mask/mask_2d_util.pyscipy.ndimage.binary_dilation moved into function
  • autoarray/util/cholesky_funcs.pyscipy.linalg moved into functions
  • autoarray/util/fnnls.pyscipy.linalg moved into function
  • autoarray/inversion/inversion/inversion_util.pyfnnls_cholesky import moved into function

🤖 Generated with Claude Code

Move scipy imports from module level to local function scope in
convolver, delaunay interpolator, mask utilities, cholesky, and fnnls
modules. This avoids loading scipy during `import autoarray`, cutting
~0.3s from the import floor in smoke tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace all module-level `import matplotlib.pyplot as plt` across plot
files with `subplots()` and `get_cmap()` wrappers from plot/utils that
import matplotlib lazily on first call. This prevents matplotlib from
loading during `import autoarray`, deferring ~0.3s of import cost to
first plot use.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit e1ec21e into main Apr 7, 2026
2 checks passed
@Jammy2211 Jammy2211 deleted the feature/lazy-imports branch April 7, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant