perf(zernike): build z**m iteratively in _zernike_scores#92
Merged
Conversation
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>
Benchmark —
|
| 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× |
afermg
approved these changes
Jul 3, 2026
afermg
left a comment
Owner
There was a problem hiding this comment.
Kind of crazy the difference, but might as well add the change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_zernike_scoresbuilt its azimuthal power table withz**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_scoresacross image sizes — bothget_zernikeand the intensity-weighted radial Zernikes go through it.Verified bit-identical to the previous output; existing
test_zernike.py/test_radial_zernike.pycover it.