Skip to content

Commit

Permalink
Merge pull request #19576 from SimonSegerblomRex/fix-19575
Browse files Browse the repository at this point in the history
BUG: Use uint32 for cost in NI_WatershedElement
  • Loading branch information
tylerjereddy committed Nov 23, 2023
2 parents a65cb5c + 0db90e1 commit ae9dc13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scipy/ndimage/src/ni_measure.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ break
typedef struct {
npy_intp index;
void *next, *prev;
npy_uint16 cost;
npy_uint32 cost;
npy_uint8 done;
} NI_WatershedElement;

Expand Down
23 changes: 20 additions & 3 deletions scipy/ndimage/tests/test_measurements.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import os.path

import numpy as np
from numpy.testing import (assert_, assert_array_almost_equal, assert_equal,
assert_almost_equal, assert_array_equal,
suppress_warnings)
from numpy.testing import (
assert_,
assert_allclose,
assert_almost_equal,
assert_array_almost_equal,
assert_array_equal,
assert_equal,
suppress_warnings,
)
from pytest import raises as assert_raises

import scipy.ndimage as ndimage
Expand Down Expand Up @@ -1390,3 +1396,14 @@ def test_watershed_ift08(self):
expected = [[1, 1],
[1, 1]]
assert_array_almost_equal(out, expected)

def test_watershed_ift09(self):
# Test large cost. See gh-19575
data = np.array([[np.iinfo(np.uint16).max, 0],
[0, 0]], np.uint16)
markers = np.array([[1, 0],
[0, 0]], np.int8)
out = ndimage.watershed_ift(data, markers)
expected = [[1, 1],
[1, 1]]
assert_allclose(out, expected)

0 comments on commit ae9dc13

Please sign in to comment.