Skip to content

perf: vectorise the over-sampled grid builder; skip the mask-edge overlay under fast plots - #534

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/smoke-test-perf-g8i2uq
Sep 8, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
claude/smoke-test-perf-g8i2uq

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

grid_2d_slim_over_sampled_via_mask_from built every unmasked pixel's sub-pixel block in a Python loop (a linspace, a meshgrid and a stack per pixel). On a 2000x100 CTI frame that is ~180k iterations and ~12s per call, and FitDataset.__init__ forces the dataset's border relocator, which calls it once per fit — four calls, ~50s of the slowest smoke script on the Heart board (autocti_workspace imaging_ci/modeling/start_here.py, 89.5s on its slowest leg), for a relocator a CTI fit never uses.

The offsets for a given sub-size are the same for every pixel, so they are now built once per distinct sub-size and broadcast onto that sub-size's pixel centres; non-uniform sub-sizes keep the pixel-ordered layout through a per-pixel block start (cumsum of block sizes). The output is bit-identical to the loop: the old construction is kept verbatim as the oracle in a new test over random masks, uniform and mixed sub-sizes (including zeros) and a non-zero origin.

plot_array also derived the mask's edge grid on every call for the overlay. With PYAUTO_FAST_PLOTS=1 the figure is closed before it is drawn or saved, so the overlay is never seen; it is now skipped under that flag (~0.4s per figure on the CTI frame, ~100 figures per bypassed fit).

Measured on the autocti script, cold (dataset simulated inside the run, libraries from source): 117.3s → 58.5s with this change alone → 25.9s with the smoke profile's PYAUTO_FAST_PLOTS=1 as well (PyAutoLabs/autocti_workspace, same branch name).

Found and measured by PyAutoBrain hygiene ci + /ci_speedup.

API Changes

No public API change. grid_2d_slim_over_sampled_via_mask_from returns the same values in the same order; a private helper _sub_pixel_offsets_from is added beside it. plot_array behaves identically unless PYAUTO_FAST_PLOTS=1, where it no longer computes the (never-drawn) mask-edge overlay.
See full details below.

Test Plan

  • test_autoarray — 1460 passed locally (libraries from source)
  • new oracle test: vectorised routine == per-pixel reference, bit-exact, uniform + mixed + zero sub-sizes
  • CI green on this PR
  • autocti_workspace smoke gate, once its profile PR is up, shows imaging_ci/modeling/start_here.py well under its 89.5s baseline
Full API Changes (for automation & release notes)

Removed

  • nothing

Added

  • autoarray.operators.over_sampling.over_sample_util._sub_pixel_offsets_from(sy, sx, sub_size) — private; the (sub_size², 2) offset block one pixel's sub-pixels take, in meshgrid(..., indexing="ij") order

Migration

  • none

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_015J8ZLmc55ZT1nSRntZMz9K


Generated by Claude Code

…rlay under fast plots

grid_2d_slim_over_sampled_via_mask_from built every unmasked pixel's
sub-pixel block in a Python loop (a linspace, a meshgrid and a stack per
pixel). On a 2000x100 CTI frame that is ~180k iterations and ~12s per call,
and FitDataset.__init__ forces the dataset's border relocator, which calls it
once per fit — four calls, ~50s of the 117s (local) / 89.5s (CI, slowest leg)
autocti_workspace imaging_ci/modeling/start_here.py smoke script, for a
relocator a CTI fit never uses. The offsets for a given sub-size are the same
for every pixel, so they are now built once per distinct sub-size and
broadcast onto that sub-size's pixel centres; non-uniform sub-sizes keep the
pixel-ordered layout through a per-pixel block start (cumsum of block sizes).
Output is bit-identical to the loop — the old construction is kept verbatim
as the oracle in a new test over random masks, uniform and mixed sub-sizes
(including zeros), and a non-zero origin.

plot_array derived the mask's edge grid on every call for the overlay; with
PYAUTO_FAST_PLOTS=1 the figure is closed before it is drawn or saved, so the
overlay is never seen. It is now skipped under that flag (~0.4s per figure on
the CTI frame, ~100 figures per bypassed fit).

Measured on the autocti script, cold (dataset simulated inside the run):
117.3s → 58.5s with this change alone → 25.9s with the smoke profile's
PYAUTO_FAST_PLOTS=1 as well. test_autoarray: 1460 passed.

Found and measured by PyAutoBrain `hygiene ci` + /ci_speedup.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015J8ZLmc55ZT1nSRntZMz9K
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 8, 2026 — with Claude
@Jammy2211
Jammy2211 merged commit 180c8a4 into main Sep 8, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the claude/smoke-test-perf-g8i2uq branch September 8, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants