Is there an easy way to wrap a double** in a c++ Eigen typ so that it can be used in Eigen expressions? As far as I know, the Eigen::Map class only supports double*. The storage where double** points to is not guaranteed to be continuous.
0
votes
1 Answers
0
votes
As you pointed out, you can use an Eigen::Map to wrap contiguous data:
double *data = new...
Map<MatrixXd> mappedData(data, m, n);
mappedData.transposeInPlace(); // etc.
Non-contiguous data has to be made contiguous, either as a copy in an Eigen object, or as a contiguous double* and using a Map as above.
Edit
You can't use (map/wrap) a non-contiguous section of memory as an Eigen::Matrix. If you have control of the memory allocation, you can do something like:
// make contiguous data array; better yet, make an
// Eigen::VectorXd of the same size to ensure alignment
double *actualData = new double[m*n];
double **columnPointers = new double[n];
for(int i = 0; i < n; ++i) columnPointers[i] = actualData + i * m;
... // do whatever you need to do with the double**
Map<MatrixXd> mappedData(actualData, m, n);
... // send to ceres, or whatever
Eigen::Mapwith a C array. The storage where thedouble**points to is not guaranteed to be continuous. - Jodebodouble**is not a matrix, assuming array decay, it's an array of arrays at best. It doesn't guarantee rectangular size, which is pretty important for a matrix, that's a bigger problem IMO. - luk32