Skip to content

Commit

Permalink
Merge pull request #797 from stan-dev/empty-array-clarification
Browse files Browse the repository at this point in the history
clarify empty array expression
  • Loading branch information
bob-carpenter authored Aug 6, 2024
2 parents e1535f4 + 4665eb9 commit 48e9943
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/reference-manual/expressions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ The empty expression `[ ]` is ambiguous and therefore is not
allowed and similarly expressions such as `[ [ ] ]` or
`[ [ ], [ ] ]` are not allowed.

### Empty vectors and matrices {-}

If needed, it is possible to create an empty vector with
```stan
rep_vector(e, 0)
```
where the first expression `e` needs to scalar of type `real`.

If needed, it is possible to create an empty matrix with
```stan
rep_matrix(e, 0, 0)
```
where the first expression `e` needs to scalar of type `real`.

### Array expressions {-}

Expand Down Expand Up @@ -334,6 +347,21 @@ array[2, 3] int b = { { 1, 2, 3 },
{ 4, 5, 6 } };
```

### Empty arrays {-}

The empty array expression (`{ }`) is not allowed. See more about restrictions on array expressions in subsection [Restrictions on values](#array-expressions).

If needed, it is possible to create an empty array with
```stan
rep_array(e, 0)
```
where the first expression `e` determines the type of the array. For
example, `rep_array(0.0, 0)` returns an empty real array of type
`real[]`, whereas `rep_array({123}, 0)` returns an empty two
dimensional integer array of type `int[ , ]`. Only the type of the
first argument is used, so the integer arrays `{123}` and `{0}`
produce equivalent values.


### Array expression types {-}

Expand Down

0 comments on commit 48e9943

Please sign in to comment.