Skip to content

ENH: avoid looping when dimensions[0] == 0 or array.size == 0#21499

Merged
mattip merged 1 commit intonumpy:mainfrom
mattip:avoid-0dim-reduce
May 12, 2022
Merged

ENH: avoid looping when dimensions[0] == 0 or array.size == 0#21499
mattip merged 1 commit intonumpy:mainfrom
mattip:avoid-0dim-reduce

Conversation

@mattip
Copy link
Member

@mattip mattip commented May 12, 2022

Part of #21477

There is no need to enter a ufunc loop if the array is empty. These were detected by using the assert in the PR together with CFLAGS="-O0 -g3 -UNDEBUG"

@mattip mattip force-pushed the avoid-0dim-reduce branch from d3d4090 to 7328dba Compare May 12, 2022 11:57
@seberg
Copy link
Member

seberg commented May 12, 2022

Ack, just also spend way too much time trying to frickle that "first visit" loop nicer. Plus, I couldn't find any other dubious paths in the ufunc machinery right now.

Thanks! Please go ahead and just self-merge once things pass. A bit tricky to make sure we never call the inner-loop with an empty count, but overall there seems no real point in not checking early on.

@seberg
Copy link
Member

seberg commented May 12, 2022

The test failure should be fixed by gh-21500, it has nothing to do with this PR.

@mattip mattip merged commit b5251e7 into numpy:main May 12, 2022
@mattip mattip deleted the avoid-0dim-reduce branch December 27, 2022 16:52
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.

2 participants