I wish to pass an object created by the Ref class as an argument to the Map class to change a vector into a matrix without affecting its contents. For example, I have the function declaration:
double obj_fun(const Ref<const VectorXd>& params){
Map<MatrixXd> D(params.data(), 3, 2);
return 0.0;}
I have seen related questions such as Correct Usage of Eigen class and here but neither address how the Map class interacts with objects created by the Ref class. From the first question's answer, I can surmise that method six is amenable to changing a matrix's orientation but not its content, which would be akin to a declaration like
double obj_fun(Ref<VectorXd>&){(…)}
but that did not work.
Using the declaration in the conventional way as recommended by Eigen which I did in my code above or 'type 1' in the first linked question, produces the error "cannot convert argument 1 from 'const double *' to 'double *'" and a similar error ensues if I use the latter method (method 6 in the other question).
The only way in which to make it work is to do
double obj_fun(VectorXd& params) {(…)}
which seems silly as it goes against convention to declare memory addresses as constants. Hence, the only way out now seems to be to pass a physical copy to my function, which I'd like to avoid. However, I assume this is safer as otherwise I am leaving a memory address liable to be manipulated.