Skip to content
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

MAINT: Remove dead codepath in generalized ufuncs #18864

Merged
merged 2 commits into from
May 6, 2021

Conversation

seberg
Copy link
Member

@seberg seberg commented Apr 27, 2021

If the iterator has size zero, then that means that the outer
iteration has size. Since the outer iteration is unaffected by
core dimensions, in that case the output always has size zero
and the code does nothing but unnecessary checking the array sizes.


@rossbar this is a short PR you will like ;).

@@ -2457,7 +2457,7 @@ PyUFunc_GeneralizedFunctionInternal(PyUFuncObject *ufunc, PyArrayObject **op,
/* Fill in any allocated outputs */
{
PyArrayObject **operands = NpyIter_GetOperandArray(iter);
for (i = 0; i < nop; ++i) {
for (i = nin; i < nop; ++i) {
Copy link
Member Author

Choose a reason for hiding this comment

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

No point in iterating through all, op[i] cannot be NULL unless i >= nin.

Copy link
Member Author

Choose a reason for hiding this comment

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

Frankly, this could be moved into the later loop, but for clarity, I wasn't sure that would actually be better...

@seberg
Copy link
Member Author

seberg commented Apr 27, 2021

Added a test for the (non-) possibility of an output that is broadcast. I am not 100% sure that it isn't possible to override the iterator flags in weird ways to allow a broadcast here, but I think I will put that into the realm of "doesn't really make sense" until proven otherwise.

@seberg seberg force-pushed the delete-nonsense-code-from-gufuncs branch from a0ec427 to 7f6a1c2 Compare April 27, 2021 21:32
If the iterator has size zero, then that means that the outer
iteration has size.  Since the outer iteration is unaffected by
core dimensions, in that case the output always has size zero
and the code does nothing but unnecessary checking the array sizes.
This ensures that it is correct to not initize the output array if
the outer iteration has size 0.  The broadcast result would always
have size 0 in that case.
If the iterator rejects such a broadcast it cannot happen.
@seberg seberg force-pushed the delete-nonsense-code-from-gufuncs branch from 7f6a1c2 to 18ffb74 Compare April 27, 2021 21:58
@mattip mattip added this to In Progress in Ufunc refactor May 5, 2021
@mattip mattip moved this from In Progress to Ready for final review in Ufunc refactor May 6, 2021
@mattip mattip merged commit b5cd0b5 into numpy:main May 6, 2021
@mattip
Copy link
Member

mattip commented May 6, 2021

Thanks @seberg

@mattip mattip removed this from Ready for final review in Ufunc refactor May 6, 2021
@seberg seberg deleted the delete-nonsense-code-from-gufuncs branch May 6, 2021 20:03
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.

None yet

2 participants