Closed mitzimorris closed 3 months ago
The wording of the issue isn't clear to me if you're asking someone else to document this or if it's just a TODO item for yourself, so forgive me if you already know, but I think the simple reason is "we don't ever want the possibility of things changing sizes between iterations"
right - I think this should go in the Generated Quantities block section of the Reference Manual and I will add it.
Note that this is also important in e.g. transformed parameters
parameters {
array[3] real y;
}
transformed parameters {
corr_matrix[size(y)] z;
}
generates the same error, since size(y)
references y
. Arguably we should make an exception for the size
family of functions, but at the moment we do not.
There is also a related, but slightly different error, for directly using an _rng
in a decl:
Semantic error in 'foo.stan', line 2, column 9 to column 26:
-------------------------------------------------
1: transformed data {
2: array[binomial_rng(3,3)] int x;
^
3: }
4:
-------------------------------------------------
Random number generators are not allowed in top level size declarations.
This is fine, though:
transformed data {
int N = binomial_rng(3,3);
array[N] int x;
}
I don't see any reason why we have to disallow
array[binomial_rng(3, 0.3)] int<lower=0, upper=3> x;
binomial_rng(3, 3)
would throw a runtime error because the second argument needs to be a probability.
We could allow that in transformed data, but not generated quantities. My guess is it was just easier to disallow everywhere
We could allow that in transformed data, but not generated quantities.
Good point. I was only thinking about transformed data given the example.
Summary:
The Stan Reference Manual doesn't mention that the Stan compiler doesn't allow this:
The compiler generates error message:
Document, explain why.