2 #include <eigen3/Eigen/LU> 3 #include <eigen3/Eigen/SVD> 9 if ((1 == matrix.rows()) && (1 == matrix.cols())) {
10 invMatrix.resize(1, 1);
11 if (matrix.coeff(0, 0) > sigmaThreshold) {
12 invMatrix.coeffRef(0, 0) = 1.0 / matrix.coeff(0, 0);
14 invMatrix.coeffRef(0, 0) = 0.0;
19 Eigen::JacobiSVD<DMat<T>> svd(matrix,
20 Eigen::ComputeThinU | Eigen::ComputeThinV);
22 int const nrows(svd.singularValues().rows());
25 for (
int ii(0); ii < nrows; ++ii) {
26 if (svd.singularValues().coeff(ii) > sigmaThreshold) {
27 invS.coeffRef(ii, ii) = 1.0 / svd.singularValues().coeff(ii);
34 invMatrix = svd.matrixV() * invS * svd.matrixU().transpose();
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
void pseudoInverse(DMat< T > const &matrix, double sigmaThreshold, DMat< T > &invMatrix)