Skip to content

Commit

Permalink
fix: ensure __len__ is defined for all transforms``
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Jul 31, 2024
1 parent fbb0451 commit 0153472
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 10 additions & 0 deletions nitransforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ def __add__(self, b):

return TransformChain(transforms=[self, b])

def __len__(self):
"""
Enable ``len()``.
By default, all transforms are of length one.
This must be overriden by transforms arrays and chains.
"""
return 1

@property
def reference(self):
"""Access a reference space where data will be resampled onto."""
Expand Down
4 changes: 0 additions & 4 deletions nitransforms/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ def __repr__(self):
"""Beautify the python representation."""
return f"<{self.__class__.__name__}[{self._field.shape[-1]}D] {self._field.shape[:3]}>"

def __len__(self):
"""Enable len() -- for compatibility, only len == 1 is supported."""
return 1

@property
def ndim(self):
"""Get the dimensions of the transform."""
Expand Down

0 comments on commit 0153472

Please sign in to comment.