tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_vector_idx_abs_max.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
4#define TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
5
10
11namespace etl::linalg {
12
14template <in_vector InVec>
15constexpr auto idx_abs_max(InVec v) -> typename InVec::size_type
16{
17 constexpr auto getValue = [](typename InVec::value_type const& val) {
19 return detail::abs_if_needed(val);
20 } else {
21 auto const re = detail::abs_if_needed(detail::real_if_needed(val));
22 auto const im = detail::abs_if_needed(detail::imag_if_needed(val));
23 return re + im;
24 }
25 };
26
28 auto maxV = numeric_limits<decltype(getValue(v(0)))>::min();
29
30 for (typename InVec::size_type i{0}; etl::cmp_less(i, v.extent(0)); ++i) {
31 if (auto const val = getValue(v(i)); val > maxV) {
32 idx = i;
33 maxV = val;
34 }
35 }
36
37 return idx;
38}
39
40} // namespace etl::linalg
41
42#endif // TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
constexpr auto min(Type const &a, Type const &b, Compare comp) noexcept -> Type const &
Returns the smaller of a and b, using a compare function.
Definition min.hpp:13
constexpr auto idx_abs_max(InVec v) -> typename InVec::size_type
Definition blas1_vector_idx_abs_max.hpp:15
constexpr auto cmp_less(T t, U u) noexcept -> bool
Compare the values of two integers t and u. Unlike builtin comparison operators, negative signed inte...
Definition cmp_less.hpp:21
Definition accessor_conjugate.hpp:12
constexpr bool is_arithmetic_v
Definition is_arithmetic.hpp:21
Definition numeric_limits.hpp:17
static constexpr auto max() noexcept
Definition numeric_limits.hpp:21