MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / min_element_if

Function min_element_if

src/include/migraphx/algorithm.hpp:81–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80template <class Iterator, class Predicate, class Compare>
81Iterator min_element_if(Iterator first, Iterator last, Predicate pred, Compare comp)
82{
83 auto it = std::min_element(first, last, [&](const auto& a, const auto& b) {
84 // Check if elements are valid
85 bool a_valid = pred(a);
86 bool b_valid = pred(b);
87
88 // If neither is valid, prefer a (doesn't matter)
89 if(not a_valid and not b_valid)
90 return false;
91
92 // If only b is valid, it should be selected
93 if(not a_valid)
94 return false;
95
96 // If only a is valid, it should be selected
97 if(not b_valid)
98 return true;
99
100 // Both are valid, select the smaller one using comparator
101 return comp(a, b);
102 });
103 if(it != last and pred(*it))
104 return it;
105 return last;
106}
107
108template <class Iterator, class Output, class Predicate>
109void group_by(Iterator start, Iterator last, Output out, Predicate pred)

Callers 2

swap_closer_axesMethod · 0.85

Calls 1

min_elementFunction · 0.85

Tested by

no test coverage detected