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
diff --git a/internal/ceres/invert_psd_matrix.h b/internal/ceres/invert_psd_matrix.h index 50b357c..78ee45b 100644 --- a/internal/ceres/invert_psd_matrix.h +++ b/internal/ceres/invert_psd_matrix.h
@@ -60,11 +60,12 @@ // // https://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html#title3 if (assume_full_rank) { - if (kSize > 0 && kSize < 5) { + if constexpr (kSize > 0 && kSize < 5) { return m.inverse(); + } else { + return m.template selfadjointView<Eigen::Upper>().llt().solve( + MType::Identity(size, size)); } - return m.template selfadjointView<Eigen::Upper>().llt().solve( - MType::Identity(size, size)); } // For a thin SVD the number of columns of the matrix need to be dynamic.