Skip to content

Commit 58dc596

Browse files
authored
Update Stan syntax to version 2.33 (#3859)
* Update Stan syntax to version 2.33 * Update CHANGES.md
1 parent 694eb52 commit 58dc596

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Core Grammars:
4040
- fix(reasonml) simplify syntax and align it with ocaml [jchavarri][]
4141
- fix(swift) `warn_unqualified_access` is an attribute [Bradley Mackey][]
4242
- enh(swift) macro attributes are highlighted as keywords [Bradley Mackey][]
43+
- enh(stan) updated for version 2.33 (#3859) [Brian Ward][]
4344

4445
Dev tool:
4546

@@ -62,6 +63,7 @@ Dev tool:
6263
[aana-h2]: https://github.com/aana-h2
6364
[Nicholas Thompson]: https://github.com/NAThompson
6465
[Yasith Deelaka]: https://github.com/YasithD
66+
[Brian Ward]: https://github.com/WardBrian
6567

6668

6769
## Version 11.8.0

src/languages/stan.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ export default function(hljs) {
3232

3333
const TYPES = [
3434
'array',
35+
'tuple',
3536
'complex',
3637
'int',
3738
'real',
3839
'vector',
40+
'complex_vector',
3941
'ordered',
4042
'positive_ordered',
4143
'simplex',
4244
'unit_vector',
4345
'row_vector',
46+
'complex_row_vector',
4447
'matrix',
48+
'complex_matrix',
4549
'cholesky_factor_corr|10',
4650
'cholesky_factor_cov|10',
4751
'corr_matrix|10',
@@ -58,8 +62,6 @@ export default function(hljs) {
5862
// functions_quoted.txt
5963

6064
const FUNCTIONS = [
61-
'Phi',
62-
'Phi_approx',
6365
'abs',
6466
'acos',
6567
'acosh',
@@ -77,7 +79,6 @@ export default function(hljs) {
7779
'bessel_first_kind',
7880
'bessel_second_kind',
7981
'binary_log_loss',
80-
'binomial_coefficient_log',
8182
'block',
8283
'cbrt',
8384
'ceil',
@@ -88,37 +89,48 @@ export default function(hljs) {
8889
'cols',
8990
'columns_dot_product',
9091
'columns_dot_self',
92+
'complex_schur_decompose',
93+
'complex_schur_decompose_t',
94+
'complex_schur_decompose_u',
9195
'conj',
9296
'cos',
9397
'cosh',
9498
'cov_exp_quad',
9599
'crossprod',
100+
'csr_extract',
96101
'csr_extract_u',
97102
'csr_extract_v',
98103
'csr_extract_w',
99104
'csr_matrix_times_vector',
100105
'csr_to_dense_matrix',
101106
'cumulative_sum',
107+
'dae',
108+
'dae_tol',
102109
'determinant',
103110
'diag_matrix',
111+
'diagonal',
104112
'diag_post_multiply',
105113
'diag_pre_multiply',
106-
'diagonal',
107114
'digamma',
108115
'dims',
109116
'distance',
110117
'dot_product',
111118
'dot_self',
119+
'eigendecompose',
120+
'eigendecompose_sym',
121+
'eigenvalues',
112122
'eigenvalues_sym',
123+
'eigenvectors',
113124
'eigenvectors_sym',
114125
'erf',
115126
'erfc',
116127
'exp',
117128
'exp2',
118129
'expm1',
119-
'fabs',
120130
'falling_factorial',
121131
'fdim',
132+
'fft',
133+
'fft2',
122134
'floor',
123135
'fma',
124136
'fmax',
@@ -128,28 +140,31 @@ export default function(hljs) {
128140
'gamma_q',
129141
'generalized_inverse',
130142
'get_imag',
131-
'get_lp',
132143
'get_real',
133144
'head',
134145
'hmm_hidden_state_prob',
135146
'hmm_marginal',
136147
'hypot',
137148
'identity_matrix',
138149
'inc_beta',
139-
'int_step',
140150
'integrate_1d',
141151
'integrate_ode',
142152
'integrate_ode_adams',
143153
'integrate_ode_bdf',
144154
'integrate_ode_rk45',
155+
'int_step',
145156
'inv',
146-
'inv_Phi',
147157
'inv_cloglog',
158+
'inv_erfc',
159+
'inverse',
160+
'inverse_spd',
161+
'inv_fft',
162+
'inv_fft2',
163+
'inv_inc_beta',
148164
'inv_logit',
165+
'inv_Phi',
149166
'inv_sqrt',
150167
'inv_square',
151-
'inverse',
152-
'inverse_spd',
153168
'is_inf',
154169
'is_nan',
155170
'lambert_w0',
@@ -175,12 +190,12 @@ export default function(hljs) {
175190
'log_falling_factorial',
176191
'log_inv_logit',
177192
'log_inv_logit_diff',
193+
'logit',
178194
'log_mix',
179195
'log_modified_bessel_first_kind',
180196
'log_rising_factorial',
181197
'log_softmax',
182198
'log_sum_exp',
183-
'logit',
184199
'machine_precision',
185200
'map_rect',
186201
'matrix_exp',
@@ -195,10 +210,11 @@ export default function(hljs) {
195210
'min',
196211
'modified_bessel_first_kind',
197212
'modified_bessel_second_kind',
198-
'multiply_log',
199213
'multiply_lower_tri_self_transpose',
200214
'negative_infinity',
201215
'norm',
216+
'norm1',
217+
'norm2',
202218
'not_a_number',
203219
'num_elements',
204220
'ode_adams',
@@ -219,14 +235,18 @@ export default function(hljs) {
219235
'ones_row_vector',
220236
'ones_vector',
221237
'owens_t',
238+
'Phi',
239+
'Phi_approx',
222240
'polar',
223241
'positive_infinity',
224242
'pow',
225243
'print',
226244
'prod',
227245
'proj',
246+
'qr',
228247
'qr_Q',
229248
'qr_R',
249+
'qr_thin',
230250
'qr_thin_Q',
231251
'qr_thin_R',
232252
'quad_form',
@@ -266,6 +286,7 @@ export default function(hljs) {
266286
'sub_col',
267287
'sub_row',
268288
'sum',
289+
'svd',
269290
'svd_U',
270291
'svd_V',
271292
'symmetrize_from_lower_tri',
@@ -278,6 +299,7 @@ export default function(hljs) {
278299
'to_array_1d',
279300
'to_array_2d',
280301
'to_complex',
302+
'to_int',
281303
'to_matrix',
282304
'to_row_vector',
283305
'to_vector',
@@ -321,18 +343,22 @@ export default function(hljs) {
321343
'inv_chi_square',
322344
'inv_gamma',
323345
'inv_wishart',
346+
'inv_wishart_cholesky',
324347
'lkj_corr',
325348
'lkj_corr_cholesky',
326349
'logistic',
350+
'loglogistic',
327351
'lognormal',
328352
'multi_gp',
329353
'multi_gp_cholesky',
354+
'multinomial',
355+
'multinomial_logit',
330356
'multi_normal',
331357
'multi_normal_cholesky',
332358
'multi_normal_prec',
359+
'multi_student_cholesky_t',
333360
'multi_student_t',
334-
'multinomial',
335-
'multinomial_logit',
361+
'multi_student_t_cholesky',
336362
'neg_binomial',
337363
'neg_binomial_2',
338364
'neg_binomial_2_log',
@@ -352,12 +378,14 @@ export default function(hljs) {
352378
'skew_double_exponential',
353379
'skew_normal',
354380
'std_normal',
381+
'std_normal_log',
355382
'student_t',
356383
'uniform',
357384
'von_mises',
358385
'weibull',
359386
'wiener',
360-
'wishart'
387+
'wishart',
388+
'wishart_cholesky'
361389
];
362390

363391
const BLOCK_COMMENT = hljs.COMMENT(

test/detect/stan/default.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ data {
55
int<lower=0> N;
66
int K;
77
matrix[N, K] x;
8+
complex_row_vector[K] z;
89
}
910
transformed data {
1011
complex zi = 1+3.14i;
@@ -16,13 +17,14 @@ parameters {
1617
array[K - 1] real mu;
1718
array[K + 1] real<lower=0> sigma;
1819
cholesky_factor_corr[K] L;
20+
tuple(real, tuple(real, real)) t;
1921
}
2022
model {
2123
target += normal_lpdf(x[ : , 1] | mu[1], sigma[1]);
2224
target += gumbel_lpdf(x[ : , 2] | mu[2], sigma[2]);
2325
target += lognormal_lpdf(x[ : , 3] | mu[3], sigma[3]);
2426
target += weibull_lpdf(x[ : , 4] | sigma[4], sigma[5]);
25-
27+
2628
{
2729
matrix[K, N] y;
2830
for (n in 1 : N) {
@@ -37,4 +39,4 @@ model {
3739
}
3840
generated quantities {
3941
matrix[K, K] Sigma = multiply_lower_tri_self_transpose(L);
40-
}
42+
}

test/markup/stan/default.expect.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<span class="hljs-type">int</span>&lt;<span class="hljs-keyword">lower</span>=<span class="hljs-number">0</span>&gt; N;
66
<span class="hljs-type">int</span> K;
77
<span class="hljs-type">matrix</span>[N, K] x;
8+
<span class="hljs-type">complex_row_vector</span>[K] z;
89
}
910
<span class="hljs-title">transformed</span> <span class="hljs-title">data</span> {
1011
<span class="hljs-type">complex</span> zi = <span class="hljs-number">1</span>+<span class="hljs-number">3.14i</span>;
@@ -16,13 +17,14 @@
1617
<span class="hljs-type">array</span>[K - <span class="hljs-number">1</span>] <span class="hljs-type">real</span> mu;
1718
<span class="hljs-type">array</span>[K + <span class="hljs-number">1</span>] <span class="hljs-type">real</span>&lt;<span class="hljs-keyword">lower</span>=<span class="hljs-number">0</span>&gt; sigma;
1819
<span class="hljs-type">cholesky_factor_corr</span>[K] L;
20+
<span class="hljs-type">tuple</span>(<span class="hljs-type">real</span>, <span class="hljs-type">tuple</span>(<span class="hljs-type">real</span>, <span class="hljs-type">real</span>)) t;
1921
}
2022
<span class="hljs-title">model</span> {
2123
<span class="hljs-keyword">target</span> += <span class="hljs-built_in">normal_lpdf</span>(x[ : , <span class="hljs-number">1</span>] | mu[<span class="hljs-number">1</span>], sigma[<span class="hljs-number">1</span>]);
2224
<span class="hljs-keyword">target</span> += <span class="hljs-built_in">gumbel_lpdf</span>(x[ : , <span class="hljs-number">2</span>] | mu[<span class="hljs-number">2</span>], sigma[<span class="hljs-number">2</span>]);
2325
<span class="hljs-keyword">target</span> += <span class="hljs-built_in">lognormal_lpdf</span>(x[ : , <span class="hljs-number">3</span>] | mu[<span class="hljs-number">3</span>], sigma[<span class="hljs-number">3</span>]);
2426
<span class="hljs-keyword">target</span> += <span class="hljs-built_in">weibull_lpdf</span>(x[ : , <span class="hljs-number">4</span>] | sigma[<span class="hljs-number">4</span>], sigma[<span class="hljs-number">5</span>]);
25-
27+
2628
{
2729
<span class="hljs-type">matrix</span>[K, N] y;
2830
<span class="hljs-keyword">for</span> (n <span class="hljs-keyword">in</span> <span class="hljs-number">1</span> : N) {
@@ -37,4 +39,4 @@
3739
}
3840
<span class="hljs-title">generated</span> <span class="hljs-title">quantities</span> {
3941
<span class="hljs-type">matrix</span>[K, K] Sigma = <span class="hljs-built_in">multiply_lower_tri_self_transpose</span>(L);
40-
}
42+
}

test/markup/stan/default.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ data {
55
int<lower=0> N;
66
int K;
77
matrix[N, K] x;
8+
complex_row_vector[K] z;
89
}
910
transformed data {
1011
complex zi = 1+3.14i;
@@ -16,13 +17,14 @@ parameters {
1617
array[K - 1] real mu;
1718
array[K + 1] real<lower=0> sigma;
1819
cholesky_factor_corr[K] L;
20+
tuple(real, tuple(real, real)) t;
1921
}
2022
model {
2123
target += normal_lpdf(x[ : , 1] | mu[1], sigma[1]);
2224
target += gumbel_lpdf(x[ : , 2] | mu[2], sigma[2]);
2325
target += lognormal_lpdf(x[ : , 3] | mu[3], sigma[3]);
2426
target += weibull_lpdf(x[ : , 4] | sigma[4], sigma[5]);
25-
27+
2628
{
2729
matrix[K, N] y;
2830
for (n in 1 : N) {
@@ -37,4 +39,4 @@ model {
3739
}
3840
generated quantities {
3941
matrix[K, K] Sigma = multiply_lower_tri_self_transpose(L);
40-
}
42+
}

0 commit comments

Comments
 (0)