报错代码
MatrixXf m = MatrixXf::Random(3, 2);
JacobiSVD<MatrixXf, (ComputeThinU | ComputeThinV)> svd(m);
错误
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:666:3: required from ‘Eigen::JacobiSVD<MatrixType, QRPreconditioner>& Eigen::JacobiSVD<MatrixType, QRPreconditioner>::compute(const MatrixType&, unsigned int) [with _MatrixType = Eigen::Matrix<float, -1, -1>; int QRPreconditioner = 40; Eigen::JacobiSVD<MatrixType, QRPreconditioner>::MatrixType = Eigen::Matrix<float, -1, -1>]’
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:548:7: required from ‘Eigen::JacobiSVD<MatrixType, QRPreconditioner>::JacobiSVD(const MatrixType&, unsigned int) [with _MatrixType = Eigen::Matrix<float, -1, -1>; int QRPreconditioner = 40; Eigen::JacobiSVD<MatrixType, QRPreconditioner>::MatrixType = Eigen::Matrix<float, -1, -1>]’
/home/xu/school/usetools/src/use_eigen.cpp:18:62: required from here
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:656:45: error: ‘struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 0, true>’ has no member named ‘allocate’
656 | if(m_cols>m_rows) m_qr_precond_morecols.allocate(*this);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:657:45: error: ‘struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 1, true>’ has no member named ‘allocate’
657 | if(m_rows>m_cols) m_qr_precond_morerows.allocate(*this);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
make[2]: *** [CMakeFiles/useEigen.dir/build.make:63: CMakeFiles/useEigen.dir/src/use_eigen.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/useEigen.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
解决方法
将构造与分解分开进行。
MatrixXf m = MatrixXf::Random(3, 2);
JacobiSVD<MatrixXf> svd;
svd.compute(m, ComputeThinU | ComputeThinV);