tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
norms.h
Go to the documentation of this file.
1#ifndef FUSED_ALGORITHMS_NORMS_H
2#define FUSED_ALGORITHMS_NORMS_H
3
4#include "config.h"
7#include "math/math_utils.h" // math::abs, math::sqrt
8
20namespace matrix_algorithms
21{
22
33 template <typename T, my_size_t N>
35 {
36 T max_col_sum = T(0);
37
38 for (my_size_t j = 0; j < N; ++j)
39 {
40 T col_sum = T(0);
41
42 for (my_size_t i = 0; i < N; ++i)
43 {
44 col_sum += math::abs(A(i, j));
45 }
46
47 if (col_sum > max_col_sum)
48 {
49 max_col_sum = col_sum;
50 }
51 }
52
53 return max_col_sum;
54 }
55
67 template <typename T, my_size_t N>
69 {
70 static_assert(is_floating_point_v<T>,
71 "norm2 requires a floating-point scalar type");
72
73 T sum_sq = T(0);
74
75 for (my_size_t i = 0; i < N; ++i)
76 {
77 sum_sq += v(i) * v(i);
78 }
79
80 return math::sqrt(sum_sq);
81 }
82
83} // namespace matrix_algorithms
84
85#endif // FUSED_ALGORITHMS_NORMS_H
Definition fused_matrix.h:12
Definition fused_vector.h:9
Global configuration for the tesseract tensor library.
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
constexpr T abs(T x) noexcept
Compute the absolute value of a numeric value.
Definition math_utils.h:48
constexpr T sqrt(T x) noexcept
Compute the square root of a floating-point value.
Definition math_utils.h:29
Definition cholesky.h:52
T norm2(const FusedVector< T, N > &v)
Compute the Euclidean (2-norm) of a vector: √(Σ vᵢ²).
Definition norms.h:68
T norm1(const FusedMatrix< T, N, N > &A)
Compute the 1-norm of a square matrix: max absolute column sum.
Definition norms.h:34