【发布时间】:2014-06-27 01:56:47
【问题描述】:
对于稠密矩阵,下面的代码解决 x^T A = b^T 就好了。
Matrix3d A;
RowVector3d bT, xT;
A << 1, 2, 3,
0, 5, 6,
0, 0, 9;
bT << 1, 2, 3;
xT = A.triangularView<Upper>().solve<OnTheRight>(bT);
printf("(%g, %g, %g)", xT(0), xT(1), xT(2));
但是,我无法将这种方法继续用于稀疏矩阵。
SparseMatrix<double> spA = A.sparseView();
spA.triangularView<Upper>().solve<OnTheRight>(bT); // COMPILE ERR!
spA.triangularView<Upper>().solve<OnTheRight>(bT.sparseView()); // COMPILE ERR!
编译错误是
no matching function for call to ‘Eigen::SparseTriangularView<Eigen::SparseMatrix<double, 0>, 2>::solve(Eigen::RowVector3d&) const’
no matching function for call to ‘Eigen::SparseTriangularView<Eigen::SparseMatrix<double, 0>, 2>::solve(const Eigen::SparseView<Eigen::Matrix<double, 1, 3> >) const’
candidate is:
template<class OtherDerived> typename Eigen::internal::plain_matrix_type_column_major<OtherDerived>::type Eigen::SparseTriangularView::solve(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = OtherDerived, MatrixType = Eigen::SparseMatrix<double, 0>, int Mode = 2, typename Eigen::internal::plain_matrix_type_column_major<OtherDerived>::type = Eigen::internal::plain_matrix_type_column_major<T>::type]
我在文档中找不到答案,谁能弄清楚如何做到这一点?
EDIT SparseTriangularView::solve 既不接受 OnTheLeft 也不接受 OnTheRight 作为 模板参数,但我只是尝试忽略该参数,它似乎可以编译。我的猜测是它是一个缺失的功能,因此已将其报告给开发人员。如果他们确认,我会将他们的回复作为答案发布。
【问题讨论】:
标签: c++ matrix eigen sparse-matrix triangular