次のコード スニペットは、Eigen アサートによって停止します。
MatrixXd L;
VectorXd x, b;
...
ASSERT_MATRIX_EQ(L*x, b);
と、
template <typename DerivedL, typename DerivedR>
void ASSERT_MATRIX_EQ(const Eigen::DenseBase<DerivedL>& A, const Eigen::DenseBase<DerivedR>& B, double tol=1e-7) {
ASSERT_EQ(A.rows(), B.rows());
ASSERT_EQ(A.cols(), B.cols());
for(int i=0; i < A.rows(); i++) {
for(int j=0; j < A.cols(); j++) {
ASSERT_NEAR(A(i,j), B(i,j), tol);
}
}
}
次のエラーで終了します。
test_leq: /usr/include/eigen3/Eigen/src/Core/ProductBase.h:154: typename Base::CoeffReturnType Eigen::ProductBase<Eigen::GeneralProduct<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 4>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >::coeff(Index, Index) const: Assertion `this->rows() == 1 && this->cols() == 1' failed.
への呼び出しでA(i,j)
。(ただし、問題なく通話できますcout << A << endl;
。)
154行目に、ProductBase.h
不思議なことにアサーションがあります
// restrict coeff accessors to 1x1 expressions. No need to care about mutators here since this isnt a Lvalue expression
typename Base::CoeffReturnType coeff(Index row, Index col) const
{
#ifdef EIGEN2_SUPPORT
return lhs().row(row).cwiseProduct(rhs().col(col).transpose()).sum();
#else
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
eigen_assert(this->rows() == 1 && this->cols() == 1);
return derived().coeff(row,col);
#endif
}
一般的な行列関数を作成するための Eigen のガイドに従っています。このジェネリック関数を正しく記述するにはどうすればよいですか?
編集: がProductBase
1x1 行列を期待する理由を知っておくとよいでしょう。