Skip to content

Commit 0153472

Browse files
committed
fix: ensure __len__ is defined for all transforms``
1 parent fbb0451 commit 0153472

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

nitransforms/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ def __add__(self, b):
279279

280280
return TransformChain(transforms=[self, b])
281281

282+
def __len__(self):
283+
"""
284+
Enable ``len()``.
285+
286+
By default, all transforms are of length one.
287+
This must be overriden by transforms arrays and chains.
288+
289+
"""
290+
return 1
291+
282292
@property
283293
def reference(self):
284294
"""Access a reference space where data will be resampled onto."""

nitransforms/nonlinear.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ def __repr__(self):
9494
"""Beautify the python representation."""
9595
return f"<{self.__class__.__name__}[{self._field.shape[-1]}D] {self._field.shape[:3]}>"
9696

97-
def __len__(self):
98-
"""Enable len() -- for compatibility, only len == 1 is supported."""
99-
return 1
100-
10197
@property
10298
def ndim(self):
10399
"""Get the dimensions of the transform."""

0 commit comments

Comments
 (0)