The following two posts are very helpful but not quite what I need:
However, I need to create a row-major C array (see 2) from an Eigen::MatrixXd, and I need to be able to specify the dimensions at run-time. Meaning, I'm making an interface that lets me pass an Eigen::MatrixXd to be converted along with it's dimensions and preallocated target C array.
This works but is column-major,
void eigen_matrixXd_to_double_array(const Eigen::MatrixXd& evector, double* destination, uint32_t nrow, uint32_t ncol)
{
Eigen::Map<Eigen::MatrixXd>(destination,nrow,ncol) = evector;
}
I want something like:
void eigen_matrixXd_to_double_array(const Eigen::MatrixXd& evector, double* destination, uint32_t nrow, uint32_t ncol)
{
Eigen::Map<Eigen::Matrix<double, nrow, ncol, Eigen::RowMajor>>(destination,nrow,ncol) = evector;
}
or,
void eigen_matrixXd_to_double_array(const Eigen::MatrixXd& evector, double* destination, uint32_t nrow, uint32_t ncol)
{
Eigen::Map<Eigen::MatrixXd<Eigen::RowMajor>>(destination,nrow,ncol) = evector;
}
but neither of these work...
Any suggestions? Is it possible for me to make a row-major mapping with programmatic dimensions (realizing that the user of the C interface must get the dims correct)?
Thanks in advance...