Skip to content

Commit 23f8e69

Browse files
committed
Apply affine inplace when the underlying arraysequence of the streamlines is not a sliced view.
1 parent ac5cd21 commit 23f8e69

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

nibabel/streamlines/array_sequence.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def __init__(self, iterable=None, buffer_size=4):
146146

147147
self.extend(iterable)
148148

149+
@property
150+
def is_sliced_view(self):
151+
return self._lengths.sum() != self._data.shape[0]
152+
149153
@property
150154
def is_array_sequence(self):
151155
return True

nibabel/streamlines/tractogram.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,12 @@ def apply_affine(self, affine, lazy=False):
429429
if np.all(affine == np.eye(4)):
430430
return self # No transformation.
431431

432-
for i in range(len(self.streamlines)):
433-
self.streamlines[i] = apply_affine(affine, self.streamlines[i])
432+
if self.streamlines.is_sliced_view:
433+
# Apply affine only on the selected streamlines.
434+
for i in range(len(self.streamlines)):
435+
self.streamlines[i] = apply_affine(affine, self.streamlines[i])
436+
else:
437+
self.streamlines._data = apply_affine(affine, self.streamlines._data, inplace=True)
434438

435439
if self.affine_to_rasmm is not None:
436440
# Update the affine that brings back the streamlines to RASmm.

0 commit comments

Comments
 (0)