Skip to content

Commit 48e9943

Browse files
Merge pull request #797 from stan-dev/empty-array-clarification
clarify empty array expression
2 parents e1535f4 + 4665eb9 commit 48e9943

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/reference-manual/expressions.qmd

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ The empty expression `[ ]` is ambiguous and therefore is not
301301
allowed and similarly expressions such as `[ [ ] ]` or
302302
`[ [ ], [ ] ]` are not allowed.
303303

304+
### Empty vectors and matrices {-}
305+
306+
If needed, it is possible to create an empty vector with
307+
```stan
308+
rep_vector(e, 0)
309+
```
310+
where the first expression `e` needs to scalar of type `real`.
311+
312+
If needed, it is possible to create an empty matrix with
313+
```stan
314+
rep_matrix(e, 0, 0)
315+
```
316+
where the first expression `e` needs to scalar of type `real`.
304317

305318
### Array expressions {-}
306319

@@ -334,6 +347,21 @@ array[2, 3] int b = { { 1, 2, 3 },
334347
{ 4, 5, 6 } };
335348
```
336349

350+
### Empty arrays {-}
351+
352+
The empty array expression (`{ }`) is not allowed. See more about restrictions on array expressions in subsection [Restrictions on values](#array-expressions).
353+
354+
If needed, it is possible to create an empty array with
355+
```stan
356+
rep_array(e, 0)
357+
```
358+
where the first expression `e` determines the type of the array. For
359+
example, `rep_array(0.0, 0)` returns an empty real array of type
360+
`real[]`, whereas `rep_array({123}, 0)` returns an empty two
361+
dimensional integer array of type `int[ , ]`. Only the type of the
362+
first argument is used, so the integer arrays `{123}` and `{0}`
363+
produce equivalent values.
364+
337365

338366
### Array expression types {-}
339367

0 commit comments

Comments
 (0)