Skip to content
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

Support minmax reductions? #14770

Closed
ronawho opened this issue Jan 16, 2020 · 13 comments
Closed

Support minmax reductions? #14770

ronawho opened this issue Jan 16, 2020 · 13 comments

Comments

@ronawho
Copy link
Contributor

ronawho commented Jan 16, 2020

We have min and max reductions, but no way to get both at once. You can get the min and max separately but you end up looking through your array twice. You can optimize this by manually writing the loop yourself, but it's not as clean/simple:

var A: [1..10] int = 1..10;

// Clean-ish, but goes through the array twice
{
  var aMin = min reduce A;
  var aMax = max reduce A;
  writeln((aMin, aMax));
}

// Uglier, but faster
{
  // I usually incorrectly write `var aMin, aMax: int`, which leads to subtle bugs
  var aMin = max(int); 
  var aMax = min(int);
  forall a in A with (min reduce aMin, max reduce aMax) {
    aMin reduce= a;
    aMax reduce= a;
  }
  writeln((aMin, aMax));
}

It seems attractive to be able to do something like:

var (aMin, aMax) = minmax reduce A;

Finding both min and max is a pretty common idiom idiom in arkouda. Reductions are fast enough that I don't think it's a major bottleneck, but it would save some time.

@bradcray

This comment has been minimized.

@bradcray
Copy link
Member

(it also could beg the question whether we'd want a minmaxlocs reduction that was like minloc and maxloc combined).

@masterashu

This comment has been minimized.

@bradcray
Copy link
Member

To get you started, I'd suggest looking at modules/internal/ChapelReduce.chpl, look at how the min and MinReduceOp and MaxReduceOp classes are defined, and add a similar class named minmax. Doing so ought to permit you to write minmax reduce ... test/thomasvandoren/mink.chpl (and the nearby tests that use it) may also be a good reference point. Sorry there's not better documentation on writing these operations, but it shouldn't be too hard to pattern-match against what others have done and get it working, I believe. Ask questions if not.

@rahulghangas

This comment has been minimized.

rahulghangas pushed a commit to rahulghangas/chapel that referenced this issue Jan 19, 2020
Implements feature request in chapel-lang#14770.
Returns a 2-tuple with the first element being the corresponding minimum and the second element being the maximum.
rahulghangas pushed a commit to rahulghangas/chapel that referenced this issue Jan 19, 2020
Implements feature request in chapel-lang#14770.
Returns a 2-tuple with the first element being the corresponding minimum and the second element being the maximum.
@masterashu

This comment has been minimized.

@klakho0400

This comment has been minimized.

@rahulghangas

This comment has been minimized.

@klakho0400

This comment has been minimized.

@bradcray
Copy link
Member

bradcray commented Jun 8, 2020

@ronawho: PR #15062 implements minmax reductions (and should be merged soon). This made me go looking for places in Arkouda where they could be used, and I'm finding cases in:

(though there may be others as well).

This raises the perennial question about whether we should open a PR to be merged after the next release, or drop in a helper file that implements the minmax reduction as a placeholder, or file an issue reminding ourselves to do this change after the next release goes out).

@ronawho
Copy link
Contributor Author

ronawho commented Jun 9, 2020

I don't think minmax is a big bottleneck, but I'd still be in favor of getting that into arkouda. Can we just drop in a duplicate minmax class into arkouda and have that take precedence over the builtin one that will be on master, or will that be ambiguous? If it's ambiguous I'd probably just name it akminmax with a comment saying "can use builtin minmax once 1.23 is required"

vasslitvinov pushed a commit that referenced this issue Jun 9, 2020
Implements feature request in #14770.

A minmax reduction returns a 2-tuple with the first element being
the corresponding minimum and the second element being the maximum.

Implemented by @rahulghangas 
Reviewed and merged by @bradcray @vasslitvinov
@vasslitvinov
Copy link
Member

Resolved by #15062

@bradcray
Copy link
Member

bradcray commented Jun 9, 2020

Can we just drop in a duplicate minmax class into arkouda and have that take precedence over the builtin one that will be on master, or will that be ambiguous?

I believe if it's put into an Arkouda file that's explicitly used, this should work. But calling it akminmax may result in less confusion while achieving the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants