cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
norm.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_COMPLEX_FUNCTIONS_NORM_H
4#define pRC_CORE_COMPLEX_FUNCTIONS_NORM_H
5
7
8namespace pRC
9{
10 template<Index P = 2, Index Q = P, class T>
11 static inline constexpr auto norm(Complex<T> const &a)
12 {
13 if constexpr(P == 1 && Q == 1)
14 {
15 return abs(a.real()) + abs(a.imag());
16 }
17 else if constexpr(P == 2 && Q == 1)
18 {
19 return a.real() * a.real() + a.imag() * a.imag();
20 }
21 else if constexpr(P == 2 && Q == 2)
22 {
23 return sqrt(norm<2, 1>(a));
24 }
25 else if constexpr(P != Q && Q == 0)
26 {
27 return norm<P, P>(a);
28 }
29 else
30 {
31 static_assert(P != P, "Unsupported p-norm.");
32 }
33 }
34}
35#endif // pRC_CORE_COMPLEX_FUNCTIONS_NORM_H
Definition complex.hpp:26
constexpr decltype(auto) real() &&
Definition complex.hpp:125
constexpr decltype(auto) imag() &&
Definition complex.hpp:145
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr auto abs(Complex< T > const &a)
Definition abs.hpp:12
static constexpr auto sqrt(Complex< T > const &a)
Definition sqrt.hpp:12
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11