Make geometric tensors explicitly not iterable #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Attempting to iterate over a geometric tensor currently results in an infinite loop. The reason is that python considers an object to be iterable if it implements
__iter__()
or__getitem__()
. In the latter case, which is the relevant one for geometric tensors, python iterates by calling__getitem__(i)
with incrementing values ofi
until anIndexError
is raised.GeometricTensor.__getitem__()
returns an empty tensor instead of raising anIndexError
for out-of-bounds indices, so the iteration never completes.I think it's worth getting rid of the infinite loop behavior, because it can be an unpleasant and confusing surprise for users. There are two ways to do this: (i) don't allow iteration at all, or (ii) mimic the way iteration works for tensors. My preference is for the former. For one thing, raising an error now keeps the door open for supporting iteration later, without breaking backwards compatibility. For another, I don't think that classes should be iterable unless they are truly meant to be containers, and I don't primarily think of tensors as containers.