Skip to content

perf(zernike): build z**m iteratively in _zernike_scores#92

Merged
afermg merged 1 commit into
mainfrom
perf/zernike-iterative-powers
Jul 3, 2026
Merged

perf(zernike): build z**m iteratively in _zernike_scores#92
afermg merged 1 commit into
mainfrom
perf/zernike-iterative-powers

Conversation

@timtreis

@timtreis timtreis commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

_zernike_scores built its azimuthal power table with z**m (m up to the zernike order) on the complex foreground-pixel array. For m ≥ 3, numpy's ** is ~20× slower than repeated multiplication. Accumulating the powers by multiplication (z, z·z, …) is bit-identical and cuts ~9% off _zernike_scores across image sizes — both get_zernike and the intensity-weighted radial Zernikes go through it.

Verified bit-identical to the previous output; existing test_zernike.py / test_radial_zernike.py cover it.

The azimuthal power table used `z**m` (m up to the zernike order) on the complex
foreground-pixel array; `**` is ~20x slower than repeated multiply for m>=3. Accumulating
the powers by multiplication is bit-identical and cuts ~9% off _zernike_scores across image
sizes — both get_zernike and the intensity-weighted radial Zernikes go through it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timtreis
timtreis requested a review from afermg July 3, 2026 18:45
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Benchmark — 38ac610 vs main

speedup = main/head (>1 faster, <1 slower) · median per cell · showing functions that moved ≥1.05× either way

granularity

size \ objects 16 64 256
256 1.01× 1.01× 0.99×
512 1.06× 1.01× 0.93×
1024 0.98× 1.00× 1.02×

manders_fold

size \ objects 16 64 256
256 0.99× 0.98× 0.97×
512 0.96× 0.97× 0.92×
1024 0.97× 0.97× 0.98×

radial_zernikes

size \ objects 16 64 256
256 1.13× 1.15× 1.11×
512 1.08× 1.15× 1.09×
1024 1.12× 1.12× 1.11×

zernike

size \ objects 16 64 256
256 1.14× 1.15× 1.11×
512 1.09× 1.11× 1.11×
1024 1.10× 1.13× 1.12×

@timtreis timtreis added the numpy label Jul 3, 2026

@afermg afermg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of crazy the difference, but might as well add the change.

@afermg
afermg merged commit 2248989 into main Jul 3, 2026
17 checks passed
@afermg
afermg deleted the perf/zernike-iterative-powers branch July 3, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants