Quick question, can I assign a vector as a single element in an array of reals?

For bringing a vector into the integrate_ode function, could I assign the vector as a single element in an array of reals x_r? For example,

data {
    vector[5] test_vector;
}

transformed data {
    real x_r[10];
    x_r[1] = test_vector;
}

Is that a possible operation? If not, the plan was to use the to_array_1d function to convert the vector into an array of reals.

No, sorry, right now you’ve got to manually pack and unpack everything from 1d arrays. It’s awkward.

We’re working on something right now to address this problem (Variadic argument lists for ODEs by bbbales2 · Pull Request #1641 · stan-dev/math · GitHub) but that won’t be finished until later this year (knock on wood).

Hi @bbbales2, thanks for your help again. So, I take it that it would also be impossible to assign an array of reals to a single element in x_r? Best way then would be to write a for loop that assigns individual elements from test_vector to x_r per iteration?

Only way, unfortunately.

Roger that, thank you!

The to_array_1d function will work, although it only saves you a few keystrokes.

rstan::lookup("to_array_1d")

Sorry, @bgoodri, for clarification, you’re saying assigning an array of reals to an individual element of x_r will work?

I just meant coercing a vector to a one-dimensional array of reals works. It will still be unpacked.