Hugely enjoying working with Stan here!

I have a computation that I have been struggling to find a way to vectorise (and that I suspect cannot be vectorised) and therefore wanted to hear if anyone has clever ideas about how to do this as efficiently as possible.

Briefly, I have an array of k reals, and another array of k [n,m] matrices. I need to multiply each matrix by the corresponding real, and then compute the sum of these k, scaled matrices. This can be done by looping like this:

```
data {
int n; int m; int k;
matrix[n, m] M[k];
real theta[k];
}
transformed data {
matrix[n,m] Msum;
Msum = rep_matrix(0,n,m);
for (i in 1:k) {
Msum = Msum + theta[i] * M[i];
}
}
```

Is there a better (possibly vectorised) way of doing this? Any pointers or ideas hugely appreciated!

Thanks,

Anders