Skip to content

Commit c52215d

Browse files
fix(remap): really fix in_place issue (copy condition was broken)
1 parent b7dfb60 commit c52215d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fastremap/fastremap.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,6 @@ def remap(arr, table, preserve_missing_labels=False, in_place=False):
675675

676676
shape = arr.shape
677677

678-
if in_place and not (arr.flags.f_contiguous or arr.flags.c_contiguous):
679-
raise ValueError("Input array must be contiguous to use in_place.")
680-
681678
if arr.flags['F_CONTIGUOUS']:
682679
order = 'F'
683680
else:
@@ -689,7 +686,14 @@ def remap(arr, table, preserve_missing_labels=False, in_place=False):
689686
fit_value = min_label if abs(min_label) > abs(max_label) else max_label
690687
arr = refit(arr, fit_value, increase_only=True)
691688

692-
if (not in_place and original_dtype == arr.dtype) or not arr.flags.writeable:
689+
make_copy = (
690+
(not in_place)
691+
or (original_dtype == arr.dtype) # avoid two copies b/c copied in refit
692+
or (not arr.flags.writeable)
693+
or not (arr.flags.f_contiguous or arr.flags.c_contiguous)
694+
)
695+
696+
if make_copy:
693697
arr = np.copy(arr, order=order)
694698

695699
if all([ k == v for k,v in table.items() ]) and preserve_missing_labels:

0 commit comments

Comments
 (0)