Skip to content

Add generic container reductions#62

Merged
inducer merged 6 commits into
inducer:mainfrom
alexfikl:reduce-array-container
Jul 16, 2021
Merged

Add generic container reductions#62
inducer merged 6 commits into
inducer:mainfrom
alexfikl:reduce-array-container

Conversation

@alexfikl

Copy link
Copy Markdown
Collaborator

This adds some helpers to do reductions over array containers.

  • adds a generic rec_reduce_array_container(reduce_func, array_func, ary) function.
  • uses that in actx.np.[sum, min, max].

Fixes #61.

@alexfikl alexfikl force-pushed the reduce-array-container branch from 4cb52b5 to d5e67e7 Compare July 15, 2021 15:26
@alexfikl alexfikl force-pushed the reduce-array-container branch from d5e67e7 to 36b2a65 Compare July 15, 2021 15:33

@kaushikcfd kaushikcfd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left some high-level design choice questions.

Comment thread arraycontext/container/traversal.py Outdated
Comment thread arraycontext/container/traversal.py Outdated

@inducer inducer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few comments below.

Comment thread arraycontext/container/traversal.py Outdated
Comment thread arraycontext/container/traversal.py Outdated
Comment thread arraycontext/container/traversal.py Outdated
Comment thread arraycontext/container/traversal.py Outdated
def _map_array_container_impl(
f: Callable[[Any], Any],
ary: ArrayContainerT, *,
reduce_func: Callable[[Any, Iterable[Tuple[Any, Any]]], Any] = None,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, not sure I'm loving this. (Writing this after reading much of the rest of this PR.) Why not make something specific to reductions instead of trying to generalize this by force? (via lots of inefficient function wrapping)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inducer The main reason I did it like this was because _multimap_array_container_impl has a lot more logic in there that I felt squimish about largely copy pasting for the reduction case. I can add an if in there to avoid the wrapping. What do you think?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. How about this: Duplicate map, but leave the wild wrap-and-dispatch thing in place for multimap? I can't really think of a "pretty" way to deal with this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 94e7c6f.

@inducer

inducer commented Jul 16, 2021

Copy link
Copy Markdown
Owner

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

@alexfikl alexfikl requested a review from inducer July 16, 2021 20:21

@inducer inducer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo, otherwise LGTM. Thanks for working on this! @kaushikcfd?

Comment thread arraycontext/container/traversal.py Outdated

@kaushikcfd kaushikcfd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great to me! The same piece of logic was being re-used at multiple places and this provides a nice primitive for it.

Co-authored-by: Andreas Klöckner <inform@tiker.net>
@inducer inducer enabled auto-merge (squash) July 16, 2021 22:28
@inducer

inducer commented Jul 16, 2021

Copy link
Copy Markdown
Owner

🎉 In it goes.

@alexfikl

Copy link
Copy Markdown
Collaborator Author

Thanks, this looks great to me! The same piece of logic was being re-used at multiple places and this provides a nice primitive for it.

Thanks for taking a look!

@inducer inducer merged commit 1261641 into inducer:main Jul 16, 2021
@alexfikl alexfikl deleted the reduce-array-container branch July 16, 2021 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make a utility for reduction over array container structures

3 participants