-
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]: concat_where for boundary conditions #1468
Conversation
… into concat_where
mask: core_defs.NDArrayObject, | ||
) -> list[tuple[bool, common.UnitRange]]: | ||
"""Take a 1-dimensional mask and return a sequence of mappings from boolean values to ranges.""" | ||
# TODO: does it make sense to upgrade this naive algorithm to numpy? |
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 used in k, probably not relevant, if used in the horizontal, probably this is a performance problem
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 some timeit
microbenchmarks with typical (both small and large) domain sizes would help to figure out if it'd pay off.
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 started doing a more exhaustive review but then switched to more general questions and comments, so there's a mix of high-level and low-level implementation details (and didn't review the tests at all).
@@ -97,14 +97,57 @@ def _absolute_sub_domain( | |||
return common.Domain(*named_ranges) | |||
|
|||
|
|||
def intersect_domains(*domains: common.Domain) -> common.Domain: | |||
def domain_intersection( |
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.
Just a suggestion, I think this could be transformed into the .intersection()
method in the Domain
class to follow the same API as set
(https://devdocs.io/python~3.12/library/stdtypes#set)
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 adding that makes sense, however I like more that this function works also when domains is empty
src/gt4py/next/embedded/common.py
Outdated
return functools.reduce( | ||
operator.and_, | ||
domains, | ||
common.Domain(dims=tuple(), ranges=tuple()), | ||
) | ||
|
||
|
||
def intersect_domains( |
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 find this function confusing specially given the previous one. I think the name could contain the name restrict
instead of intersection (e.g. restrict_to_lower_bound
, restrict_to_intersection
) and the ignore_dims
argument shouldn't be optional, because otherwise is just a simple intersection of domains.
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.
- Changed the name.
- In generic context allowing ignore_dims to be optional makes sense to me. Maybe I could change the API to only accept tuples and default to empty tuple. What do you think?
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 still don't like that much that ignore_dims
is optional but it's ok. ignore_dims
accepting only tuples makes sense to me, but it's not strictly needed and it's orthogonal to my original complaint because it'll still have a default value.
mask: core_defs.NDArrayObject, | ||
) -> list[tuple[bool, common.UnitRange]]: | ||
"""Take a 1-dimensional mask and return a sequence of mappings from boolean values to ranges.""" | ||
# TODO: does it make sense to upgrade this naive algorithm to numpy? |
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 some timeit
microbenchmarks with typical (both small and large) domain sizes would help to figure out if it'd pay off.
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.
It looks good, just have a few comments, most of them optional, and it should be ready to merge.
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.
ILGTM
Introduces `concat_where` to be used for boundary conditions. `where` will intersect all 3 fields. Therefore `where(klevel == 0, boundary_layer, interior)` will not work if `boundary_layer` is only defined on `klevel == 0`. `concat_where` will concatenate the fields that are selected by the mask regions. The `mask` is currently required to be 1 dimensional.
Introduces
concat_where
to be used for boundary conditions.where
will intersect all 3 fields. Thereforewhere(klevel == 0, boundary_layer, interior)
will not work ifboundary_layer
is only defined onklevel == 0
.concat_where
will concatenate the fields that are selected by the mask regions. Themask
is currently required to be 1 dimensional.