Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pywt/_thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ def threshold_firm(data, value_low, value_high):
raise ValueError(
"value_high must be greater than or equal to value_low.")

if np.isinf(value_high):
return soft(data, value_low)

data = np.asarray(data)
magnitude = np.absolute(data)
with np.errstate(divide='ignore', invalid='ignore'):
Expand Down
17 changes: 17 additions & 0 deletions pywt/tests/test_thresholding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from numpy.testing import assert_, assert_allclose, assert_equal, assert_raises

import pywt
Expand Down Expand Up @@ -200,3 +201,19 @@ def test_threshold_zero_value_with_zeros():
assert_(not np.isnan(out_soft).any())
assert_(not np.isnan(out_garrote).any())
assert_(not np.isnan(out_firm).any())


@pytest.mark.parametrize("dtype", [np.float32, np.float64, np.complex64, np.complex128])
@pytest.mark.parametrize("value_low", [0.0, 2.0])
def test_threshold_firm_infinite_upper_threshold(dtype, value_low):
data = np.array([-4, -2, -1, 0, 1, 2, 4], dtype=dtype)
if np.issubdtype(dtype, np.complexfloating):
data = data * (1 + 1j)
original = data.copy()

actual = pywt.threshold_firm(data, value_low, np.inf)
expected = pywt.threshold(data, value_low, mode='soft')

assert_allclose(actual, expected)
assert actual.dtype == expected.dtype
assert_allclose(data, original)