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// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
5#define TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
6
7#include <etl/_limits/numeric_limits.hpp>
8#include <etl/_linalg/concepts.hpp>
9#include <etl/_type_traits/is_arithmetic.hpp>
10#include <etl/_utility/cmp_less.hpp>
11
12namespace etl::linalg {
13
14/// \ingroup linalg
15template <in_vector InVec>
16constexpr auto idx_abs_max(InVec v) -> typename InVec::size_type
17{
18 constexpr auto getValue = [](typename InVec::value_type const& val) {
19 if constexpr (is_arithmetic_v<typename InVec::value_type>) {
20 return detail::abs_if_needed(val);
21 } else {
22 auto const re = detail::abs_if_needed(detail::real_if_needed(val));
23 auto const im = detail::abs_if_needed(detail::imag_if_needed(val));
24 return re + im;
25 }
26 };
27
28 auto idx = numeric_limits<typename InVec::size_type>::max();
29 auto maxV = numeric_limits<decltype(getValue(v(0)))>::min();
30
31 for (typename InVec::size_type i{0}; etl::cmp_less(i, v.extent(0)); ++i) {
32 if (auto const val = getValue(v(i)); val > maxV) {
33 idx = i;
34 maxV = val;
35 }
36 }
37
38 return idx;
39}
40
41} // namespace etl::linalg
42
43#endif // TETL_LINALG_BLAS1_VECTOR_IDX_ABS_MAX_HPP
constexpr auto idx_abs_max(InVec v) -> typename InVec::size_type
Definition blas1_vector_idx_abs_max.hpp:16
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9
Definition numeric_limits.hpp:18