Simple syntax error row_vector /= real


Hi there, I am assuming this is a simple issue, I have a matrix ‘expectations’ I want to divide all the elements by the sums of the row. So I used the following code

int Y = 10;
int A = 8;
matrix[Y, A] expectations;
real year_total;
for (t in 1:Y) {
  year_total = sum(expectations[t,]);
  expectations[t,] /= year_total;

But get the following error ‘PARSER EXPECTED: <expression>’ the manual says I should be allowed to use the /= operator between a row_vector and real, so I am unsure whats going on. Any help would be much appreciated.


I am not a Stan dev, but this really looks like a bug, especially since expectations[t,] = expectations[t,] / year_total; is OK. The compound operators are new so maybe that is something that was overlooked. Consider filing an issue at (with a more minimal example of the issue).



I’m not sure but I’m tagging @Bob_Carpenter and @mitzimorris one of whom should know.

Also make sure the values in that matrix are initialized before you divide otherwise you’re dividing by NaN.


I am in the process of making a simple reproducible example, the error occurs using stanc() call in R which I use to debug models. I am using rstan_2.17.3 StanHeaders_2.17.2, if that helps


I have posted an issue in the rstan github page for future reference here


Thanks for opening the issue and following up!


I moved the issue to Stan, but you can get there by following the links. The problem is that we don’t support sliced lvalues in compound declare-define.