Bugzilla – Bug 447
seg fault on (A * B)(0, 0)
Last modified: 2012-04-18 18:48:37 UTC
When I multiply two matrices and index into the product (without saving it to a matrix variable) I get a segmentation fault. The following program reproduces the problem for me. Note it seems to be some sort of infinite recursion.
Eigen::MatrixXd A (1, 3);
A << 1, 2, 3;
Eigen::MatrixXd B (3, 1);
B << 4, 5, 6;
double p = (A * B)(0, 0);
I am using x86-64 Linux and GCC 4.6.2 with Eigen 3.0.5.
Thanks for the report. This is indeed an infinite recursion in ProductBase::coeff(), triggered by a product of dynamic-size matrices. Note that you can only index into a product if the result has size 1-by-1. This bug has been bresent for a while.
One possible fix is to restrict indexing for *fixed-size* products of size 1-by-1. But this gives a difference between fixed and dynamic size which seems unnecessary. I implemented another fix and added a regression test (changeset 2bba8cc484ad for Eigen 3.0 and 0c2dd64f0b25 for Eigen 3.1)
Thanks Jitse for fixing it.
To Bowie, since you know that A and B are vectors, you should really use vectors: huge speed up expected.