Skip to content

BUG: return 0 not NaN when thresholding zeros at value 0 - #878

Merged
rgommers merged 1 commit into
PyWavelets:mainfrom
Dmao233:cursor/fix-866-threshold-zero-nan-6b9b
Sep 17, 2026
Merged

rgommers merged 1 commit into
PyWavelets:mainfrom
Dmao233:cursor/fix-866-threshold-zero-nan-6b9b

Conversation

@Dmao233

@Dmao233 Dmao233 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #866.

soft / nn_garrote / threshold_firm used 1 - value/|x|. When value == 0 and x == 0 that is 0/0 → NaN (clip does not clean NaN). Soft thresholding is defined as sign(x)·max(|x|−λ, 0), which is 0 for x == 0 at any λ ≥ 0.

Ignore the invalid divide and write 0 for |x| == 0 after the multiply (keeps dtype, including complex). Adds a regression test for soft/garrote/firm, all-zeros, complex, and float32/64 + complex64/128.

AI disclosure: the patch was written with an LLM; I reviewed and pushed it myself.

soft/garrote/firm used 1 - value/|x|, which is 0/0 → NaN when both
are zero. Ignore the invalid warning and zero those entries.

Co-authored-by: CenFangyu <Dmao233@users.noreply.github.com>

@rgommers rgommers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dmao233, this looks good to me.

@rgommers
rgommers merged commit cc45b0d into PyWavelets:main Sep 17, 2026
20 checks passed
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.

soft/garrote thresholding returns NaN for zero-valued data at threshold 0

3 participants