This forum has been archived. All content is frozen. Please use KDE Discuss instead.

transposeInPlace() on Eigen::Map

Tags: None
(comma "," separated)
Xavier
Registered Member
Posts
3
Karma
0

transposeInPlace() on Eigen::Map

Mon Feb 24, 2014 9:19 am
I am not quite sure if it's a bug or if I'm doing something wrong, but the following code:

Code: Select all
#include <Eigen/Dense>
using Eigen::Map;
using Eigen::MatrixXi;

int main() {
   // Create an array of integers 0 to 9
   int* dat = new int[10];
   for (int i = 0; i < 10; i++) {
      dat[i] = i;
   }

   // Map it in a 2x5 matrix
   Map<MatrixXi> m(dat, 2, 5);
   
   // Transpose in place
   m.transposeInPlace();
   
   delete[] dat;
   return 0;
}
compiles fine with g++ 4.6 - 4.8 on Ubuntu / Mac respectively, but when I run I get the following error:

Code: Select all
/path-to-eigen/Eigen/src/Core/Assign.h:498: Derived& Eigen::DenseBase<Derived>::lazyAssign(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<int, -0x00000000000000001, -0x00000000000000001, 1, -0x00000000000000001, -0x00000000000000001>, Derived = Eigen::Map<Eigen::Matrix<int, -0x00000000000000001, -0x00000000000000001> >]: Assertion `rows() == other.rows() && cols() == other.cols()' failed.


It works fine with rectangular matrices and with non-map matrices.
Am I missing something obvious here?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is because you cannot resize a Map. Perhaps Map::resize could be allowed if rows*cols does not change...
Xavier
Registered Member
Posts
3
Karma
0
Thanks for your answer!

In practice, what should I do? Can I for instance define a map m2 with transposed dimensions and transpose it there with something like:

Code: Select all
   Map<MatrixXi> m2(dat, 5, 2);
   m2 = m1.transpose().eval();


This apparently works with my simple test case, will it always be the case?

Ultimately it would be nice if transposeInPlace would work on rectangular maps... but as I don't know why one can't resize a map (and wasn't even aware of it), so I'll leave it up to you to decide. Should I open a feature request?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: transposeInPlace() on Eigen::Map

Mon Feb 24, 2014 10:30 am
Yes please, add a feature request in the bugtracker. Map does not hold its memory, so there are strong restrictions on what resize could do. Your use case seems ok to me, but let's see what the others think about it.
Xavier
Registered Member
Posts
3
Karma
0

Re: transposeInPlace() on Eigen::Map

Mon Feb 24, 2014 10:44 am
Ok, posted here: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=749
Thanks a lot,
Xavier


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]