Skip to content

fix: enforce consistent coefficient order for ravel_coeffs#427

Merged
grlee77 merged 1 commit into
PyWavelets:masterfrom
grlee77:ravel_sort_keys
Sep 20, 2018
Merged

fix: enforce consistent coefficient order for ravel_coeffs#427
grlee77 merged 1 commit into
PyWavelets:masterfrom
grlee77:ravel_sort_keys

Conversation

@grlee77
Copy link
Copy Markdown
Contributor

@grlee77 grlee77 commented Sep 19, 2018

The current implementation of ravel_coeffs depends on the order of the keys in the detail coefficient dictionaries returned by wavedecn. This order can vary across python versions due to differences in whether the underlying Python dict respects insertion order. This PR just sorts the keys first to make sure that the wavelet subbands are stacked in the raveled array is identical across all Python versions.

A compact example of the key ordering issue:

c = pywt.wavedecn(np.ones((4, 4)), wavelet='db1', level=1)
print(c[1].keys())

The output of the print statement above in Python 3.6 is dict_keys(['ad', 'da', 'dd']), but on Python 2.7 is ['dd', 'ad', 'da']. Note the difference in order which ends up reflected in which order the coefficients are stacked by pywt.ravel_coeffs.

print(sorted(c[1].keys())) whereas gives ['ad', 'da', 'dd'] on both versions for consistent order.

@grlee77 grlee77 added the bug label Sep 19, 2018
@grlee77 grlee77 changed the title fix: sort detail coefficient keys in ravel_coeffs for consistent order fix: enforce consistent coefficient order for ravel_coeffs Sep 19, 2018
@grlee77
Copy link
Copy Markdown
Contributor Author

grlee77 commented Sep 19, 2018

closes #426

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