Skip to content

algorithms: expose Proj parameter in hpx::min/max/minmax_element CPOs#7230

Open
aneek22112007-tech wants to merge 1 commit intoTheHPXProject:masterfrom
aneek22112007-tech:feat/minmax-projection-support
Open

algorithms: expose Proj parameter in hpx::min/max/minmax_element CPOs#7230
aneek22112007-tech wants to merge 1 commit intoTheHPXProject:masterfrom
aneek22112007-tech:feat/minmax-projection-support

Conversation

@aneek22112007-tech
Copy link
Copy Markdown
Contributor

Summary

This PR exposes the Proj (projection) parameter in the public Customization Point Objects (CPOs) for hpx::min_element, hpx::max_element, and hpx::minmax_element.

Previously, while the internal detail layer supported projections, the public parallel CPO overloads hardcoded hpx::identity_v. This change brings these algorithms into alignment with the std::ranges design and ensures consistency with the existing hpx::ranges container algorithms.

Technical Details

CPO Updates

  • Updated all six tag_fallback_invoke overloads for each algorithm in libs/core/algorithms/include/hpx/parallel/algorithms/minmax.hpp.
  • Added a Proj template parameter (defaulting to hpx::identity) to support the standard projection API across all execution policies (including seq, par, and async variations).
  • Integrated hpx::parallel::traits::is_projected_v and hpx::parallel::traits::is_indirect_callable_v constraints to ensure strict type checking and improved error diagnostics at the CPO boundary.

Type Deduction Fix

  • Resolved a regression in element_type deduction within sequential_minmax_element_ind.
  • The previous deduction logic using std::iter_value_t<FwdIter>& was insufficient for the parallel reduction phase, where FwdIter refers to an iterator over partition results rather than the base elements.
  • Restored the decltype(HPX_INVOKE(proj, *it)) pattern to correctly resolve the proxy value type when merging partition results.

Testing

  • Added three new regression test files: min_element_proj.cpp, max_element_proj.cpp, and minmax_element_proj.cpp.
  • Test coverage includes:
    • Projecting member variables from custom structs/pairs.
    • Value transformations (e.g., negating values to invert min/max logic).
    • Verification of projection forwarding in seq(task) async policies.
    • Edge cases (empty ranges, single-element ranges, and all-equal elements).
  • Confirmed that all existing min_element, max_element, and minmax_element unit tests pass.

Checklist

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; it uses a seed and the generated numbers are valid.

@StellarBot
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@aneek22112007-tech aneek22112007-tech force-pushed the feat/minmax-projection-support branch 2 times, most recently from ef665ad to 264e948 Compare April 28, 2026 11:29
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 28, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@aneek22112007-tech aneek22112007-tech force-pushed the feat/minmax-projection-support branch from 264e948 to 426ac05 Compare April 28, 2026 12:03
Comment thread libs/core/algorithms/include/hpx/parallel/algorithms/minmax.hpp Outdated
Comment thread libs/core/algorithms/include/hpx/parallel/algorithms/is_partitioned.hpp Outdated
This commit adds projection tests for the std::ranges::minmax_element equivalent in HPX (hpx::ranges::minmax_element) to ensure it correctly handles projections in both sequential and parallel contexts. It also moves the existing minmax_element_parallel_projection.cpp test to the container_algorithms directory where it belongs.
@aneek22112007-tech aneek22112007-tech force-pushed the feat/minmax-projection-support branch from 426ac05 to f1e0dd0 Compare April 28, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants