Enable resize() on Maps when rows*cols doesn't change
Submitted by Xavier Robin
Assigned to Nobody
Link to original bugzilla bug (#749)
Version: 3.2
Platform: x86 - general
Description
Hope to phrase this correctly.
A typical use-case where one would like to allow resizing of a map is when calling transposeInPlace() on a rectangular Map<...>. Currently this fails because the resulting map has different dimensions than itself:
/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.
The following example (that currently produce the above error) ought to work though, as the dimensions of the data doesn't change it should be pretty safe to write:
#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;
}
This feature request was discussed here: http://forum.kde.org/viewtopic.php?f=74&t=119828