Assigning different dimensions

  1. Must each side of an assignment statement have the same dimensions in Stan or can it recycle values? For example a[1:2] = 9 in R is equivalent to a[1:2] = c(9,9) but I suppose for the vector a in Stan, we need a[1:2] = [9,9]?

  2. The compound declaration section of the reference manual states that matrix[3, 2] a = b; “declares a matrix variable a and assigns it to the value of b, which must be of type matrix for the compound statement to be well formed.” Should this say “assigns it the value of b?”

1 Like

Must each side of an assignment statement have the same dimensions in Stan or can it recycle values? For example a[1:2] = 9 in R is equivalent to a[1:2] = c(9,9) but I suppose for the vector a in Stan, we need a[1:2] = [9,9]?

Yes both sides need to have the same dimension and type, there isn’t any implicit recycling. For your a example, you could also use a[1:2] = rep_vector(9, 2)

The compound declaration section of the reference manual states that matrix[3, 2] a = b; “declares a matrix variable a and assigns it to the value of b, which must be of type matrix for the compound statement to be well formed.” Should this say “assigns it the value of b?”

Good catch, this wording is a little unclear - I’ll open an issue in our docs repo about this