New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 1453 - Strange behavior for Matrix::Map, if only InnerStride is provided
Summary: Strange behavior for Matrix::Map, if only InnerStride is provided
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal API Change
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3.4
  Show dependency treegraph
 
Reported: 2017-08-02 12:28 UTC by Christoph Hertzberg
Modified: 2017-08-22 11:28 UTC (History)
3 users (show)



Attachments

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.

Note You need to log in before you can comment on or make changes to this bug.