Common issues
Invalid read (C++ only)
Referenced in Issue 307
Issue
When doing operations on matrices and vectors, Eigen doesn’t evaluate the value of the result unless it is required.
This behavior can lead to an ‘invalid read’ issue when the result of an operation is stored in a variable with an auto type.
For example the following code raises an invalid read :
Matrix m ({{0.5,0.5},{0.,1.}});
IntervalVector b ({1.,2.});
auto B1 = m.inverse()*b;
auto B2 = inverse_enclosure(m)*b;
auto boo = B1.is_subset(B2); // invalid read here
Explanation
See https://libeigen.gitlab.io/eigen/docs-nightly/TopicPitfalls.html#TopicPitfalls_auto_keyword
Fix
Explicitly declare the type that you are expecting. For example the previous code becomes :
Matrix m ({{0.5,0.5},{0.,1.}});
IntervalVector b ({1.,2.});
IntervalVector B1 = m.inverse()*b;
IntervalVector B2 = inverse_enclosure(m)*b;
auto boo = B1.is_subset(B2); // no more invalid read