Skip to content

Commit

Permalink
Revert to Python float that is out of range
Browse files Browse the repository at this point in the history
In `test_overrange_tolerance_float`:
The previous test actually checked what happens if a Python float that
is out of range for the image type is used as the tolerance. Not casting
with `max_value.item()` would result in `np.float32(inf)` which is a
different test.

In `flood`:
Furthermore, we need to turn `min_value` and `max_value` into Python
scalars with `.item()` as well. Otherwise `max` and `min` seem to
trigger an overflow error during the comparison.
  • Loading branch information
lagru committed Feb 23, 2024
1 parent 5b419f3 commit 74a6592
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions skimage/morphology/_flood_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def flood(image, seed_point, *, footprint=None, connectivity=None, tolerance=Non
# Account for over- & underflow problems with seed_value ± tolerance
# in a way that works with NumPy 1 & 2
min_value, max_value = numeric_dtype_min_max(seed_value.dtype)
low_tol = max(min_value, seed_value.item() - tolerance)
high_tol = min(max_value, seed_value.item() + tolerance)
low_tol = max(min_value.item(), seed_value.item() - tolerance)
high_tol = min(max_value.item(), seed_value.item() + tolerance)

_flood_fill_tolerance(
working_image.ravel(order),
Expand Down
4 changes: 1 addition & 3 deletions skimage/morphology/tests/test_flood_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def test_overrange_tolerance_float():
image *= max_value

expected = np.ones_like(image)
with np.errstate(over="ignore"):
tolerance = max_value * 10
output = flood_fill(image, (0, 1), 1.0, tolerance=tolerance)
output = flood_fill(image, (0, 1), 1.0, tolerance=max_value.item() * 10)

np.testing.assert_equal(output, expected)

Expand Down

0 comments on commit 74a6592

Please sign in to comment.