#include "pinv.h" #include #include template void igl::pinv( const Eigen::MatrixBase & A, typename DerivedA::Scalar tol, Eigen::PlainObjectBase & X) { Eigen::JacobiSVD svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV ); typedef typename DerivedA::Scalar Scalar; const Eigen::Matrix & U = svd.matrixU(); const Eigen::Matrix & V = svd.matrixV(); const Eigen::Matrix & S = svd.singularValues(); if(tol < 0) { const Scalar smax = S.array().abs().maxCoeff(); tol = (Scalar)(std::max(A.rows(),A.cols())) * (smax-std::nextafter(smax,std::numeric_limits::epsilon())); } const int rank = (S.array()>0).count(); X = (V.leftCols(rank).array().rowwise() * (1.0/S.head(rank).array()).transpose()).matrix()* U.leftCols(rank).transpose(); } template void igl::pinv( const Eigen::MatrixBase & A, Eigen::PlainObjectBase & X) { return pinv(A,-1,X); }