tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_vector_two_norm.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_LINALG_BLAS1_VECTOR_TWO_NORM_HPP
4
#define TETL_LINALG_BLAS1_VECTOR_TWO_NORM_HPP
5
6
#include <
etl/_cmath/sqrt.hpp
>
7
#include <
etl/_linalg/concepts.hpp
>
8
#include <
etl/_type_traits/declval.hpp
>
9
#include <
etl/_utility/cmp_less.hpp
>
10
11
namespace
etl::linalg
{
12
14
template
<in_vector InVec,
typename
Scalar>
15
constexpr
auto
vector_two_norm
(InVec v, Scalar init)
noexcept
-> Scalar
16
{
17
auto
sum = init;
18
for
(
typename
InVec::size_type i{0};
etl::cmp_less
(i, v.extent(0)); ++i) {
19
auto
const
val = detail::abs_if_needed(v(i));
20
auto
const
square = val * val;
21
sum += square;
22
}
23
24
using
etl::sqrt
;
25
return
static_cast<
Scalar
>
(
sqrt
(sum));
26
}
27
29
template
<in_vector InVec>
30
constexpr
auto
vector_two_norm
(InVec v)
noexcept
->
typename
InVec::value_type
31
{
32
using
abs_type =
decltype
(detail::abs_if_needed(
declval<typename InVec::value_type>
()));
33
using
value_type =
decltype
(
declval<abs_type>
() *
declval<abs_type>
());
34
return
vector_two_norm
(v, value_type{});
35
}
36
37
}
// namespace etl::linalg
38
39
#endif
// TETL_LINALG_BLAS1_VECTOR_TWO_NORM_HPP
concepts.hpp
cmp_less.hpp
declval.hpp
etl::sqrt
constexpr auto sqrt(float arg) noexcept -> float
Computes the square root of arg.
Definition
sqrt.hpp:14
etl::linalg::vector_two_norm
constexpr auto vector_two_norm(InVec v, Scalar init) noexcept -> Scalar
Definition
blas1_vector_two_norm.hpp:15
etl::cmp_less
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
etl::linalg
Definition
accessor_conjugate.hpp:12
etl::declval
auto declval() noexcept -> add_rvalue_reference_t< T >
sqrt.hpp
include
etl
_linalg
blas1_vector_two_norm.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0