-
Notifications
You must be signed in to change notification settings - Fork 130
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
Add a SubrangeMapper
helper class which maps a _subrange_ of src
range to its counterpart in dst
range, if possible.
#1702
base: main
Are you sure you want to change the base?
Conversation
3db98e1
to
d368670
Compare
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.
SubrangeMapper.map
looks a bit convoluted but seems like a useful method overall. I will re-review when the tests pass.
dace/subsets.py
Outdated
@@ -895,6 +909,10 @@ def size(self): | |||
def size_exact(self): | |||
return self.size() | |||
|
|||
def volume_exact(self) -> int: | |||
""" Returns the total number of elements in all dimenssions together. """ | |||
return reduce(operator.mul, self.size_exact()) |
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.
Is this compatible with all supported Python versions? Note that we also have another method that does the same in dace.data
:
Line 139 in 057a680
def _prod(sequence): |
Maybe it is a good idea to move (one of them) to a utility method.
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.
As far as I can tell, it does work for 3.7 and 3.12. Replaced with lambda function regardless, since that's how _prod
works.
I don't think it's necessary to make reduce(lambda a, b : a * b, sequence)
itself an utility function. It's really short, easy to see what it does. I've added the volume_exact()
function to just give that operation a meaningful name (i.e. why it does that). But of course, if you rather have it separately, I can move it too.
of elements they have.
Its functionality === Equipped with a `src` and a `dst` range of equal volumes but possibly different shapes or even dimensions (i.e., there is an 1-to-1 correspondence between the elements of `src` and `dst`), maps a subrange of `src` to its counterpart in `dst`, if possible. Note that such subrange-to-subrange mapping may not always exist.
more tests to cover everything.
8cc57a6
to
92b82a1
Compare
`operator.mul` with a lambda function.
I can try and rephrase the comments. If you have any suggestion on phrasing, please let me know.
The unit tests pass. For the CI tests, please check the last commit to see what I'm aiming for (note: this commit is incomplete, but is there just to demonstrate that with a few additional bug fixes, redundant array can be simplified a lot while at the same time correcting its behaviour). I'll try to trigger a CI run later. |
SubrangeMapper
helper class.SubrangeMapper
helper class which maps a _subrange_ of src
range to its counterpart in dst
range, if possible.
Equipped with a
src
and adst
range of equal volumes but possibly different shapes or even dimensions (i.e.,there is an 1-to-1 correspondence between the elements of
src
anddst
), maps a subrange ofsrc
to itscounterpart in
dst
, if possible (which is not always the case).It remains dead-code in this PR and not used anywhere at all. But it should help with correctly reshaping memlet subsets in a following PR (which will aim to fix
RedundantArray
transform by simplying it to something like this: https://github.com/pratyai/dace/blob/be571d21aa8abbc465daa11d04941040fbf93401/dace/transformation/dataflow/redundant_array.py#L426-L480).