Skip to content

Adding min_value, max_value and minmax_value - #132

Closed
sriramster wants to merge 2 commits into
jvdd:mainfrom
sriramster:value_helpers
Closed

sriramster wants to merge 2 commits into
jvdd:mainfrom
sriramster:value_helpers

Conversation

@sriramster

Copy link
Copy Markdown

This patch introduces and resolves the marked "todo" for the value helpers.

  • Added the min_value, max_value, minmax_value helper function.
  • Extend the unit tests to cover these newly introduce APIs,
  • Introduce the Item type in the trait to propagate the type information.

Sriram Raghunathan added 2 commits October 18, 2026 22:41
Adding the value helper implementation for the min, max
and minmax APIs. The approach is to use the underlying argmin,
argmax, and argminmax APIs to return the index and fetch the value
from the corresponding index.

Signed-off-by: Sriram Raghunathan <sriram@hcoop.net>
Signed-off-by: Sriram Raghunathan <sriram@hcoop.net>
@jvdd

jvdd commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR and the thorough tests! I'm going to pass on this one, though.

These helpers wrap argmin/argmax, so they're equivalent to data[data.argmin()]. That route is also the slower one for getting a value. A plain min/max (e.g. data.iter().min() or a simple fold) is most likely auto-vectorized into SIMD by the compiler. argmin/argmax are not, which is why this crate exists. A value-only SIMD min/max should also beat argmin/argmax, because it needs no index bookkeeping. So getting the value via the index adds overhead compared to what users can already get from std.

On top of that, adding an associated type plus required methods to the public ArgMinMax trait would be a breaking change for a convenience that's a one-liner today.

The old TODO was misleading; I'll remove it. If you have a use case where the compiler does not vectorize a value-only min/max well, so that dedicated SIMD kernels here would pay off, I'd be happy to discuss that in an issue first.

@jvdd jvdd closed this Oct 20, 2026
@sriramster

Copy link
Copy Markdown
Author

Thank you for the review and detailed explanation around this.

@jvdd

jvdd commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks a lot for taking the time to put this together, @sriramster. It was a pleasure to go through it, and I'm sorry it couldn't be merged.

If you hit a case where a value-only min/max doesn't vectorize well, or anything else, you're always welcome back! :)

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.

2 participants