akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
vector_norms.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
10#include "norm_traits.hpp"
11
12namespace linalg {
13
23template <FieldVector Vec>
24struct L2 {
28
29 constexpr codomain_type operator()(const domain_type& x) const {
31 const auto squared_norm = inner_product(x, x);
32 if constexpr (Real<scalar_type>) result = squared_norm;
33 else {
35 "L2 complex norm expects real inner product");
36 result = squared_norm.real();
37 }
39 }
40};
41
51template <FieldVector Vec>
52struct L1 {
56
57 constexpr codomain_type operator()(const domain_type& x) const {
59 for (const auto& _x : x) sum += constexpr_abs(_x);
60 return sum;
61 }
62};
63
73template <FieldVector Vec>
74struct Linf {
78
79 constexpr codomain_type operator()(const domain_type& x) const {
80 codomain_type mx = 0;
81 for (const auto& _x : x) mx = std::max(mx, constexpr_abs(_x));
82 return mx;
83 }
84};
85
86} // namespace linalg
#define AK_ASSERT(x)
Definition assert.hpp:13
Field classified by scalar_traits as real.
constexpr auto inner_product(const Vec &lhs, const Vec &rhs)
Evaluate the canonical inner product for two field vectors.
std::remove_cvref_t< T > remove_cvref_t
Remove top-level const, volatile, and reference qualification.
typename vector_traits_t< Vec >::element_type vector_element_t
Registered vector coordinate type.
typename scalar_traits_t< T >::real_type real_type_t
Associated real component type registered for T.
constexpr T constexpr_abs(T x)
Compute real absolute value or complex magnitude.
constexpr T constexpr_sqrt_safe(T x, T floor=T(0), T g=1e-10, T tol=1e-10)
Return a scalar square root with a sanitized fallback radicand.
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
constexpr bool is_real(const std::complex< T > &z, real_type_t< T > tol=1e-10)
Check whether a complex value's imaginary component is below a bound.
forward declaration for L1 norm
constexpr codomain_type operator()(const domain_type &x) const
remove_cvref_t< Vec > domain_type
vector_element_t< domain_type > scalar_type
real_type_t< scalar_type > codomain_type
forward declaration for L2 norm
vector_element_t< domain_type > scalar_type
remove_cvref_t< Vec > domain_type
real_type_t< scalar_type > codomain_type
constexpr codomain_type operator()(const domain_type &x) const
forward declaration for Linf norm
constexpr codomain_type operator()(const domain_type &x) const
remove_cvref_t< Vec > domain_type
real_type_t< scalar_type > codomain_type
vector_element_t< domain_type > scalar_type