Understanding brackets array syntax documentation

I am trying to update my code to address this error:

Warning in '/tmp/RtmpH9sgz3/model-3b673bc8c67.stan', line 38, column 2: Declaration
    of arrays by placing brackets after a variable name is deprecated and
    will be removed in Stan 2.32.0. Instead use the array keyword before the
    type. This can be changed automatically using the auto-format flag to
    stanc

and found the documentation page: 13.10 Brackets array syntax | Stan Reference Manual (mc-stan.org), but I am still confused. Specifically, I do not understand the double declaration of dimensions such as

matrix[7, 2] mu[15, 12];

becoming

array[15, 12] matrix[7, 2] mu;

Why are there two dimensions? [15,12] and [7,2]? And why don’t they match?

For example, how do I change

matrix[total_observations, m_delta] v_p;

to avoid this errors?

Also, if someone provide a link, I’m happy to take a stab at updating the docs once I understand what’s going on.

matrix[7, 2] mu[15, 12]; declares a 15 x 12 array of 7 x 2 matrices. I think this was confusing to everybody, which is partly why it’s getting replaced with array[15, 12] matrix[7, 2] mu;.

This change shouldn’t affect matrix[i, j] varname, which is not declaring an array at all but rather is declaring an i x j matrix. Lines like this should not raise the deprecation warning.

2 Likes