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
3#ifndef TETL_LINALG_BLAS1_MATRIX_FROB_NORM_HPP
4#define TETL_LINALG_BLAS1_MATRIX_FROB_NORM_HPP
5
6#include <etl/_cmath/sqrt.hpp>
10
11namespace etl::linalg {
12
14template <in_matrix InMat, typename Scalar>
15[[nodiscard]] constexpr auto matrix_frob_norm(InMat a, Scalar init) -> Scalar
16{
17 auto result = init;
18 for (typename InMat::size_type row{0}; etl::cmp_less(row, a.extent(0)); ++row) {
19 for (typename InMat::size_type col{0}; etl::cmp_less(col, a.extent(1)); ++col) {
20 result += detail::abs_if_needed(a(row, col));
21 }
22 }
23
24 using etl::sqrt;
25 return static_cast<Scalar>(sqrt(result));
26}
27
29template <in_matrix InMat>
30[[nodiscard]] constexpr auto matrix_frob_norm(InMat a)
31{
32 using abs_type = decltype(detail::abs_if_needed(declval<typename InMat::value_type>()));
33 using return_type = decltype(declval<abs_type>() * declval<abs_type>());
34 return matrix_frob_norm(a, return_type{});
35}
36
37} // namespace etl::linalg
38
39#endif // TETL_LINALG_BLAS1_MATRIX_FROB_NORM_HPP
constexpr auto sqrt(float arg) noexcept -> float
Computes the square root of arg.
Definition sqrt.hpp:14
constexpr auto matrix_frob_norm(InMat a, Scalar init) -> Scalar
Definition blas1_matrix_frob_norm.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
auto declval() noexcept -> add_rvalue_reference_t< T >