What I would like to do essentially is implement this function:
template<typename T>
Matrix<T, Dynamic, Dynamic, ColMajor>* dataToEigen(T* const data, const int rows, const int cols);
without copying any data. I know the standard way to accomplish something like this is with a Map, but I have several issues with this approach.
I don't want to rewrite the rest of my code to accept Maps as inputs (without copying the Map into a temporary matrix, that is). I know I could do this by generalizing my functions to take MatrixBase objects as inputs, but I've defined specific Matrix templates in my inputs for a reason - if my function takes a
Matrix<T, Dynamic, Dynamic, ColMajor>
, then it's because only matrices of that type should be used as inputs.Ideally, I'd like the created Matrix to take ownership of the data pointer, so I can just manage the Matrix via shared_ptr and not have to touch the original data pointer again.
My initial thought was that I could do something like create an uninitialized dynamically sized Matrix object, and then just set the object's dimensions and data pointer, but this doesn't seem to be possible in the Eigen API. Does anyone know of any workarounds?