Vectorized if-else?

Hi everyone,

I am trying to vectorize a function on the functions block. However, at some point I need to make a decision based on an elementwise comparison. Something like:

vector foo(vector  y) {
real quantity;
int N = num_elements(y);
vector[N] z = if (y < quantity) {
do_something(y);
} else {
do_nothing(y);
}
return z;
}

Is there a workaround to implement this sort of thing in Stan? Or at the moment the only way to go would be to use a for loop on every element of my vector?

Thanks,
Tiago

Loop

1 Like

Thanks!