Hi Christoph,
Thank you for the response. I think the access within the function masked the real problem we are having.
The issue: matrix multiplication does not behave like other _expression_ templates, e.g. transpose, Map.
Example function (bar.hpp):
------------------------------------------------------------
#include <Eigen/Dense>
#include <iostream>
template <typename Derived>
void bar(const Eigen::MatrixBase<Derived>& a) {
std::cout << "a(0): " << a(0) << std::endl;
}
------------------------------------------------------------
Example that works:
------------------------------------------------------------
#include "bar.hpp"
int main() {
Eigen::MatrixXd u(1,1);
u << 1;
Eigen::MatrixXd v(1,2);
v << 1, 2;
bar((u*v).transpose());
bar((u*v).transpose().transpose());
return 0;
}
------------------------------------------------------------
Example that does not work, but I expect to work:
------------------------------------------------------------
#include "bar.hpp"
int main() {
Eigen::MatrixXd u(1,1);
u << 1;
Eigen::MatrixXd v(1,2);
v << 1, 2;
bar(u*v);
return 0;
}
------------------------------------------------------------
This results in:
> ./a.out
Assertion failed: (this->rows() == 1 && this->cols() == 1), function coeff, file /Users/daniel/dev/stan/lib/eigen_3.2.2/Eigen/src/Core/ProductBase.h, line 150.
a(0): Abort trap: 6
I am not expecting this assertion failure. With EIGEN2_SUPPORT defined, this assertion goes away.
Question: did we do something incorrectly with the definition of the function bar?
Thanks again.
Daniel