You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to figure out how to use ufunc.resolve_dtypes. So as per usual, I threw away the manual and instead just tried a couple of guesses.
First I tried passing 1 to np.sin.resolve_dtypes, that didn't work:
In [1]: np.sin.resolve_dtypes(1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 np.sin.resolve_dtypes(1)
TypeError: resolve_dtypes: The dtypes must be a tuple of `ufunc.nargs` length.
The error message seems helpful though; it must be a tuple (of size 2 in this case), so I tried with (1, 1) next:
In [2]: np.sin.resolve_dtypes((1, 1))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 np.sin.resolve_dtypes((1, 1))
TypeError: Provided dtype must be a valid NumPy dtype, int, float, complex, or None.
Hmm, that didn't work either...
It mentions it accepts "dtype", I thought I'd try it with int types, i.e. (int, int):
I now realize that this works as intended with e.g. resolve_dtypes((float, float)).
This segfault clearly shouldn't have happened though; it should've raised a TypeError with a another helpful error message, like it did when I passed (1, 1) and 1.
Ok, starting at it a bit too long: I think the code is a bit weird but correct. The NULL there is OK and not the NULL that is tripping things.
The problem is that original_DTypes[i] == NULL here. The interaction there is a bit wild, but does come down a bit to the fact that input makes no sense at all: You cannot have a Python int/float/complex as an output to a ufunc! This works fine:
Just took a look here, and still wrapping my head around it, but yes: I think during the ufunc promotion step the output dtype (which is then original_DTypes[i]) is set to NULL but the incoming Python int is still there as an operand.
It leaks in because the "allow weak scalars branch" does not reject output dtypes:
Activity
ngoldbaum commentedon Jun 24, 2026
Some context from lldb:
So this is a NULL-pointer dereference. The NULL pointer is coming from a few levels up in the stack:
numpy/numpy/_core/src/umath/ufunc_object.c
Lines 4247 to 4256 in 2a674fc
inputs_tupis NULL, so we end up in the branch that setsdescrto NULL and this callsPyArray_CommonDType, which doesn't handle NULL input like this.@seberg do you happen to remember why you wrote it this way back in 1cb4044?
seberg commentedon Jun 24, 2026
Ok, starting at it a bit too long: I think the code is a bit weird but correct. The
NULLthere is OK and not theNULLthat is tripping things.The problem is that
original_DTypes[i] == NULLhere. The interaction there is a bit wild, but does come down a bit to the fact that input makes no sense at all: You cannot have a Python int/float/complex as an output to a ufunc! This works fine:MaanasArora commentedon Jul 2, 2026
Just took a look here, and still wrapping my head around it, but yes: I think during the ufunc promotion step the output dtype (which is then
original_DTypes[i]) is set toNULLbut the incoming Python int is still there as an operand.It leaks in because the "allow weak scalars branch" does not reject output dtypes:
https://github.com/Diamagnetic/numpy/blob/06661b0144c9c06ac07d27d96d5984492900010f/numpy/_core/src/umath/ufunc_object.c#L6427-L6436