Skip to content

BUG: fix indexing in reconstruct method of 1-D/2-D wavelet packet - #860

Open
rgommers wants to merge 3 commits into
PyWavelets:mainfrom
rgommers:waveletpacketnd-followup
Open

BUG: fix indexing in reconstruct method of 1-D/2-D wavelet packet #860
rgommers wants to merge 3 commits into
PyWavelets:mainfrom
rgommers:waveletpacketnd-followup

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is a follow-up to gh-857, fixing the same issue for 1-D/2-D as that PR fixed for n-D. Also improve the tests.

AI usage declaration: I used Claude Opus 5.0 to audit the code for this issue, and most of the code is generated by it.

Every existing WaveletPacketND test uses even-length axes, so the trim back to
the original data shape was never exercised - which is how the IndexError in
reconstruct() went unnoticed.
… shape

Node._reconstruct and Node2D._reconstruct both trim the inverse transform back
to the shape of the coefficients stored in the node, but NodeND._reconstruct
did not. For odd-length axes this made a subnode reconstruct one sample too
long along each transformed axis, and with update=True the data held by the
node silently grew. It is also why only the ND class reached the trim in
WaveletPacketND.reconstruct, where the IndexError was hit.
Same defect as the one fixed in WaveletPacketND.reconstruct: numpy no longer
accepts a list of slices as an index. These two are not reachable today, as the
node level trim in Node._reconstruct and Node2D._reconstruct already resizes
the data, so there is nothing to add a test for.
@rgommers rgommers added the bug label Aug 17, 2026
@rgommers rgommers added this to the v1.10.0 milestone Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant