Skip to content

Strange behavior for Matrix::Map, if only InnerStride is provided

Submitted by Christoph Hertzberg

Assigned to Nobody

Link to original bugzilla bug (#1453)
Version: 3.3 (current stable)

Description

I don't know if that is intended, or if providing only InnerStride was supposed to work only for 1D-Maps:

const double data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};  



std::cout << "Unexpected behavior:\n";  

std::cout << MatrixXd::Map(data, 2, 3, InnerStride&lt;2&gt;()) << "\n\n";  

std::cout << MatrixXd::Map(data, 2, 3, InnerStride&lt;&gt;(2)) << "\n\n";  



std::cout << "Expected behavior:\n";  

std::cout << MatrixXd::Map(data, 2, 3, Stride<Eigen::Dynamic, 2>(2*3, 2)) << "\n\n";  

Output:

Unexpected behavior:

0 2 4

2 4 6

0 2 4

2 4 6

Expected behavior:

0 6 12

2 8 14

The solution would be to multiply the (current) outerStride by the innerStride, unless the outerStride is explicitly given. As this would silently break API (although only in cases which are unlikely intended), I don't want to change it without asking first.

An alternative solution would be to prohibit providing InnerStride only, unless the Map is 1-dimensional. This could also break code, but it would result in compile errors (which then could be easily fixed).

Blocking

#814