Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/PartSegCore_compiled_backend/_napari_mapping.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ctypedef fused out_types:
out_types_mod
cnp.float32_t

def _zero_preserving_modulo_seq(label_types[:] labels, out_types_mod modulo, label_types to_zero, out_types_mod[:] out):
def _zero_preserving_modulo_seq(label_types[:] labels, int modulo, int to_zero, out_types_mod[:] out):
cdef Py_ssize_t i
cdef Py_ssize_t n = labels.shape[0]
for i in range(n):
Expand All @@ -37,7 +37,7 @@ def _zero_preserving_modulo_seq(label_types[:] labels, out_types_mod modulo, la
else:
out[i] = ((modulo + ((labels[i] - 1) % modulo)) % modulo) + 1

def _zero_preserving_modulo_par(label_types[:] labels, out_types_mod modulo, label_types to_zero, out_types_mod[:] out):
def _zero_preserving_modulo_par(label_types[:] labels, int modulo, int to_zero, out_types_mod[:] out):
cdef Py_ssize_t i
cdef Py_ssize_t n = labels.shape[0]
for i in prange(n, nogil=True):
Expand Down
13 changes: 13 additions & 0 deletions src/tests/test_napari_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ def test_map_array(func, data):
out = func(data, map_dkt, 0)
assert out.dtype == np.uint8
npt.assert_array_equal(out, _map_array(data, map_dkt, np.uint8))


@pytest.mark.parametrize('num,dtype', [(40, np.uint8), (1000, np.uint16)])
@pytest.mark.parametrize('func', [zero_preserving_modulo_parallel, zero_preserving_modulo_sequential])
def test_cast_labels_to_minimum_type_auto(num: int, dtype, monkeypatch, func):
data = np.zeros(3, dtype=np.uint32)
data[1] = 10
data[2] = 10**6 + 5
cast_arr = func(data, num, 0)
assert cast_arr.dtype == dtype
assert cast_arr[0] == 0
assert cast_arr[1] == 10
assert cast_arr[2] == 10**6 % num + 5