akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
symmetric_matrix.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
11
12namespace linalg {
13
20template <SquareMatrix Mat>
21struct SymmetricMatrix : SymmetricOperator<Mat, SymmetricMatrix<Mat>> {
27
30 using SymmetricBase::N;
31
40 constexpr explicit SymmetricMatrix(const Mat& A, ScalarT tol = 1e-8)
41 : SymmetricBase(A) {
42 factor(A, tol);
43 }
44
45private:
54 constexpr void factor(const Mat& A, const ScalarT& tol) {
55 // (0) First see if the incoming matrix is symmetric
56 bool valid = false;
57 if constexpr (Real<T>) valid = all_equal(A, transpose(A));
59
60 // (1) No need to set data for invalid one and set type
61 // likewise if it is symmetric we can store it temporarily
62 // as indefinite one
63 if (!valid) {
65 return;
66 }
67
68 // (2) Next calculate the eigenvalues of the matrix and check signs of the
69 // eigenvalues by running count
70 const auto eig_decomp = EigenDecomposition(A);
71 if (!eig_decomp.converged) {
73 return;
74 }
75
76 // (3) Compute definiteness of matrix
77 this->compute_definiteness(eig_decomp.lambda, tol);
78 }
79};
80
81} // namespace linalg
Field classified by scalar_traits as real.
constexpr auto conjugate_transpose(const Mat &A)
conjugate transpose of a matrix
constexpr auto transpose(const Vec &x)
tranpose of a vector
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
constexpr bool all_equal(const Vec &X, const Vec &Y, real_type_t< vector_element_t< Vec > > tol=1e-10)
checks if two vectors are equivalent to a given tolerance (different than == operator on vector which...
std::complex< ScalarT > ComplexT
matrix_scalar_t< Mat > T
alias helpers for types
static constexpr std::size_t N
helper to extract N
real_type_t< T > ScalarT
forward declaration for a matrix
constexpr SymmetricMatrix(const Mat &A, ScalarT tol=1e-8)
CTOR.
forward declaration for symmetric operator
static constexpr std::size_t DIM
helpers to get DIM from mat
constexpr void compute_definiteness(const Vector< DiagT, N > &diag, const ScalarT &tol)
compute definiteness