@@ -782,8 +782,10 @@ In addition to single integer indexes, as described in
782
782
[ the language indexing section] ( #language-indexing.section ) , Stan supports multiple indexing.
783
783
Multiple indexes can be integer arrays of indexes, lower
784
784
bounds, upper bounds, lower and upper bounds, or simply shorthand for
785
- all of the indexes. A complete table of index types is given in the
786
- following table.
785
+ all of the indexes. If the upper bound is smaller than the lower bound,
786
+ the range is empty (unlike, e.g., in R). The upper bound and lower bound can be
787
+ expressions that evaluate to integer. A complete list of index types is
788
+ given in the following table.
787
789
788
790
##### Indexing Options Table {- #index-types-table}
789
791
@@ -797,9 +799,18 @@ following table.
797
799
| lower bound | ` a[3:] ` | ` a[3] ` , ..., ` a[N] ` |
798
800
| upper bound | ` a[:5] ` | ` a[1] ` , ..., ` a[5] ` |
799
801
| range | ` a[2:7] ` | ` a[2] ` , ..., ` a[7] ` |
802
+ | range | ` a[7:2] ` | [ ] |
803
+ | range | ` a[5-3:5+2] ` | ` a[2] ` , ..., ` a[7] ` |
800
804
| all | ` a[:] ` | ` a[1] ` , ..., ` a[N] ` |
801
805
| all | ` a[] ` | ` a[1] ` , ..., ` a[N] ` |
802
806
807
+ The range indexing with ` : ` allows only increasing sequences. Indexing
808
+ with a decereasing sequence can be made by creating an integer array in
809
+ the following way:
810
+ ``` stan
811
+ array[6] int ii = reverse(linspaced_int_array(6, 2, 7));
812
+ ```
813
+ Then ` a[ii] ` evaluates to ` a[7] ` , ..., ` a[2] ` .
803
814
804
815
### Multiple index semantics {-}
805
816
0 commit comments