Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make geometric tensors explicitly not iterable #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions escnn/nn/geometric_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ def to(self, *args, **kwargs):
tensor = self.tensor.to(*args, **kwargs)
return GeometricTensor(tensor, self.type, self.coords)

def __iter__(self):
# The purpose of this method is to prevent an infinite loop from
# occurring if a user accidentally tries to iterate over a geometric
# tensor. The infinite loop occurs because of the way `__getitem__()`
# is implemented [1].
#
# [1] https://stackoverflow.com/questions/926574/why-does-defining-getitem-on-a-class-make-it-iterable-in-python

raise TypeError(f"{self.__class__.__name__!r} object is not iterable")

def __getitem__(self, slices) -> 'GeometricTensor':
r'''

Expand Down