4#ifndef SVMP_COMMON_MATH_DENSELINEARALGEBRA_H
5#define SVMP_COMMON_MATH_DENSELINEARALGEBRA_H
46 double multiplier =
double(64)) noexcept;
63 double largest_singular_value,
64 double multiplier =
double(64)) noexcept;
112struct DenseLUSolver {
117 DenseLUSolver(DenseLUSolver&&)
noexcept;
118 DenseLUSolver& operator=(DenseLUSolver&&)
noexcept;
119 DenseLUSolver(
const DenseLUSolver&) =
delete;
120 DenseLUSolver& operator=(
const DenseLUSolver&) =
delete;
134 [[nodiscard]]
bool empty() const noexcept {
return n == 0; }
140 void solve_in_place(std::span<double> rhs)
const;
146 void solve_in_place(std::span<double> rhs, std::size_t rhs_count)
const;
152 [[nodiscard]] std::vector<double> solve(std::span<const double> rhs)
const;
169 std::span<const double> matrix,
172 std::string_view error_message_label =
"dense matrix");
185 std::string_view error_message_label =
"dense matrix");
198 std::string_view error_message_label =
"dense matrix");
211 std::vector<double> matrix,
213 std::string_view error_message_label =
"dense matrix");
225 const DenseInverseResult& result,
226 std::size_t expected_rank,
227 std::string_view error_message_label =
"dense matrix",
254 std::span<const double> matrix,
257 std::string_view error_message_label =
"dense matrix");
void validate_dense_inverse_diagnostics(const DenseInverseResult &result, std::size_t expected_rank, std::string_view error_message_label="dense matrix", double max_condition=dense_matrix_condition_error_threshold())
Validate that a dense inverse has full rank and acceptable conditioning.
Definition DenseLinearAlgebra.cpp:243
std::vector< double > invert_dense_matrix(std::vector< double > matrix, std::size_t n, std::string_view error_message_label="dense matrix")
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=double(64)) noexcept
Scale-aware singular-value tolerance for rank decisions.
Definition DenseLinearAlgebra.cpp:69
DenseMatrixDiagnostics dense_matrix_diagnostics(std::span< const double > matrix, std::size_t rows, std::size_t cols, std::string_view error_message_label="dense matrix")
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="dense matrix")
LU-factor a dense square matrix.
Definition DenseLinearAlgebra.cpp:157
double dense_matrix_condition_fallback_threshold() noexcept
Condition estimate above which the inverse switches to an SVD fallback.
Definition DenseLinearAlgebra.cpp:79
double dense_matrix_condition_error_threshold() noexcept
Condition estimate above which validation rejects a dense inverse.
Definition DenseLinearAlgebra.cpp:83
DenseInverseResult invert_dense_matrix_with_diagnostics(std::vector< double > matrix, std::size_t n, std::string_view error_message_label="dense matrix")
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=double(64)) noexcept
Scale-aware pivot tolerance for dense factorization.
Definition DenseLinearAlgebra.cpp:59
DensePseudoInverseResult rank_revealing_pseudo_inverse(std::span< const double > matrix, std::size_t rows, std::size_t cols, std::string_view error_message_label="dense matrix")
Moore-Penrose pseudo-inverse via a rank-revealing SVD.
Definition DenseLinearAlgebra.cpp:298
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
double dense_matrix_max_abs(std::span< const double > matrix) noexcept
Largest absolute entry of a dense matrix.
Definition DenseLinearAlgebra.cpp:51
A dense inverse together with its diagnostics.
Definition DenseLinearAlgebra.h:85
bool used_svd_fallback
True when an SVD fallback was used for a high-condition matrix.
Definition DenseLinearAlgebra.h:88
std::vector< double > inverse
Row-major inverse.
Definition DenseLinearAlgebra.h:86
DenseMatrixDiagnostics diagnostics
Conditioning/rank diagnostics of the input.
Definition DenseLinearAlgebra.h:87
Definition DenseLinearAlgebra.cpp:42
std::unique_ptr< Impl > impl
Eigen factorization (pimpl).
Definition DenseLinearAlgebra.h:128
double pivot_tolerance
Scale-aware pivot tolerance used.
Definition DenseLinearAlgebra.h:124
bool empty() const noexcept
Whether the factorization is empty (n == 0).
Definition DenseLinearAlgebra.h:134
double max_pivot
Largest pivot magnitude.
Definition DenseLinearAlgebra.h:126
double min_pivot
Smallest pivot magnitude.
Definition DenseLinearAlgebra.h:125
DenseMatrixDiagnostics diagnostics
Pivot-derived diagnostics (rank, tolerance).
Definition DenseLinearAlgebra.h:123
std::string error_message_label
Prefix for solve-time exception messages.
Definition DenseLinearAlgebra.h:127
std::size_t n
Matrix dimension.
Definition DenseLinearAlgebra.h:122
SVD-based conditioning and rank diagnostics for a dense matrix.
Definition DenseLinearAlgebra.h:76
double tolerance
Singular-value tolerance used.
Definition DenseLinearAlgebra.h:78
std::size_t rank
Numerical rank at tolerance.
Definition DenseLinearAlgebra.h:77
double smallest_retained_singular_value
Smallest singular value kept.
Definition DenseLinearAlgebra.h:80
double condition_estimate
Condition estimate; infinite when rank-deficient.
Definition DenseLinearAlgebra.h:81
double largest_singular_value
Largest singular value.
Definition DenseLinearAlgebra.h:79
Result of a rank-revealing pseudo-inverse.
Definition DenseLinearAlgebra.h:67
double largest_singular_value
Largest singular value.
Definition DenseLinearAlgebra.h:71
double tolerance
Singular-value tolerance used.
Definition DenseLinearAlgebra.h:70
double smallest_retained_singular_value
Smallest singular value kept.
Definition DenseLinearAlgebra.h:72
std::size_t rank
Numerical rank at the chosen tolerance.
Definition DenseLinearAlgebra.h:69
std::vector< double > inverse
Row-major pseudo-inverse.
Definition DenseLinearAlgebra.h:68