Subindex using logical expression in Stan


I am wondering whether Stan allows subindexing a vector using logical expression like R. For example, suppose I have:

int<lower = 0> N;
int<lower = 0> K;
vector<lower=0> [N] y;
vector<lower=0> [N] index; //eg (1, 1,1,2,2,3...)

Are we allowed to use expression like the following to select certain ys according an logical expression criteria? If not, do we have alternative expressions available in Stan?

generated quantities{
vector<lower = 0> [K] z;
for (i in 1 : K){
z[i] = sum(y[index == i]);


Unfortunately this is not allowed in Stan at this time. Marking this as solved but feel free to continue the discussion.

Sure and I found that the discussion in this post Dealing with data subsetting in Stan - #7 by seantalts has some user-defined function to implement such purpose. Will the future version of Stan add this logical subsetting tool?

The only thing I know is that I am not aware of any such current efforts.

But this is an open source project so who knows, maybe someone is working on this we just dont know it yet :)