Reputation: 385
I have written the following function:
template<typename mattype, typename vectype>
inline static boost::any ApplyCholesky(boost::any const& A, boost::any const& x) {
const Eigen::LLT<mattype>& chol = boost::any_cast<Eigen::LLT<mattype> const&>(A);
const mattype& mat = chol.matrixL();
const vectype& vec = boost::any_cast<vectype const&>(x);
assert(mat.cols()==vec.size());
vectype soln = mat.triangularView<Eigen::Lower>()*mat.transpose()*vec;
return soln;
}
Basically, I want to be able to call things like:
ApplyCholesky<Eigen::MatrixXd, Eigen::VectorXd>(A, x);
ApplyCholesky<Eigen::Matrix4d, Eigen::Vector4d>(A, x);
ApplyCholesky<Eigen::Matrix2f, Eigen::Vector2f>(A, x);
However, I get the following error:
error: expected expression
vectype soln = mat.triangularView<Eigen::Lower>()*mat.transpose()*vec;
I cannot figure out what I have done wrong. I have a similar ApplyInverseCholesky that solves the linear system (i.e., I need two functions: (i) y = A x and (ii) y = A^{-1} x) that has the the same error
Upvotes: 0
Views: 112
Reputation: 275405
vectype soln = mat.template triangularView<Eigen::Lower>()*mat.transpose()*vec;
it is parsing the <
as a less than and >
as greater than. Then it dies at the ()
.
This is because triangularView
being a template or not is dependent on the type of mat
. To simplify parsing, C++ states when a token could be a template, type or value depending on the type of an unbound template parameter, the parser should assume it is a value.
Programmers must use the typename
and template
keywords to disambiguate.
Upvotes: 3