add manual NumPy patching to mkl_fft#224
Conversation
mkl_fftmkl_fft
b2ebfdc to
d22ae8e
Compare
c8fe204 to
559373e
Compare
559373e to
e4c64d4
Compare
4eb05ce to
b5a4b19
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces manual NumPy patching functionality to mkl_fft, following NEP-36 fair play guidelines. It allows users to dynamically replace NumPy's FFT functions with mkl_fft's optimized implementations at runtime, similar to the approach used in mkl_umath.
Changes:
- Added
_patch_numpy.pymodule with patching/restoration functions and a context manager - Added test file
test_patch.pyto verify basic patch/restore functionality - Exported new public API functions:
patch_numpy_fft(),restore_numpy_fft(),is_patched(), andmkl_fftcontext manager
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| mkl_fft/_patch_numpy.py | Implements the patching mechanism using thread-local storage to track state, provides functions to patch/restore numpy.fft functions, and includes a context manager for temporary patching |
| mkl_fft/tests/test_patch.py | Basic test verifying patch and restore functionality by checking module names |
| mkl_fft/init.py | Exports the new patching API functions and context manager class |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
51ba5d3 to
83496b2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@ndgrigorian ping here, bot has some good points about idempotency of the patch function and some test cases |
yep, I agree, and same goes for in umath |
|
@antonwolfy @jharlow-intel This whole thing is a little hacky, so I added a note saying to prefer the context manager in general. |
jharlow-intel
left a comment
There was a problem hiding this comment.
Left a few comments on non-important stuff but this PR looks good to me
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM! The only comment from me is that it'd be great to update the changelog.
|
@jharlow-intel @antonwolfy should be ready |
f1604dd to
ac6eca8
Compare
* improve thread-safety of patching * gate repeated patch calls there still exist problematic edge cases (race condition where one thread restores while another is using patched functions)
leftover from idea to use GlobalPatch as parent to mkl_fft context manager
acb0658 to
c5931a9
Compare
also use from mkl_fft import interfaces to avoid redundant mkl_fft module in namespace
c5931a9 to
a162685
Compare
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM! Thank you @ndgrigorian
this PR proposes implementing manual patching for NumPy a la mkl_umath to mkl_fft
this patching is specifically designed with NEP-36 in mind