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 :(得分:0)
正如您所指出的,您可以使用Eigen::Map
来包装连续的数据:
double *data = new...
Map<MatrixXd> mappedData(data, m, n);
mappedData.transposeInPlace(); // etc.
非连续数据必须连续成为copy in an Eigen object,或连续double*
并使用上述Map
。
您不能使用(映射/换行)非连续内存部分作为Eigen :: Matrix。如果您可以控制内存分配,则可以执行以下操作:
// 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