MAINT: fix two more issues with padding length 0 and size-0 axis input - #859
Open
rgommers wants to merge 2 commits into
Open
MAINT: fix two more issues with padding length 0 and size-0 axis input#859rgommers wants to merge 2 commits into
rgommers wants to merge 2 commits into
Conversation
…mples A slope cannot be determined from a single sample, and pywt.pad computed one anyway from whatever numpy.pad had left in the padding buffer, giving a ramp away from the only known value. With a pad width of 0 there was no buffer to read from and it raised an IndexError instead. The transforms already handle this: convolution.template.c demotes MODE_SMOOTH to MODE_CONSTANT_EDGE when the input has fewer than 2 samples. Do the same in pad(), and leave a zero-length axis untouched as there is nothing to extend from.
The reflected segments that the mode flips the sign of are as wide as the unpadded signal, so for a zero-size axis `r_edge += seg_width` never advanced and the loop spun forever. Only reachable with a pad width of 0, as numpy.pad rejects reflecting an empty axis otherwise. There is nothing to reflect in that case, so return early. Also assert what 'periodization' does for a zero pad width instead of skipping it, since it is the one mode that is deliberately not the identity there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow-up to gh-854.
Used Claude Opus 5.0 to review gh-854 and it identified these two similar cases - fix them while we're at it. Claude also wrote the code, verified by me. This isn't very important as a real-world issue, but may as well get it all handled consistently.