4#ifndef SVMP_FE_MATH_DENSELINEARALGEBRA_H
5#define SVMP_FE_MATH_DENSELINEARALGEBRA_H
17namespace svmp::FE::math {
48 double multiplier =
double(64)) noexcept;
65 double largest_singular_value,
66 double multiplier =
double(64)) noexcept;
73 double largest_singular_value{0};
74 double smallest_retained_singular_value{0};
126 double pivot_tolerance{0};
136 [[nodiscard]]
bool empty() const noexcept {
return n == 0; }
142 void solve_in_place(std::span<double> rhs)
const;
148 void solve_in_place(std::span<double> rhs, std::size_t rhs_count)
const;
154 [[nodiscard]] std::vector<double> solve(std::span<const double> rhs)
const;
171 std::span<const double> matrix,
174 std::string_view error_message_label =
"dense matrix");
187 std::string_view error_message_label =
"dense matrix");
200 std::string_view error_message_label =
"dense matrix");
213 std::vector<double> matrix,
215 std::string_view error_message_label =
"dense matrix");
227 const DenseInverseResult& result,
228 std::size_t expected_rank,
229 std::string_view error_message_label =
"dense matrix",
256 std::span<const double> matrix,
259 std::string_view error_message_label =
"dense matrix");
Fundamental type definitions for the finite element library.
DenseInverseResult invert_dense_matrix_with_diagnostics(std::vector< double > matrix, std::size_t n, std::string_view error_message_label)
Invert a dense square matrix with diagnostics, using an SVD fallback for high-condition matrices.
Definition DenseLinearAlgebra.cpp:199
double dense_matrix_pivot_tolerance(std::size_t rows, std::size_t cols, double max_abs, double multiplier) noexcept
Scale-aware pivot tolerance for dense factorization.
Definition DenseLinearAlgebra.cpp:59
std::vector< double > invert_dense_matrix(std::vector< double > matrix, std::size_t n, std::string_view error_message_label)
Invert a dense square matrix.
Definition DenseLinearAlgebra.cpp:263
double dense_matrix_singular_value_tolerance(std::size_t rows, std::size_t cols, double largest_singular_value, double multiplier) noexcept
Scale-aware singular-value tolerance for rank decisions.
Definition DenseLinearAlgebra.cpp:69
std::size_t dense_matrix_rank(std::vector< double > matrix, std::size_t rows, std::size_t cols)
Numerical rank of a dense matrix from its singular values.
Definition DenseLinearAlgebra.cpp:273
void validate_dense_inverse_diagnostics(const DenseInverseResult &result, std::size_t expected_rank, std::string_view error_message_label, double max_condition)
Validate that a dense inverse has full rank and acceptable conditioning.
Definition DenseLinearAlgebra.cpp:243
double dense_matrix_condition_error_threshold() noexcept
Condition estimate above which validation rejects a dense inverse.
Definition DenseLinearAlgebra.cpp:83
double dense_matrix_max_abs(std::span< const double > matrix) noexcept
Largest absolute entry of a dense matrix.
Definition DenseLinearAlgebra.cpp:51
DensePseudoInverseResult rank_revealing_pseudo_inverse(std::span< const double > matrix, std::size_t rows, std::size_t cols, std::string_view error_message_label)
Moore-Penrose pseudo-inverse via a rank-revealing SVD.
Definition DenseLinearAlgebra.cpp:298
double dense_matrix_condition_fallback_threshold() noexcept
Condition estimate above which the inverse switches to an SVD fallback.
Definition DenseLinearAlgebra.cpp:79
DenseMatrixDiagnostics dense_matrix_diagnostics(std::span< const double > matrix, std::size_t rows, std::size_t cols, std::string_view error_message_label)
SVD-based rank and conditioning diagnostics for a dense matrix.
Definition DenseLinearAlgebra.cpp:117
DenseLUSolver factor_dense_matrix(std::vector< double > matrix, std::size_t n, std::string_view error_message_label)
LU-factor a dense square matrix.
Definition DenseLinearAlgebra.cpp:157
A dense inverse together with its diagnostics.
Definition DenseLinearAlgebra.h:87
std::vector< double > inverse
Row-major inverse.
Definition DenseLinearAlgebra.h:88
bool used_svd_fallback
True when an SVD fallback was used for a high-condition matrix.
Definition DenseLinearAlgebra.h:90
DenseMatrixDiagnostics diagnostics
Conditioning/rank diagnostics of the input.
Definition DenseLinearAlgebra.h:89
Definition DenseLinearAlgebra.cpp:42
LU factorization of a dense square matrix with a cached pivot summary.
Definition DenseLinearAlgebra.h:114
bool empty() const noexcept
Whether the factorization is empty (n == 0).
Definition DenseLinearAlgebra.h:136
std::unique_ptr< Impl > impl
Eigen factorization (pimpl).
Definition DenseLinearAlgebra.h:130
std::string error_message_label
Prefix for solve-time exception messages.
Definition DenseLinearAlgebra.h:129
DenseMatrixDiagnostics diagnostics
Pivot-derived diagnostics (rank, tolerance).
Definition DenseLinearAlgebra.h:125
SVD-based conditioning and rank diagnostics for a dense matrix.
Definition DenseLinearAlgebra.h:78
std::size_t rank
Numerical rank at tolerance.
Definition DenseLinearAlgebra.h:79
double condition_estimate
Condition estimate; infinite when rank-deficient.
Definition DenseLinearAlgebra.h:83
double tolerance
Singular-value tolerance used.
Definition DenseLinearAlgebra.h:80
double smallest_retained_singular_value
Smallest singular value kept.
Definition DenseLinearAlgebra.h:82
double largest_singular_value
Largest singular value.
Definition DenseLinearAlgebra.h:81
Result of a rank-revealing pseudo-inverse.
Definition DenseLinearAlgebra.h:69
std::vector< double > inverse
Row-major pseudo-inverse.
Definition DenseLinearAlgebra.h:70