Skip to content

BUG: preserve coefficients during inverse multiresolution analysis - #885

Open
antonsoo wants to merge 1 commit into
PyWavelets:mainfrom
antonsoo:fix/preserve-mra-coefficients
Open

antonsoo wants to merge 1 commit into
PyWavelets:mainfrom
antonsoo:fix/preserve-mra-coefficients

Conversation

@antonsoo

Copy link
Copy Markdown

imra2 and imran add details into the supplied approximation array. Reconstructing twice from the same decomposition therefore adds the details twice, and later filtered reconstructions use a changed approximation:

import numpy as np
import pywt

x = pywt.data.camera()[192:224, 192:224].astype(float)
coeffs = pywt.mra2(x, 'db2', level=2)
approximation = coeffs[0].copy()
first = pywt.imra2(coeffs).copy()
second = pywt.imra2(coeffs)
print(np.max(np.abs(first - second)))  # about 44 before; 0 after
np.testing.assert_array_equal(coeffs[0], approximation)

Copy the approximation before summing in both inverse functions. This retains the existing summation order and allocates one output array. It also allows read-only coefficient arrays.

Validation covers actual camera/RGB-face/ECG data with DWT/SWT, both APIs, db2/sym4 and real/complex single/double precision. All 80 configurations change their input before; none do afterward. All 80 first-reconstruction outputs remain byte-identical, repeated outputs now agree exactly, and all read-only cases complete. An independent sum of attenuated components agrees within 4.32e-5 in float32.

All 32 new regressions fail on main and pass with the fix. The full package suite passes (1084 tests, two skips), as do the project pre-commit hooks. The released 1.10.0 wheel and #847's head reproduce the same mutation; #847 changes annotations only in this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant