Skip to content

Commit bd1d16b

Browse files
author
Bob Carpenter
authored
Merge pull request #148 from stan-dev/add-reverse
Add documentation for reverse()
2 parents 32c9de9 + cee0742 commit bd1d16b

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/functions-reference/array_operations.Rmd

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
```{r results='asis', echo=FALSE}
44
if (knitr::is_html_output()) {
55
cat(' * <a href="array-reductions.html">Reductions</a>\n')
6-
cat(' * <a href="array-size-and-dimension-function.html">Array Size and Dimension Function</a>\n')
7-
cat(' * <a href="array-broadcasting.html">Array Broadcasting</a>\n')
8-
cat(' * <a href="array-concatenation.html">Array Concatenation</a>\n')
6+
cat(' * <a href="array-size-and-dimension-function.html">Array size and dimension function</a>\n')
7+
cat(' * <a href="array-broadcasting.html">Array broadcasting</a>\n')
8+
cat(' * <a href="array-concatenation.html">Array concatenation</a>\n')
99
cat(' * <a href="sorting-functions.html">Sorting functions</a>\n')
10+
cat(' * <a href="reversing-functions.html">Reversing functions</a>\n')
1011
}
1112
```
1213

@@ -178,7 +179,7 @@ The squared Euclidean distance between x and y
178179
`real` **`squared_distance`**`(row_vector x, row_vector[] y)`<br>\newline
179180
The Euclidean distance between x and y
180181

181-
## Array Size and Dimension Function
182+
## Array size and dimension function
182183

183184
The size of an array or matrix can be obtained using the `dims()`
184185
function. The `dims()` function is defined to take an argument
@@ -236,7 +237,7 @@ can be any type, but the size is just the size of the top level array,
236237
not the total number of elements contained. For example, if `x` is of
237238
type `real[4,3]` then `size(x)` is 4.
238239

239-
## Array Broadcasting {#array-broadcasting}
240+
## Array broadcasting {#array-broadcasting}
240241

241242
The following operations create arrays by repeating elements to fill
242243
an array of a specified size. These operations work for all input
@@ -312,7 +313,7 @@ After the assignment to `b`, the value for `b[j,k,m,n]` is equal to
312313
`a[m,n]` where it is defined, for `j` in `1:3`, `k` in `1:4`, `m` in
313314
`1:5`, and `n` in `1:6`.
314315

315-
## Array Concatenation {#array-concatenation}
316+
## Array concatenation {#array-concatenation}
316317

317318
<!-- T; append_array; (T x, T y); -->
318319
\index{{\tt \bfseries append\_array }!{\tt (T x, T y): T}|hyperpage}
@@ -409,3 +410,16 @@ Number of components of v less than v[s]
409410
`int` **`rank`**`(int[] v, int s)`<br>\newline
410411
Number of components of v less than v[s]
411412

413+
## Reversing functions {#reversing-functions}
414+
415+
Stan provides functions to create a new array by reversing the order of
416+
elements in an existing array. For example, if `v` is declared as a real
417+
array of size 3, with values
418+
\[ \text{v} = (1,\, -10.3,\, 20.987), \] then
419+
\[ \mathrm{reverse(v)} = (20.987,\, -10.3,\, 1). \]
420+
421+
<!-- T[]; reverse; (T[] v); -->
422+
\index{{\tt \bfseries reverse }!{\tt (T[] v): T[]}|hyperpage}
423+
424+
`T[]` **`reverse`**`(T[] v)`<br>\newline
425+
Return a new array containing the elements of the argument in reverse order.

src/functions-reference/matrix_operations.Rmd

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cat(' * <a href="softmax.html">Special Matrix Functions</a>\n')
1616
cat(' * <a href="covariance.html">Covariance Functions</a>\n')
1717
cat(' * <a href="linear-algebra-functions-and-solvers.html">Linear Algebra Functions and Solvers</a>\n')
1818
cat(' * <a href="sort-functions.html">Sort Functions</a>\n')
19+
cat(' * <a href="reverse-functions.html">Reverse Functions</a>\n')
1920
}
2021
```
2122

@@ -1544,8 +1545,8 @@ The singular values of A in descending order
15441545

15451546
## Sort Functions
15461547

1547-
see section [sorting functions](#sorting-functions) for examples of how the functions
1548-
work.
1548+
See the [sorting functions section](#sorting-functions) for examples of how
1549+
the functions work.
15491550

15501551
<!-- vector; sort_asc; (vector v); -->
15511552
\index{{\tt \bfseries sort\_asc }!{\tt (vector v): vector}|hyperpage}
@@ -1611,3 +1612,16 @@ Number of components of v less than v[s]
16111612
`int` **`rank`**`(row_vector v, int s)`<br>\newline
16121613
Number of components of v less than v[s]
16131614

1615+
## Reverse Functions {#reverse-functions}
1616+
1617+
<!-- vector; reverse; (vector v); -->
1618+
\index{{\tt \bfseries reverse }!{\tt (vector v): vector}|hyperpage}
1619+
1620+
`vector` **`reverse`**`(vector v)`<br>\newline
1621+
Return a new vector containing the elements of the argument in reverse order.
1622+
1623+
<!-- row_vector; reverse; (row_vector v); -->
1624+
\index{{\tt \bfseries reverse }!{\tt (row_vector v): row_vector}|hyperpage}
1625+
1626+
`row_vector` **`reverse`**`(row_vector v)`<br>\newline
1627+
Return a new row vector containing the elements of the argument in reverse order.

0 commit comments

Comments
 (0)