This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1343 - Matrix expressions cannot be used to initialize ArrayXd
Summary: Matrix expressions cannot be used to initialize ArrayXd
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - expression templates (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-17 20:00 UTC by Yixuan Qiu
Modified: 2019-12-04 16:31 UTC (History)
3 users (show)



Attachments

Description Yixuan Qiu 2016-11-17 20:00:26 UTC
Hi All,

I just found an issue that newly appeared in the 3.3 version. The problem is that a matrix-vector multiplication cannot be used to initialize an ArrayXd object. See the minimal example below:

=====================================================================

#include <Eigen/Core>

using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::ArrayXd;

int main()
{
    MatrixXd m1 = MatrixXd::Random(10, 10);
    VectorXd v1 = VectorXd::Random(10);
    
    ArrayXd a1 = v1;       // This is fine
    ArrayXd a2 = m1 * v1;  // OK on 3.2 but fails on 3.3
    
    return 0;
}

=====================================================================

OS: Fedora 25 64-bit
Compiler: GCC 6.2/clang 3.8



Thank you.


Best,
Yixuan
Comment 1 Yixuan Qiu 2016-11-17 20:09:09 UTC
A possibly related one:

=====================================================================

#include <Eigen/Core>

using Eigen::MatrixXd;

int main()
{
    MatrixXd m1 = MatrixXd::Random(10, 10);
    
    MatrixXd m2 = m1.selfadjointView<Eigen::Lower>(); // Fine
    MatrixXd m3 = MatrixXd::Zero(10, 10);
    m3 += m1.selfadjointView<Eigen::Lower>(); // Fails on 3.3
    
    return 0;
}

=====================================================================


Maybe coming from the new mechanism of expression evaluation?


Best,
Yixuan
Comment 2 Gael Guennebaud 2016-11-18 09:20:22 UTC
For the 1st one, the problem is that in 3.2, the expression turned out to be evaluated as:

ArrayXd a2 = (m1*v1).eval()

(this was not the case if a2 is a VectorXf). In 3.3, the implementation is more general, and it thus reveals this issue. Fixed:

https://bitbucket.org/eigen/eigen/commits/25c392fdbf64/
3.3: https://bitbucket.org/eigen/eigen/commits/669d7bf13a67/

For the second one, the generic EigenBase2EigenBase assignment was lacking -= and +=, fixed:

https://bitbucket.org/eigen/eigen/commits/0e78c04fea69/
3.3: https://bitbucket.org/eigen/eigen/commits/9b63b9758a3f/
Comment 3 Yixuan Qiu 2016-11-18 14:02:12 UTC
Thank you Gael!
Comment 4 Nobody 2019-12-04 16:31:06 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/1343.

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