This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Eigen/Dense> | |
template <class MatT> | |
Eigen::Matrix<typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> | |
pseudoinverse(const MatT &mat, typename MatT::Scalar tolerance = typename MatT::Scalar{1e-4}) // choose appropriately | |
{ | |
typedef typename MatT::Scalar Scalar; | |
auto svd = mat.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV); | |
const auto &singularValues = svd.singularValues(); | |
Eigen::Matrix<Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime> singularValuesInv(mat.cols(), mat.rows()); |
NewerOlder