Hi! I am not sure if the way I define a function return multiple values and the way I call it makes sense in Stan? Thanks for your help!
real foo(real x) {
return 1.0, 2.0, 3.0;
}
model{
...
a,b,c = foo(x)
...
}
Hi! I am not sure if the way I define a function return multiple values and the way I call it makes sense in Stan? Thanks for your help!
real foo(real x) {
return 1.0, 2.0, 3.0;
}
model{
...
a,b,c = foo(x)
...
}
That won’t work. Instead you could change the return type to “vector” (or a real array) and then return that. Which you can then unpack after calling.
May I double check with you, so the form like
vector foo(real x) {
vector[3] u;
u[1] = 1.0;
u[2] = 2.0;
u[3] = 3.0;
return u;
}
will work?
Yep. Or
u = [1, 2, 3]’;