-
Notifications
You must be signed in to change notification settings - Fork 53
feat[next]: adding python containers #2232
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
base: main
Are you sure you want to change the base?
Conversation
2988116 to
5a6ce4f
Compare
5a6ce4f to
7ce5f52
Compare
| return extractors if extractors else None | ||
|
|
||
| def __postinit__(self) -> None: | ||
| def __post_init__(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add a pygrep expression in pre-commit to catch this (or check if ruff has a rule for this).
| *self.program_type.definition.pos_or_kw_args.values(), | ||
| ] | ||
| ): | ||
| if isinstance(type_spec, ts.NamedTupleType): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a ts.TupleType that contains NamedTupleType, we have to generate an extractor.
src/gt4py/next/containers.py
Outdated
| def extract( | ||
| container, | ||
| ) -> NestedTuple[ | ||
| PythonContainerValue | ||
| ]: # TODO the input is NestedAnyContainer[PythonContainerValue], to be defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly remove again once we have the extractor for all args
| def __setitem__(self, index: AnyIndexSpec, value: Field | core_defs.ScalarT) -> None: ... | ||
|
|
||
|
|
||
| NumericValue: TypeAlias = core_defs.Scalar | Field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| NumericValue: TypeAlias = core_defs.Scalar | Field | |
| #: Elements of containers: TODO: use more examples | |
| NumericValue: TypeAlias = core_defs.Scalar | Field |
|
cscs-ci run |
| return len(self.types) | ||
|
|
||
|
|
||
| class NamedTupleType(TupleType): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inheriting from TupleType is dangerous as NamedTuples can not be used in all places where tuples are allowed, but we check if something is a tuple by doing isinstance(..., TupleType)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it StructType because due to the original_python_type it is not a just a NamedTuple anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe NamedCollectionType
|
|
||
| class NamedTupleType(TupleType): | ||
| keys: list[str] | ||
| original_python_type: str # Format: '__module__:__qualname__' (used by pkgutil.resolve_name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a comment that described where is value may be used and where not. For example inside of the type_deduction is should never be used.
In case there is a view of a global array, we do not have a problem, because we never modify the strides of globals. The problems start when there is a view of a transient. The SDFG is constructed using C order, which good for CPU. However, for GPU we go to FORTRAN order which is essentially swapping the memory order. But we can not only do that for transients, but must also do it for views, which might be difficult, because views can add or remove certain dimensions. This PR does _not_ solve it, but instead generates an error if such a case is detected.
## Description We found that there was an issue with absolute k-indexing inside the conditional of a while loop. This was due to a missing propagation of the symbol-table into the conditional. This PR fixes that issue. ## Requirements - [x] All fixes and/or new features come with corresponding tests. - [ ] Important design decisions have been documented in the appropriate ADR inside the [docs/development/ADRs/](docs/development/ADRs/README.md) folder. N/A
Adding support for typed namedtuples and Dataclasses as basic containers structures for related Fields. Changes initially prototyped in #2211