docs
docs copied to clipboard
Clarify index range construction and its difference from R behaviour
Summary:
A colleague has mentioned that it would be helpful for the manual to be more explicit about Stan's behaviour with range indexing that involves operations.
For example:
transformed data {
array[5] int Y = {1, 2, 3, 4, 5};
int i = 3;
int p = 5;
array[3] int Y_subset = Y[p-i:p-1]; // Y[2:4]
}
It would be good to be explicit that the Stan will parse the indexing in Y[p-i:p-1]
as:
(p-i):(p-1)
As opposed to:
p - (i:p) - 1
Noting that the latter behaviour is how the indexing would be parsed in R:
> i <- 3
> p <- 5
> p-i:p-1
[1] 1 0 -1
Current Version:
v2.18.0
Adding that clarification could be made at least in the two following places
- colon : as in indexing could be mentioned in the Operator Precedence Table https://mc-stan.org/docs/reference-manual/arithmetic-expressions.html
- index range construction could be clarified in https://mc-stan.org/docs/reference-manual/language-multi-indexing.html
The colon in indexing isn't really an operator in Stan, since we don't allow 1:2
as an expression, only as part of for loops multi-indexing. We could put it in the operator table, but I worry that would cause even more potential confusion