You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Return value of thrust::minmax_element differs from STL's minmax_element #699
In both STL and thrust a call to minmax_element returns a pair of iterators, the first points to the minimum and the second to the maximum value. In both STL and thrust, if more than run minimum exists, the first value is chosen. If more than one maximum value exists, the STL version chooses the last candidate while thrust chooses the first one. While I think the STL is quite inconsistent here, I'd still prefer if thrust would behave just like the STL
changed the title [-]Return value of minmax_element differs form STL's minmax_element[/-][+]Return value of minmax_element differs from STL's minmax_element[/+]on Mar 7, 2023
thrust::minmax_element will select the first maximum element whereas std::minmax_element picks the last.
fwiw, std::minmax_element and std::max_element are frustratingly inconsistent:
std::minmax_element:
If several elements are equivalent to the largest element, the iterator to the last such element is returned.
std::max_element:
If several elements in the range are equivalent to the greatest element, returns the iterator to the first such element.
In contrast, Thrust is self-consistent between thrust::minmax_element and thrust::max_element:
thrust::minmax_element
It returns a pair of iterators (imin, imax) where imin is the same iterator returned by min_element and imax is the same iterator returned by max_element.
While I agree it would be good for Thrust to be consistent with std:: here, this would be a breaking change and one that is changing to arguably worse behavior... I'll keep the issue open for now, but I don't expect this is something we'll be doing anytime soon.
Thx for looking into this. I worked back in 2016 when I was still a student with thrust, but I haven't looked much into it after finishing that particular course.
Ebedded C programming and IoT is now the domain I'm most active in. I have to admit that by now I have even forgotten to ever file issues here :-(
changed the title [-]Return value of minmax_element differs from STL's minmax_element[/-][+]Return value of thrust::minmax_element differs from STL's minmax_element[/+]on Aug 9, 2026
Activity
[-]Return value of minmax_element differs form STL's minmax_element[/-][+]Return value of minmax_element differs from STL's minmax_element[/+]jrhemstad commentedon Mar 7, 2023
Confirmed that this difference in behavior still exists: https://godbolt.org/z/dqzxKEYzM
thrust::minmax_elementwill select the first maximum element whereasstd::minmax_elementpicks the last.fwiw,
std::minmax_elementandstd::max_elementare frustratingly inconsistent:std::minmax_element:std::max_element:In contrast, Thrust is self-consistent between
thrust::minmax_elementandthrust::max_element:thrust::minmax_elementWhile I agree it would be good for Thrust to be consistent with
std::here, this would be a breaking change and one that is changing to arguably worse behavior... I'll keep the issue open for now, but I don't expect this is something we'll be doing anytime soon.maribu commentedon Mar 7, 2023
Thx for looking into this. I worked back in 2016 when I was still a student with thrust, but I haven't looked much into it after finishing that particular course.
Ebedded C programming and IoT is now the domain I'm most active in. I have to admit that by now I have even forgotten to ever file issues here :-(
[-]Return value of minmax_element differs from STL's minmax_element[/-][+]Return value of thrust::minmax_element differs from STL's minmax_element[/+]