Skip to content

BUG: threshold_firm returns shrunk value when the only large value is at index 0 - #883

Open
Arthur031221 wants to merge 1 commit into
PyWavelets:mainfrom
Arthur031221:fix-threshold-firm-first-index
Open

Arthur031221 wants to merge 1 commit into
PyWavelets:mainfrom
Arthur031221:fix-threshold-firm-first-index

Conversation

@Arthur031221

Copy link
Copy Markdown

threshold_firm returns wrong values for anyone whose above-value_high entries all lie in the first row (for 1-D data, a single large value at index 0, such as a large approximation coefficient from wavedec): those entries are shrunk instead of being left unchanged.

The restore step used np.any(large_vals[0]), which tests the index values from np.where for truthiness, so index 0 counts as "nothing to restore". It now indexes with the boolean mask magnitude > value_high.

Before:

>>> pywt.threshold_firm(np.array([5., 0.5]), 1.0, 2.0)
array([8., 0.])
>>> pywt.threshold_firm(np.array([0.5, 5.]), 1.0, 2.0)
array([0., 5.])

After: [5., 0.] for the first call. The second is unchanged.

Added test_threshold_firm_large_value_first (1-D, 2-D, complex); it fails on main and passes with the change. Full suite: 1053 passed, 2 skipped.

…at index 0

The check np.any(large_vals[0]) tested index values for truthiness, so a
value above value_high located at index 0 of the first axis was returned
shrunk instead of unchanged. Use a boolean mask.
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