Armadillo: Obtain raw data from matrix/vector as array
armadillo, c++
Solution
There is no function to return an array of pointers. You can access the underlying buffer with the `memptr()` method:
float *a = A.memptr();
You can also get a pointer to any matrix column with the `colptr()` method. I'm not sure why you might need an array of pointers but you could build one like this (uncompiled and untested code):
std::vector<float *> av;
av.reserve(A.n_cols);
for (unsigned int i = 0; i < A.n_cols; ++i)
av.push_back() = A.colptr(i);
float **a = &av[0]; // a remains valid while av is in scope
Note that Armadillo stores data in column-major order.
Problem
I am searching for something like this: ``` fmat A = randu<fmat>(4,5); float **a = A.to_array(); // Return matrix as float** ``` Does anybody know how one could do this in `Armadillo`?