1#ifndef FUSED_ALGORITHMS_EIGEN_JACOBI_H
2#define FUSED_ALGORITHMS_EIGEN_JACOBI_H
69 template <
typename T, my_
size_t N>
100 template <
typename T, my_
size_t N>
106 static_assert(is_floating_point_v<T>,
107 "eigen_jacobi requires a floating-point scalar type");
111 return Unexpected{MatrixStatus::NotSymmetric};
121 for (
my_size_t iter = 0; iter < max_iters; ++iter)
159 T diff = W(p, p) - W(q, q);
166 s = (W(p, q) >= T(0)) ? inv_sqrt2 : -inv_sqrt2;
171 T tau = diff / (T(2) * W(p, q));
177 t = T(1) / (tau +
math::sqrt(T(1) + tau * tau));
181 t = T(-1) / (-tau +
math::sqrt(T(1) + tau * tau));
194 if (i == p || i == q)
199 W(i, p) = c * wip + s * wiq;
200 W(i, q) = -s * wip + c * wiq;
210 W(p, p) = c * c * wpp + T(2) * c * s * wpq + s * s * wqq;
211 W(q, q) = s * s * wpp - T(2) * c * s * wpq + c * c * wqq;
220 V(i, p) = c * vip + s * viq;
221 V(i, q) = -s * vip + c * viq;
226 return Unexpected{MatrixStatus::NotConverged};
A discriminated union holding either a success value or an error.
Definition expected.h:86
Definition fused_matrix.h:12
bool isSymmetric(void) const
Definition fused_matrix.h:292
FusedMatrix & setIdentity(void)
Definition fused_matrix.h:234
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
#define PRECISION_TOLERANCE
Tolerance for floating-point comparisons (e.g. symmetry checks, Cholesky).
Definition config.h:117
A minimal, STL-free expected/result type for failable operations.
Runtime property descriptors and error codes for matrices.
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
Expected< EigenResult< T, N >, MatrixStatus > eigen_jacobi(const FusedMatrix< T, N, N > &A, my_size_t max_iters=100, T tol=T(PRECISION_TOLERANCE))
Compute eigenvalues and eigenvectors of a symmetric matrix via Jacobi.
Definition eigen.h:101
MatrixStatus
Error codes for matrix decomposition and solver algorithms.
Definition matrix_traits.h:33
constexpr remove_reference_t< T > && move(T &&t) noexcept
Cast to rvalue reference (replacement for std::move).
Definition simple_type_traits.h:178
Tag type for constructing an Expected in the error state.
Definition expected.h:30
Result of eigenvalue decomposition.
Definition eigen.h:71
FusedMatrix< T, N, N > eigenvectors
Columns are eigenvectors (orthogonal).
Definition eigen.h:73
FusedVector< T, N > eigenvalues
Diagonal of D (unsorted).
Definition eigen.h:72