-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat[next]: Extend astype to work with tuples #1352
Conversation
3823227
to
048d4c0
Compare
cscs-ci run |
cscs-ci run |
cscs-ci run |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_type_deduction.py
Outdated
Show resolved
Hide resolved
tests/next_tests/unit_tests/ffront_tests/foast_passes_tests/test_type_alias_replacement.py
Outdated
Show resolved
Hide resolved
cscs-ci run |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_execution.py
Outdated
Show resolved
Hide resolved
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_execution.py
Outdated
Show resolved
Hide resolved
cscs-ci run |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_execution.py
Outdated
Show resolved
Hide resolved
779ae8b
to
4a11354
Compare
cscs-ci run |
def cast_tuple( | ||
a: cases.IFloatField, | ||
b: cases.IFloatField, | ||
a_casted_to_int_outside_of_gt4py: cases.IField, |
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.
a_casted_to_int_outside_of_gt4py: cases.IField, | |
a_asint: cases.IField, |
The naming was not a serious proposal of mine, but just to signify what it meant. Here it should be clear from the context.
|
||
a = cases.allocate(cartesian_case, cast_tuple, "a")() | ||
b = cases.allocate(cartesian_case, cast_tuple, "b")() | ||
a_casted_to_int_outside_of_gt4py = gtx.np_as_located_field(IDim)(np.asarray(a).astype(int32)) |
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.
a_casted_to_int_outside_of_gt4py = gtx.np_as_located_field(IDim)(np.asarray(a).astype(int32)) | |
a_asint = gtx.np_as_located_field(IDim)(np.asarray(a).astype(int32)) |
As above.
This pull request extends the functionality of the built-in
astype
function in theffront
module such that we can writefield_float32, field_float32 = astype((field_float64, field_float64), float32)
. The changes specifically impact thefoast_to_itir.py
file. Here's an overview of the modifications:astype
function's argument and return types have been extended to accept tuples of fields in addition to individual fields.foast_to_itir.py
file, when casting tuples, each element is processed individually. The casted elements are then combined into a new tuple usingmake_tuple
.astype
function correctly handles tuples of fields.The motivation for these changes is to simplify and enhance code readability when performing operations that mix different types. In such scenarios, explicit type promotion is required, resulting in cluttered stencils with casting operations. This update makes the type conversion explicit and visible, reducing the need for extensive casting operations and improving code clarity.