Skip to content

TST: Add tests for PyUFunc_ReplaceLoopBySignature#31097

Merged
seberg merged 3 commits intonumpy:mainfrom
eendebakpt:ufunc_loop_replace_tests
Apr 10, 2026
Merged

TST: Add tests for PyUFunc_ReplaceLoopBySignature#31097
seberg merged 3 commits intonumpy:mainfrom
eendebakpt:ufunc_loop_replace_tests

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

PR summary

Add C test helpers (replace_loop/restore_loop) that replace a ufunc's float64 loop with one that always outputs 42.0.

Python tests verify:

  • Replaced loop is actually called (output is 42.0, not normal result)
  • Replacement works after the ufunc has been called (caches populated)
  • Original loop is correctly restored

AI Disclosure

Claude was instructed to create a test based on #31068 (comment). Afterwards the test was manually cleaned and made more specific.

eendebakpt and others added 2 commits March 29, 2026 20:47
Add C test helpers (replace_loop/restore_loop) in _umath_tests that
replace a ufunc's float64 loop with one that always outputs 42.0.

Python tests verify:
- Replaced loop is actually called (output is 42.0, not normal result)
- Replacement works after the ufunc has been called (caches populated)
- Original loop is correctly restored

The test_replace_after_use test is specifically designed to catch bugs
where loop caching optimizations fail to invalidate on replacement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@eendebakpt eendebakpt force-pushed the ufunc_loop_replace_tests branch from 86b03e2 to 7c6ca27 Compare March 29, 2026 18:47
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks for adding this test, probably best to have if we want to touch things here (and even if we deprecated easy to remove).

A bit scary to use a real ufunc, but should be OK. (Although if there is a testing one around, and you feel like it...)

Either way, the only real thing is that this test isn't thread safe, so needs the marker.

Comment thread numpy/_core/tests/test_umath.py
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Thanks, if things change and the test is outdated it should be easy to follow-up!

@seberg seberg merged commit 8df4566 into numpy:main Apr 10, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants