mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Modernize InvertPSDMatrix with if constexpr
Use if constexpr for kSize checks in InvertPSDMatrix to allow for dead-code elimination at compile time. This ensures that for small fixed-size matrices, only the inverse() path is compiled, and for larger or dynamic matrices, only the LLT path is compiled when assume_full_rank is true. Change-Id: I4def2faadd080a4defccf1c0527015ae004f20ce
This commit is contained in:
@@ -60,12 +60,13 @@ typename EigenTypes<kSize, kSize>::Matrix InvertPSDMatrix(
|
|||||||
//
|
//
|
||||||
// https://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html#title3
|
// https://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html#title3
|
||||||
if (assume_full_rank) {
|
if (assume_full_rank) {
|
||||||
if (kSize > 0 && kSize < 5) {
|
if constexpr (kSize > 0 && kSize < 5) {
|
||||||
return m.inverse();
|
return m.inverse();
|
||||||
}
|
} else {
|
||||||
return m.template selfadjointView<Eigen::Upper>().llt().solve(
|
return m.template selfadjointView<Eigen::Upper>().llt().solve(
|
||||||
MType::Identity(size, size));
|
MType::Identity(size, size));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For a thin SVD the number of columns of the matrix need to be dynamic.
|
// For a thin SVD the number of columns of the matrix need to be dynamic.
|
||||||
using SVDMType = typename EigenTypes<kSize, Eigen::Dynamic>::Matrix;
|
using SVDMType = typename EigenTypes<kSize, Eigen::Dynamic>::Matrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user