New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1380 - Matrix exponential does not work for mapped matrices
Matrix exponential does not work for mapped matrices
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Unsupported modules
3.3 (current stable)
All All
: Normal Compilation Problem
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-01-21 20:23 UTC by Yixuan Qiu
Modified: 2017-02-20 13:07 UTC (History)
2 users (show)



Attachments

Description Yixuan Qiu 2017-01-21 20:23:56 UTC
Hi All,

It looks like that on the 3.3 branch, matrix exponential (from the unsupported module) no longer works for mapped matrices. Below is an example, modified from the documentation:

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

#include <unsupported/Eigen/MatrixFunctions>
#include <iostream>
using namespace Eigen;
int main()
{
    const double pi = std::acos(-1.0);
    MatrixXd A(3, 3);
    A << 0,    -pi/4, 0,
         pi/4, 0,     0,
         0,    0,     0;
    std::cout << "The matrix A is:\n" << A << "\n\n";
    std::cout << "The matrix exponential of A is:\n" << A.exp() << "\n\n"; // fine

    Map<MatrixXd> B(A.data(), 3, 3);
    std::cout << "The matrix B is:\n" << B << "\n\n";
    std::cout << "The matrix exponential of B is:\n" << B.exp() << "\n\n"; // fails on Eigen 3.3

  return 0;
}

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

This is due to this line: https://bitbucket.org/eigen/eigen/src/0f635ff77c58/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h?at=default&fileviewer=file-view-default#MatrixExponential.h-354, where `MatrixType` is `Map<MatrixXd>` that does not have a default constructor.


Best,
Yixuan
Comment 2 Yixuan Qiu 2017-01-30 15:34:41 UTC
Thank you Gael.
Comment 3 Yixuan Qiu 2017-02-18 22:51:23 UTC
Hi Gael,

I have tried this patch, but it seems that the problem has not been fully resolved. I compiled the example code above under the newest 3.3 branch, and it generated the following errors:

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

./unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h:359:40: error: no matching function for call to ‘Eigen::internal::matrix_exp_computeUV<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, double>::run(const Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> > >::PlainObject&, Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> > >::PlainObject&, int&)’
   matrix_exp_computeUV<MatrixType>::run(arg, U, V, squarings); // Pade approximant is (U+V) / (-U+V)
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
./unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h:232:15: note: candidate: template<class ArgType> static void Eigen::internal::matrix_exp_computeUV<MatrixType, double>::run(const ArgType&, MatrixType&, MatrixType&, int&) [with ArgType = ArgType; MatrixType = Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >]
   static void run(const ArgType& arg, MatrixType& U, MatrixType& V, int& squarings)
               ^~~
./unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h:232:15: note:   template argument deduction/substitution failed:
./unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h:359:40: note:   cannot convert ‘U’ (type ‘Eigen::MatrixBase<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> > >::PlainObject {aka Eigen::Matrix<double, -1, -1>}’) to type ‘Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >&’
   matrix_exp_computeUV<MatrixType>::run(arg, U, V, squarings); // Pade approximant is (U+V) / (-U+V)

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


Thanks!


Best,
Yixuan
Comment 4 Gael Guennebaud 2017-02-20 13:07:55 UTC
Right, here is a more complete fix:

https://bitbucket.org/eigen/eigen/commits/cf029096b7b7/ (devel)
https://bitbucket.org/eigen/eigen/commits/a19f8531ea35/ (3.3)

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