Registered Member
|
I'm reading http://eigen.tuxfamily.org/dox-devel/cl ... _1Ref.html. According to this page, I believe that this program [obviously change your eigen path], should work:
********** #include <iostream> #include "/Users/rif/tmp/eigen3.2.4/Eigen/Core" void PrintRowOrColumnConst(const Eigen::Ref<const Eigen::VectorXf>& v) { std::cout << v << "\n\n"; } int main(int argc, char** argv) { Eigen::MatrixXf M(3, 4); M << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12; // 1 2 3 4 // 5 6 7 8 // 9 10 11 12 std::cout << M << "\n\n"; PrintRowOrColumnConst(M.row(1)); } ********** M.row(1) doesn't reference contiguous data, so it should copy to a temporary. What actually happens is that we get a runtime crash about row and column sizes not matching, I assume because the function expects a VectorXf, which is an n-by-1 structure, and it gets a 1-by-n structure. So I think the webpage should *either* change * foo2(A.row()); // The row is copied into a contiguous temporary to * foo2(A.row().transpose()); // The row is copied into a contiguous temporary or should define its functions to take Ref<MatrixXf> rather than Ref<VectorXf>. Am I interpreting correctly? rif |
Moderator
|
You are perfectly right, we need to add a .transpose().
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]