Skip to content

Commit 87aa8b6

Browse files
authored
Merge pull request #1093 from MarcCote/fix_995
FIX: Resize ArraySequence.data without helper function to avoid reference increment
2 parents 1e93bd5 + 67c04b5 commit 87aa8b6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

nibabel/streamlines/array_sequence.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ def is_ndarray_of_int_or_bool(obj):
2424
np.issubdtype(obj.dtype, np.bool_)))
2525

2626

27-
def _safe_resize(a, shape):
28-
""" Resize an ndarray safely, using minimal memory """
29-
try:
30-
a.resize(shape)
31-
except ValueError:
32-
a = a.copy()
33-
a.resize(shape, refcheck=False)
34-
return a
35-
36-
3727
class _BuildCache(object):
3828
def __init__(self, arr_seq, common_shape, dtype):
3929
self.offsets = list(arr_seq._offsets)
@@ -287,7 +277,11 @@ def _resize_data_to(self, n_rows, build_cache):
287277
if self._data.size == 0:
288278
self._data = np.empty(new_shape, dtype=build_cache.dtype)
289279
else:
290-
self._data = _safe_resize(self._data, new_shape)
280+
try:
281+
self._data.resize(new_shape)
282+
except ValueError:
283+
self._data = self._data.copy()
284+
self._data.resize(new_shape, refcheck=False)
291285

292286
def shrink_data(self):
293287
self._data.resize((self._get_next_offset(),) + self.common_shape,

0 commit comments

Comments
 (0)