This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 1453

Summary: Strange behavior for Matrix::Map, if only InnerStride is provided
Product: Eigen Reporter: Christoph Hertzberg <chtz>
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: API Change CC: chtz, gael.guennebaud, jacob.benoit.1
Priority: Normal    
Version: 3.3 (current stable)   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 814    

Description Christoph Hertzberg 2017-08-02 12:28:32 UTC
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<2>()) << "\n\n";
    std::cout << MatrixXd::Map(data, 2, 3, InnerStride<>(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).
Comment 1 Christoph Hertzberg 2017-08-02 12:34:50 UTC
Actually, the expected behavior would be given by:
  Eigen::Stride<Eigen::Dynamic, 2>(2*2, 2)
> 0  4  8 
> 2  6 10

i.e., OuterStride == InnerStride*InnerSize
Comment 2 Gael Guennebaud 2017-08-22 10:54:30 UTC
This is indeed a bug. If no outer-stride is provided then it is automatically inferred from the sizes of the matrix. This is what says the doc. The problem is that inner-stride is assumed to be 1 in the respective code, which is clearly an unintentional shortcoming that needs to be fixed.
Comment 4 Nobody 2019-12-04 17:07:19 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1453.