Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### Submission Checklist

- [ ] Builds locally
- [ ] New functions marked with `` `r since("VERSION")` ``
- [ ] Declare copyright holder and open-source license: see below

#### Summary
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ This repository uses
[GitHub Pages](https://help.github.com/categories/github-pages-basics)
to serve the
[project pages](https://help.github.com/articles/user-organization-and-project-pages/#project-pages-sites) site
with URL `https://mc-stan.org/docs`.
with URL https://mc-stan.org/docs.
The publishing strategy is to serve the contents of the directory `docs` on branch `master`.
The `docs` directory contains an empty file named `.nojekyll` so that GitHub will treat the contents
as pre-generated HTML instead of trying to run [jekyll](https://jekyllrb.com).
Expand Down
7 changes: 7 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.aux
*.fdb_latexmk
*.fls
*.idx
*.ilg
*.ind
*.toc
40 changes: 40 additions & 0 deletions src/functions-reference/array_operations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@ with respect to the combination operation (min, max, sum, or product).

`real` **`min`**`(array[] real x)`<br>\newline
The minimum value in x, or $+\infty$ if x is size 0.
`r since("2.0")`

<!-- int; min; (array[] int x); -->
\index{{\tt \bfseries min }!{\tt (array[] int x): int}|hyperpage}

`int` **`min`**`(array[] int x)`<br>\newline
The minimum value in x, or error if x is size 0.
`r since("2.0")`

<!-- real; max; (array[] real x); -->
\index{{\tt \bfseries max }!{\tt (array[] real x): real}|hyperpage}

`real` **`max`**`(array[] real x)`<br>\newline
The maximum value in x, or $-\infty$ if x is size 0.
`r since("2.0")`

<!-- int; max; (array[] int x); -->
\index{{\tt \bfseries max }!{\tt (array[] int x): int}|hyperpage}

`int` **`max`**`(array[] int x)`<br>\newline
The maximum value in x, or error if x is size 0.
`r since("2.0")`

### Sum, product, and log sum of exp

Expand All @@ -52,18 +56,21 @@ The maximum value in x, or error if x is size 0.
The sum of the elements in x, defined for $x$ of size $N$ by \[
\text{sum}(x) = \begin{cases} \sum_{n=1}^N x_n & \text{if} N > 0
\\[4pt] 0 & \text{if} N = 0 \end{cases} \]
`r since("2.1")`

<!-- real; sum; (array[] real x); -->
\index{{\tt \bfseries sum }!{\tt (array[] real x): real}|hyperpage}

`real` **`sum`**`(array[] real x)`<br>\newline
The sum of the elements in x; see definition above.
`r since("2.0")`

<!-- real; prod; (array[] real x); -->
\index{{\tt \bfseries prod }!{\tt (array[] real x): real}|hyperpage}

`real` **`prod`**`(array[] real x)`<br>\newline
The product of the elements in x, or 1 if x is size 0.
`r since("2.0")`

<!-- real; prod; (array[] int x); -->
\index{{\tt \bfseries prod }!{\tt (array[] int x): real}|hyperpage}
Expand All @@ -72,13 +79,15 @@ The product of the elements in x, or 1 if x is size 0.
The product of the elements in x, \[ \text{product}(x) = \begin{cases}
\prod_{n=1}^N x_n & \text{if} N > 0 \\[4pt] 1 & \text{if} N = 0
\end{cases} \]
`r since("2.0")`

<!-- real; log_sum_exp; (array[] real x); -->
\index{{\tt \bfseries log\_sum\_exp }!{\tt (array[] real x): real}|hyperpage}

`real` **`log_sum_exp`**`(array[] real x)`<br>\newline
The natural logarithm of the sum of the exponentials of the elements
in x, or $-\infty$ if the array is empty.
`r since("2.0")`

### Sample mean, variance, and standard deviation

Expand All @@ -102,6 +111,7 @@ The sample mean of the elements in x. For an array $x$ of size $N >
0$, \[ \text{mean}(x) \ = \ \bar{x} \ = \ \frac{1}{N} \sum_{n=1}^N
x_n. \] It is an error to the call the mean function with an array of
size $0$.
`r since("2.0")`

<!-- real; variance; (array[] real x); -->
\index{{\tt \bfseries variance }!{\tt (array[] real x): real}|hyperpage}
Expand All @@ -112,6 +122,7 @@ The sample variance of the elements in x. For $N > 0$, \[
- \bar{x})^2 & \text{if } N > 1 \\[4pt] 0 & \text{if } N = 1
\end{cases} \] It is an error to call the `variance` function with an
array of size 0.
`r since("2.0")`

<!-- real; sd; (array[] real x); -->
\index{{\tt \bfseries sd }!{\tt (array[] real x): real}|hyperpage}
Expand All @@ -121,6 +132,7 @@ The sample standard deviation of elements in x. \[ \text{sd}(x) =
\begin{cases} \sqrt{\, \text{variance}(x)} & \text{if } N > 1 \\[4pt]
0 & \text{if } N = 0 \end{cases} \] It is an error to call the `sd`
function with an array of size 0.
`r since("2.0")`

### Euclidean distance and squared distance

Expand All @@ -132,24 +144,28 @@ The Euclidean distance between x and y, defined by \[
\text{distance}(x,y) \ = \ \sqrt{\textstyle \sum_{n=1}^N (x_n -
y_n)^2} \] where `N` is the size of x and y. It is an error to call
`distance` with arguments of unequal size.
`r since("2.2")`

<!-- real; distance; (vector x, row_vector y); -->
\index{{\tt \bfseries distance }!{\tt (vector x, row\_vector y): real}|hyperpage}

`real` **`distance`**`(vector x, row_vector y)`<br>\newline
The Euclidean distance between x and y
`r since("2.2")`

<!-- real; distance; (row_vector x, vector y); -->
\index{{\tt \bfseries distance }!{\tt (row\_vector x, vector y): real}|hyperpage}

`real` **`distance`**`(row_vector x, vector y)`<br>\newline
The Euclidean distance between x and y
`r since("2.2")`

<!-- real; distance; (row_vector x, row_vector y); -->
\index{{\tt \bfseries distance }!{\tt (row\_vector x, row\_vector y): real}|hyperpage}

`real` **`distance`**`(row_vector x, row_vector y)`<br>\newline
The Euclidean distance between x and y
`r since("2.2")`

<!-- real; squared_distance; (vector x, vector y); -->
\index{{\tt \bfseries squared\_distance }!{\tt (vector x, vector y): real}|hyperpage}
Expand All @@ -160,24 +176,28 @@ The squared Euclidean distance between x and y, defined by \[
\textstyle \sum_{n=1}^N (x_n - y_n)^2, \] where `N` is the size of x
and y. It is an error to call `squared_distance` with arguments of
unequal size.
`r since("2.7")`

<!-- real; squared_distance; (vector x, row_vector y); -->
\index{{\tt \bfseries squared\_distance }!{\tt (vector x, row\_vector y): real}|hyperpage}

`real` **`squared_distance`**`(vector x, row_vector y)`<br>\newline
The squared Euclidean distance between x and y
`r since("2.26")`

<!-- real; squared_distance; (row_vector x, vector y); -->
\index{{\tt \bfseries squared\_distance }!{\tt (row\_vector x, vector y): real}|hyperpage}

`real` **`squared_distance`**`(row_vector x, vector y)`<br>\newline
The squared Euclidean distance between x and y
`r since("2.26")`

<!-- real; squared_distance; (row_vector x, row_vector y); -->
\index{{\tt \bfseries squared\_distance }!{\tt (row\_vector x, row\_vector y): real}|hyperpage}

`real` **`squared_distance`**`(row_vector x, row_vector y)`<br>\newline
The Euclidean distance between x and y
`r since("2.26")`

### Quantile

Expand All @@ -193,12 +213,14 @@ Sample quantiles in Statistical Packages (R's default quantile function).

`real` **`quantile`**`(data array[] real x, data real p)`<br>\newline
The p-th quantile of x
`r since("2.27")`

<!-- array[] real; quantile; (data array[] real x, data array[] real p); -->
\index{{\tt \bfseries quantile }!{\tt (data array[] real x, data array[] real p): real}|hyperpage}

`array[] real` **`quantile`**`(data array[] real x, data array[] real p)`<br>\newline
An array containing the quantiles of x given by the array of probabilities p
`r since("2.27")`

## Array size and dimension function

Expand Down Expand Up @@ -238,6 +260,7 @@ extract the dimensions of vectors and matrices.
`array[] int` **`dims`**`(T x)`<br>\newline
Return an integer array containing the dimensions of x; the type of
the argument T can be any Stan type with up to 8 array dimensions.
`r since("2.0")`

<!-- int; num_elements; (array[] T x); -->
\index{{\tt \bfseries num\_elements }!{\tt (array[] T x): int}|hyperpage}
Expand All @@ -248,6 +271,7 @@ elements in contained arrays, vectors, and matrices. T can be any
array type. For example, if `x` is of type `array[4, 3] real` then
`num_elements(x)` is 12, and if `y` is declared as `array[5] matrix[3, 4] y`,
then `size(y)` evaluates to 60.
`r since("2.5")`

<!-- int; size; (array[] T x); -->
\index{{\tt \bfseries size }!{\tt (array[] T x): int}|hyperpage}
Expand All @@ -257,6 +281,7 @@ Return the number of elements in the array x; the type of the array T
can be any type, but the size is just the size of the top level array,
not the total number of elements contained. For example, if `x` is of
type `array[4, 3] real` then `size(x)` is 4.
`r since("2.0")`

## Array broadcasting {#array-broadcasting}

Expand All @@ -270,18 +295,21 @@ arrays.

`array[] T` **`rep_array`**`(T x, int n)`<br>\newline
Return the n array with every entry assigned to x.
`r since("2.0")`

<!-- array[,] T; rep_array; (T x, int m, int n); -->
\index{{\tt \bfseries rep\_array }!{\tt (T x, int m, int n): array[,] T}|hyperpage}

`array [,] T` **`rep_array`**`(T x, int m, int n)`<br>\newline
Return the m by n array with every entry assigned to x.
`r since("2.0")`

<!-- array[,,] T; rep_array; (T x, int k, int m, int n); -->
\index{{\tt \bfseries rep\_array }!{\tt (T x, int k, int m, int n): array[,,] T}|hyperpage}

`array[,,] T` **`rep_array`**`(T x, int k, int m, int n)`<br>\newline
Return the k by m by n array with every entry assigned to x.
`r since("2.0")`

For example, `rep_array(1.0,5)` produces a real array (type `array[] real`)
of size 5 with all values set to 1.0. On the other hand,
Expand Down Expand Up @@ -343,6 +371,7 @@ After the assignment to `b`, the value for `b[j, k, m, n]` is equal to
Return the concatenation of two arrays in the order of the arguments.
T must be an N-dimensional array of any Stan type (with a maximum N of
7). All dimensions but the first must match.
`r since("2.18")`

For example, the following code appends two three dimensional arrays
of matrices together. Note that all dimensions except the first match.
Expand Down Expand Up @@ -372,64 +401,74 @@ as a real array of size 3, with values \[ \text{v} = (1, -10.3,

`array[] real` **`sort_asc`**`(array[] real v)`<br>\newline
Sort the elements of v in ascending order
`r since("2.0")`

<!-- array[] int; sort_asc; (array[] int v); -->
\index{{\tt \bfseries sort\_asc }!{\tt (array[] int v): array[] int}|hyperpage}

`array[] int` **`sort_asc`**`(array[] int v)`<br>\newline
Sort the elements of v in ascending order
`r since("2.0")`

<!-- array[] real; sort_desc; (array[] real v); -->
\index{{\tt \bfseries sort\_desc }!{\tt (array[] real v): array[] real}|hyperpage}

`array[] real` **`sort_desc`**`(array[] real v)`<br>\newline
Sort the elements of v in descending order
`r since("2.0")`

<!-- array[] int; sort_desc; (array[] int v); -->
\index{{\tt \bfseries sort\_desc }!{\tt (array[] int v): array[] int}|hyperpage}

`array[] int` **`sort_desc`**`(array[] int v)`<br>\newline
Sort the elements of v in descending order
`r since("2.0")`

<!-- array[] int; sort_indices_asc; (array[] real v); -->
\index{{\tt \bfseries sort\_indices\_asc }!{\tt (array[] real v): array[] int}|hyperpage}

`array[] int` **`sort_indices_asc`**`(array[] real v)`<br>\newline
Return an array of indices between 1 and the size of v, sorted to
index v in ascending order.
`r since("2.3")`

<!-- array[] int; sort_indices_asc; (array[] int v); -->
\index{{\tt \bfseries sort\_indices\_asc }!{\tt (array[] int v): array[] int}|hyperpage}

`array[] int` **`sort_indices_asc`**`(array[] int v)`<br>\newline
Return an array of indices between 1 and the size of v, sorted to
index v in ascending order.
`r since("2.3")`

<!-- array[] int; sort_indices_desc; (array[] real v); -->
\index{{\tt \bfseries sort\_indices\_desc }!{\tt (array[] real v): array[] int}|hyperpage}

`array[] int` **`sort_indices_desc`**`(array[] real v)`<br>\newline
Return an array of indices between 1 and the size of v, sorted to
index v in descending order.
`r since("2.3")`

<!-- array[] int; sort_indices_desc; (array[] int v); -->
\index{{\tt \bfseries sort\_indices\_desc }!{\tt (array[] int v): array[] int}|hyperpage}

`array[] int` **`sort_indices_desc`**`(array[] int v)`<br>\newline
Return an array of indices between 1 and the size of v, sorted to
index v in descending order.
`r since("2.3")`

<!-- int; rank; (array[] real v, int s); -->
\index{{\tt \bfseries rank }!{\tt (array[] real v, int s): int}|hyperpage}

`int` **`rank`**`(array[] real v, int s)`<br>\newline
Number of components of v less than v[s]
`r since("2.0")`

<!-- int; rank; (array[] int v, int s); -->
\index{{\tt \bfseries rank }!{\tt (array[] int v, int s): int}|hyperpage}

`int` **`rank`**`(array[] int v, int s)`<br>\newline
Number of components of v less than v[s]
`r since("2.0")`

## Reversing functions {#reversing-functions}

Expand All @@ -444,3 +483,4 @@ array of size 3, with values

`array[] T` **`reverse`**`(array[] T v)`<br>\newline
Return a new array containing the elements of the argument in reverse order.
`r since("2.23")`
Loading