Skip to content

Commit

Permalink
Merge pull request #7414 from lagru/pywt-numpy2
Browse files Browse the repository at this point in the history
Fix NumPy2 dtype promotion issues in pywt dependent code
  • Loading branch information
hmaarrfk committed May 8, 2024
2 parents 4cc5b3d + 05d585c commit cd20256
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Other
skimage/exposure/tests/test_exposure.py::test_rescale_nan_warning
* Finalize ``skimage.future.manual_segmentation`` API,
see https://github.com/scikit-image/scikit-image/issues/2624
* Remove ``except AttributeError`` block in
``skimage/segmentation/random_walker_segmentation.py`` as well as the warning filter
in ``pyproject.toml``, once pyamg supports NumPy 2
(see https://github.com/pyamg/pyamg/issues/406).

Post numpy 2
------------
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ python_classes = ["Test*", "*Suite"]
python_functions = ["time_*", "test_*", "peakmem_*"]
filterwarnings = [
"error",
'default:.*pyamg, which cannot \(yet\) be imported with NumPy >=2:RuntimeWarning'
]

[tool.coverage.run]
Expand Down
1 change: 1 addition & 0 deletions skimage/metrics/simple_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def peak_signal_noise_ratio(image_true, image_test, *, data_range=None):
image_true, image_test = _as_floats(image_true, image_test)

err = mean_squared_error(image_true, image_test)
data_range = float(data_range) # prevent overflow for small integer types
return 10 * np.log10((data_range**2) / err)


Expand Down
4 changes: 3 additions & 1 deletion skimage/restoration/_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@ def _wavelet_threshold(
for thresh, level in zip(threshold, dcoeffs)
]
denoised_coeffs = [coeffs[0]] + denoised_detail
return pywt.waverecn(denoised_coeffs, wavelet)[original_extent]
out = pywt.waverecn(denoised_coeffs, wavelet)[original_extent]
out = out.astype(image.dtype)
return out


def _scale_sigma_and_image_consistently(image, sigma, multichannel, rescale_sigma):
Expand Down
11 changes: 11 additions & 0 deletions skimage/segmentation/random_walker_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def new_del(self):
amg_loaded = True
except ImportError:
amg_loaded = False
except AttributeError as error:
if "`np.deprecate` was removed" in error.args[0]:
warn(
"found optional dependency pyamg, which cannot (yet) be imported with "
"NumPy >=2 and will be treated as if not available",
RuntimeWarning,
)
amg_loaded = False
else:
raise error


from ..util import img_as_float

Expand Down

0 comments on commit cd20256

Please sign in to comment.