I have a very general question not related to any particular Stan code. It deals with the distinction between a vector and a real and their incompatibility.
As far as I know, it is usually adviced to use vectors in order that, for example, operations like “-” can be vectorized. Thus, it seems good practice to use vectors instead of real when trying to avoid loops.
However, there are important functions, like the integrate_ode_rk45 function, which basically require the user to write a function signature containing a real and thus prohibiting the definition of a vector (afaik).
If I want to use the ODE-solver and if I at the same time require operations like “-” to be well defined (component-wise), then it seems to me like I am forced to constantly call functions like “to_vector()” or “to_array_1d()” in order to shift between the different aims of usage.
With respect to this setup, I have two questions:
- Does calling “to_vector” allocate a new vector, or does it reuse the old “real”. Closely related: Is it efficient to call these conversion functions or is there a significant cost to it?
- What is the generally recommended way to deal with the above setup?
Thank you very much for any hints/advices!