xiehw
March 16, 2020, 4:20am
1
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).
xiehw
March 16, 2020, 3:00pm
3
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?
The to_array_1d
function will work, although it only saves you a few keystrokes.
rstan::lookup("to_array_1d")
xiehw
March 16, 2020, 5:46pm
7
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.