tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_matrix_frob_norm.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_MATRIX_FROB_NORM_HPP
5#define TETL_LINALG_BLAS1_MATRIX_FROB_NORM_HPP
6
7#include <etl/_cmath/sqrt.hpp>
8#include <etl/_linalg/concepts.hpp>
9#include <etl/_type_traits/declval.hpp>
10#include <etl/_utility/cmp_less.hpp>
11
12namespace etl::linalg {
13
14/// \ingroup linalg
15template <in_matrix InMat, typename Scalar>
16[[nodiscard]] constexpr auto matrix_frob_norm(InMat a, Scalar init) -> Scalar
17{
18 auto result = init;
19 for (typename InMat::size_type row{0}; etl::cmp_less(row, a.extent(0)); ++row) {
20 for (typename InMat::size_type col{0}; etl::cmp_less(col, a.extent(1)); ++col) {
21 result += detail::abs_if_needed(a(row, col));
22 }
23 }
24
25 using etl::sqrt;
26 return static_cast<Scalar>(sqrt(result));
27}
28
29/// \ingroup linalg
30template <in_matrix InMat>
31[[nodiscard]] constexpr auto matrix_frob_norm(InMat a)
32{
33 using abs_type = decltype(detail::abs_if_needed(declval<typename InMat::value_type>()));
34 using return_type = decltype(declval<abs_type>() * declval<abs_type>());
35 return matrix_frob_norm(a, return_type{});
36}
37
38} // namespace etl::linalg
39
40#endif // TETL_LINALG_BLAS1_MATRIX_FROB_NORM_HPP
constexpr auto matrix_frob_norm(InMat a, Scalar init) -> Scalar
Definition blas1_matrix_frob_norm.hpp:16
constexpr auto matrix_frob_norm(InMat a)
Definition blas1_matrix_frob_norm.hpp:31
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9