E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ min_element

auto eve::algo::min_element = function_with_traits<min_element_>
inlineconstexpr

#include <eve/module/algo/algo/min_element.hpp>

Note
for equivalent elements we return the first amoung equal.
we assume that eve::is_less defined for your type is total order. (this comes up when switching min with max)

Alternative Header

#include <eve/algo.hpp>

Callable Signatures

namespace eve::algo
{
template<relaxed_range Rng, typename Less>
auto min_element(Rng&& rng, Less less) -> unaligned_iterator_t<Rng>; // 1
template<relaxed_range Rng>
auto min_element(Rng&& rng) -> unaligned_iterator_t<Rng>; // 2
}
unaligned_t< iterator_t< R > > unaligned_iterator_t
Unaligned iterator for a relaxed range.
Definition ranges_types.hpp:68
constexpr auto min_element
SIMD version of std::min_element
Definition min_element.hpp:256
  1. Returns the position of a minimum value, according to less. If the range is empty - returns past the end.
  2. Same as 1 but the less is eve::is_less

Parameters

  • rng: Relaxed input range to process
  • less: SIMD strict weak ordering.

Return value

iterator to min element (end if the range is empty).

Example

#include <eve/module/core.hpp>
#include <eve/module/algo.hpp>
#include <tts/tts.hpp> // as_string
#include <vector>
int main()
{
std::vector<int> v{ 2, -1, 4, -1, 0 };
std::cout << " -> v = "
<< tts::as_string(v)
<< "\n";
std::cout << " -> eve::algo::min_value(v) = "
<< *eve::algo::min_value(v) << "\n";
std::cout << " -> eve::algo::min_element(v) - v.begin() = "
<< eve::algo::min_element(v) - v.begin() << "\n";
std::cout << " -> eve::algo::min_value(v, eve::is_greater) = "
std::cout << " -> eve::algo::min_value(v, eve::is_greater) - v.begin() = "
<< eve::algo::min_element(v, eve::is_greater) - v.begin() << "\n";
auto absolutes = eve::views::map(v, eve::abs);
std::cout << " -> eve::algo::min_element[eve::algo::single_pass](absolutes) - absolutes.begin() = "
<< eve::algo::min_element[eve::algo::single_pass](absolutes) - absolutes.begin() << "\n";
}
constexpr auto single_pass
Trait that changes the algorithm for min_element/max_element for index tracking.
Definition traits.hpp:289
constexpr auto min_value
SIMD algorithm that returns minimum value in the range.
Definition min_value.hpp:100
constexpr auto abs
elementwise_callable object computing the absolute value of the parameter.
Definition abs.hpp:85
constexpr auto is_greater
elementwise callable returning a logical true if and only if the element value of the first parameter...
Definition is_greater.hpp:84
See also
min_value
max_element
Note
if you just need a value and not position, use eve::algo::min_value.

Can be one of two algorithms: one pass and two pass (default).

Two pass finds a value and then does a linear search for the value. This proves to be faster on smaller simpler arrays. By default unrolls by 4 and aligned all memory accesses.

The one pass version keeps track of index and is better suited for complicated predicates. You can opt in by using single_pass or expensive_callable traits. The single_pass opt-in will be aligning all data accesses