Repository navigation
perf: check x_arr, not x, when deciding whether irfft can write into out directly - #396
intel-python-devops wants to merge 2 commits into
Conversation
…array Add a test for `irfft` with `out=` on strided input that is cast (integer and real dtypes) or zero-padded (complex dtype) into a contiguous copy, in C and F order, which exercises MKL writing directly into `out`. Add a changelog entry for gh-396.
What this change doesIn the out-of-place branch of
When A correction to the description: the check does not only decide whether an extra copy happens. For input with 3 or more dimensions, the backend makes a single batched MKL call based on the layout of the input alone, so the check is also what keeps input and output layouts that don't match away from that call. The same change in MeasurementsLunar Lake,
A check against One case gets slower: input that is both C- and F-contiguous, such as shape Pushed to this branch16f2734 adds The failed |
Note
This pull request is entirely AI-generated. Please review thoroughly.
_c2r_fft1d_impl's out-of-place branch, the c_contig/f_contig heuristic that decides whetheroutcan be written to directly (versus allocating a scratch buffer and copying) now checksx_arr.flagsinstead ofx.flags.x_arris the array actually handed to the MKL backend (it may be a freshly-cast copy ofxwhen the input dtype is real, e.g. forirffton a float array), whilexis the original user-supplied object; whenxis non-contiguous but the cast copyx_arrhappens to be C- or F-contiguous, checkingx.flagswrongly concludes the layouts are incompatible and forces an avoidable scratch allocation plus a finalout[...] = f_arrcopy on every such call. The sibling function_r2c_fft1d_implalready fixed this exact pattern (its comment explicitly says "Check x_arr, which may be a cast copy of x with a different layout");_c2r_fft1d_implhad been left checkingx. The backend's irfft kernel (mklfft.c.src) always derives input and output DFTI strides independently from the actualx_arr/outarrays it is given, so this heuristic only ever gates whether the extra copy happens — never correctness — making the fix behaviour-preserving while enabling the zero-copy path in more cases.