I have an n-dimensional data in C++ and would like to be able to have them in dynamic Eigen types (preferably without copying).
float** mydata = new float*[nDim]; // Number of dimensions
for (size_t i = 0; i < nDim; i++)
{
mydata[i] = new float[nRows*nCols];
// fill the data for each dimension
// ...
}
std::vector<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>> A(nDim);
for (size_t i = 0; i < nDim; i++)
{
A.at(i).resize(nRows, nCols);
// How can I map my n-dimensional data to Eigen matrices preferably without copying mydata?
// something like: A.at(i).data = mydata
}
Could someone kindly help me with this?
If you don't want to copy the data, you should use a bunch of Eigen::Map
s. This wraps the existing data with an Eigen object with the exception of things like resizing. You can save a list of Maps in a vector:
std::vector<Eigen::Map<Eigen::MatrixXf>> arrayOfMaps;
arrayOfMaps.reserve(nDims);
for (size_t i = 0; i < nDim; i++)
{
arrayOfMaps.push_back(Eigen::Map<Eigen::MatrixXf>(mydata[i], nRows, nCols));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments