我正在尝试编译为Eigen::JacobiSVD提供的示例,但出现以下错误,
\n/usr/local/include/eigen3/Eigen/src/SVD/JacobiSVD.h: In instantiation of \xe2\x80\x98Eigen::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>]\xe2\x80\x99:\n/usr/local/include/eigen3/Eigen/src/SVD/JacobiSVD.h:549:14: required from \xe2\x80\x98Eigen::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>]\xe2\x80\x99\ndemo.cpp:9:55: required from here\n/usr/local/include/eigen3/Eigen/src/SVD/JacobiSVD.h:692:27: error: \xe2\x80\x98struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 0, true>\xe2\x80\x99 has no member named \xe2\x80\x98run\xe2\x80\x99\n m_qr_precond_morecols.run(*this, m_scaledMatrix);\n ~~~~~~~~~~~~~~~~~~~~~~^~~\n/usr/local/include/eigen3/Eigen/src/SVD/JacobiSVD.h:693:27: error: \xe2\x80\x98struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 1, true>\xe2\x80\x99 has no member named \xe2\x80\x98run\xe2\x80\x99\n m_qr_precond_morerows.run(*this, m_scaledMatrix);\nRun Code Online (Sandbox Code Playgroud)\n你能帮我解决这个问题吗?谢谢
\n代码 :
\n#include <Eigen/Core>\n#include <Eigen/SVD>\n#include <iostream>\nusing namespace std;\nusing namespace Eigen;\nint main () {\n MatrixXf m = MatrixXf::Random(3,2);\n cout << "Here is the matrix m:" << endl << m << endl;\n JacobiSVD<MatrixXf, ComputeThinU | ComputeThinV> svd(m);\n cout << "Its singular values are:" << endl << svd.singularValues() << endl;\n cout << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl;\n cout << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl;\n Vector3f rhs(1, 0, 0);\n cout << "Now consider this rhs vector:" << endl << rhs << endl;\n cout << "A least-squares solution of m*x = rhs is:" << endl << svd.solve(rhs) << endl;\n}\nRun Code Online (Sandbox Code Playgroud)\n克++:7.5
\n本征:3.4.0
\nHom*_*512 14
这看起来很像一个错误。我查看了代码,没有办法运行。我将提交错误报告。
作为一种解决方法,即使它被标记为已弃用,它也应该有效:
JacobiSVD<MatrixXf> svd;
svd.compute(m, ComputeThinU | ComputeThinV);
Run Code Online (Sandbox Code Playgroud)
根本问题是,在模板专业化期间,代码不会将计算选项与 QR 预处理器选项分开。所以没有找到合适的实现。
问题在于在线文档和当前版本之间存在差异。该文档适用于 3.4.90,但最后发布的版本是 3.4.0。
在 3.4.90 中,计算参数必须在模板或运行时参数中声明,但不能同时声明。
在 3.4.0 及更早版本中,必须在运行时参数中声明计算选项。
// works in all versions but deprecation warning in 3.4.90
Eigen::JacobiSVD<Eigen::MatrixXf> svd;
svd.compute(m, Eigen::ComputeThinV | Eigen::ComputeThinU);
// or
Eigen::JacobiSVD<Eigen::MatrixXf> svd(m, Eigen::ComputeThinV | Eigen::ComputeThinU);
// works in 3.4.90
Eigen::JacobiSVD<Eigen::MatrixXf, Eigen::ComputeThinV | Eigen::ComputeThinU> svd;
svd.compute(m);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1351 次 |
| 最近记录: |