Skip to content

BUG: np.fft.hfft on main segfaults when n=1 #25661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jakevdp opened this issue Jan 22, 2024 · 3 comments · Fixed by #25668
Closed

BUG: np.fft.hfft on main segfaults when n=1 #25661

jakevdp opened this issue Jan 22, 2024 · 3 comments · Fixed by #25668
Labels

Comments

@jakevdp
Copy link
Contributor

jakevdp commented Jan 22, 2024

Describe the issue:

With the current nightly release, np.fft.hfft segfaults when n=1

Reproduce the code example:

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '2.0.0.dev0+git20240120.6bd3abf'

In [3]: x = np.arange(10)

In [4]: np.fft.hfft(x, n=1)
Segmentation fault: 11

Error message:

Segmentation fault: 11

Python and NumPy Versions:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)
2.0.0.dev0+git20240120.6bd3abf
3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)]

Runtime Environment:

>>> import numpy; print(numpy.show_runtime())
[{'numpy_version': '2.0.0.dev0+git20240120.6bd3abf',
  'python': '3.9.6 (default, May  7 2023, 23:32:44) \n'
            '[Clang 14.0.3 (clang-1403.0.22.14.1)]',
  'uname': uname_result(system='Darwin', node='jmdg-macbookpro.roam.internal', release='23.2.0', version='Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}}]

Context for the issue:

I found this through nightly tests of JAX against upstream NumPy; this failure began to appear in the last few days, so this is likely due to a recent change to fft.

@jakevdp jakevdp changed the title BUG: np.fft.hfft segfault when n=1 BUG: np.fft.hfft on main segfaults when n=1 Jan 22, 2024
@jakevdp
Copy link
Contributor Author

jakevdp commented Jan 22, 2024

I haven't bisected, but given the timing #25536 seems to be the likely culprit. cc/ @mhvk

@ngoldbaum
Copy link
Member

Seems to be coming from memcpy being passed a negative size:

(lldb) up
warning: _pocketfft_umath.cpython-311-darwin.so was compiled with optimization - stepping may behave oddly; variables may not be available.
frame #1: 0x00000001003e6990 _pocketfft_umath.cpython-311-darwin.so`irfft_loop [inlined] copy_data(in=<unavailable>, step_in=16, nin=8, out="", step_out=16, nout=-1, elsize=16) at _pocketfft_umath.c:37:9 [opt]
   34  	{
   35  	    npy_intp ncopy = nin <= nout? nin : nout;
   36  	    if (step_in == elsize && step_out == elsize) {
-> 37  	        memcpy(out, in, ncopy*elsize);
   38  	    }
   39  	    else {
   40  	        char *ip = in, *op = out;
(lldb) p ncopy
(npy_intp) -1
(lldb) p nin
(npy_intp) 8
(lldb) p nout
(npy_intp) -1

@mhvk
Copy link
Contributor

mhvk commented Jan 23, 2024

That surely is me 🤦
...
Fix in #25668.

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 a pull request may close this issue.

3 participants