Skip to content

Commit

Permalink
docs: Stan array sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdt committed Jul 24, 2024
1 parent 9b99427 commit bb40671
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/actionsheets/data/stan/array.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
language = "stan"
parent = "stan"
name = "array"
title = "Array"

[create]
section = "Create"

[create.1d.declare]
action = "Declare 1D array of length _N_"
code = "real a[N];"

[create.2d.declare]
action = "Declare 2D array of size _N_ by _M_"
code = "real a[N,M];"

[create.3d.declare]
action = "Declare 3D array of size _N_ by _M_ by _O_"
code = "real a[N,M,O];"

[create.1d.constant.zero]
action = "Declare 1D array with zeros"
code = "real a[N] = rep_array(0, N);"

[create.1d.values]
action = "Declare 1D array with values"
code = "real a[] = {1, 2, 5}"

[create.2d.values]
action = "Declare 2D array with values"
code = "int b[2, 3] = { { 1, 2, 3 }, { 4, 5, 6 } };"


[prop]
section = "Properties"

[prop.dim]
action = "Dimensions"
code = "dims(a)"

[prop.length]
action = "Number of elements"
code = "num_elements(a)"

[prop.dim.1]
action = "Size of first dimension"
code = "size(a)"
details = "real a[4,3]; then size(a) = 4"


[derive]
section = "Derive"


[derive.grow]
section = "Grow"

[derive.grow.append.array]
action = "Append array"
code = "append_array(x, y)"


[convert]
section = "Convert"

[convert.1d]
action = "To 1D array"
code = "to_array_1d(a)"

[convert.2d]
action = "To 2D array"
code = "to_array_2d(a)"

[convert.vector]
action = "To vector"
code = "to_vector(a)"

[convert.matrix]
action = "To matrix"
code = "to_matrix(a)"

[convert.matrix.1d]
action = "1D array to matrix of size (column-major order)"
code = "to_matrix(a, nrow, ncol)"
25 changes: 25 additions & 0 deletions src/actionsheets/data/stan/stan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@ language = "stan"
parent = ""
name = "stan"
title = "Stan"

[output]
section = "Output"

[output.print]
action = "Print string"
code = """
print("Hello world")
"""

[output.print.var]
action = "Print value of variable with name"
code = """
print("x=", x);
"""


[error]
section = "Errors"

[error.throw]
action = "Throw error"
code = """
reject("x contains NaNs");
"""

0 comments on commit bb40671

Please sign in to comment.