Skip to content

ENH: NEP 50 scalar promotion semantics in ufunc.at - #32094

Merged
mhvk merged 7 commits into
numpy:mainfrom
ngoldbaum:nep-50-ufunc-at
Jul 31, 2026
Merged

ENH: NEP 50 scalar promotion semantics in ufunc.at#32094
mhvk merged 7 commits into
numpy:mainfrom
ngoldbaum:nep-50-ufunc-at

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

PR summary

Followup for #32076 (comment)

Also see #32090.

AI Disclosure

I used AI to identify the issue and help debug the fix.

Comment on lines +649 to +650
* TODO: Just like the general dual NEP 50/legacy promotion
* support this is meant as a temporary hack for NumPy 1.25.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@seberg what do you think about this "temporary hack"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this seems fine to do (just like the other PR was, of course not back-porting).

The "temporary hack" would require removing legacy promotion entirely, which in part would be nice, but in it's entirety seems hard...
(I think I once thought that if we stop using it in NumPy, one could at least move the hack to a different place for user ufunc and slowly deprecate)

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ngoldbaum - looks very good! And nice that it is relatively simple. Only some small comments.

Py_INCREF(tmp_operands[1]);
operand_DTypes[1] = NPY_DTYPE(PyArray_DESCR(op2_array));
Py_INCREF(operand_DTypes[1]);
if (mark_pyscalar_operand(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could in principle directly assign to op2_is_pyscalar, but arguably what you have is clearer, so only writing this in case you feel differently.

Comment thread numpy/_core/src/umath/ufunc_object.c
Comment thread numpy/_core/src/umath/ufunc_object.c Outdated
Comment thread numpy/_core/tests/test_nep50_promotions.py Outdated
Comment thread numpy/_core/tests/test_nep50_promotions.py Outdated
@ngoldbaum

Copy link
Copy Markdown
Member Author

@mhvk if you could give this another pass I'd appreciate it, that would unblock me updating #32040.

@ikrommyd ikrommyd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I honestly do not see anything here. All looks good to me. The only OCD thing that the other PR that I did #32090 was labeled as a BUG while this is an ENH. I say they should be the same so this one needs changing or the already merged on. The release notes are labeled in both PRs as "change". Only left a minor nitpicky comment for the goto label.

Comment thread numpy/_core/src/umath/ufunc_object.c Outdated
/* Find the correct operation_descrs for the operation */
int resolve_result = resolve_descriptors(nop, ufunc, ufuncimpl,
tmp_operands, operation_descrs, signature, operand_DTypes, NULL, NPY_UNSAFE_CASTING);
finish_resolution:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this should probably not be indented in. fail: is usually at column 0

@ngoldbaum

Copy link
Copy Markdown
Member Author

I say they should be the same so this one needs changing or the already merged on. The release notes are labeled in both PRs as "change". Only left a minor nitpicky comment for the goto label.

IMO the other one should have been labeled as ENH because it changes behavior. No need to go back and correct that though.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks all OK to me, thanks!

@mhvk
mhvk merged commit 10a566f into numpy:main Jul 31, 2026
91 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.

4 participants