Skip to content

Commit

Permalink
Fix size check in CollapseTuple pass (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehrengruber authored Jan 3, 2024
1 parent 100bc7f commit 7a9489f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gt4py/next/iterator/transforms/collapse_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def _get_tuple_size(elem: ir.Node, node_types: Optional[dict] = None) -> int | t
):
return UnknownLength

if not type_.dtype.has_known_length:
return UnknownLength

return len(type_.dtype)


Expand Down
6 changes: 6 additions & 0 deletions src/gt4py/next/iterator/type_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def __iter__(self) -> abc.Iterator[Type]:
raise ValueError(f"Can not iterate over partially defined tuple '{self}'.")
yield from self.others

@property
def has_known_length(self):
return isinstance(self.others, EmptyTuple) or (
isinstance(self.others, Tuple) and self.others.has_known_length
)

def __len__(self) -> int:
return sum(1 for _ in self)

Expand Down

0 comments on commit 7a9489f

Please sign in to comment.