Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array constructors don't work with sampling statements #2710

Closed
bob-carpenter opened this issue Dec 13, 2018 · 1 comment
Closed

array constructors don't work with sampling statements #2710

bob-carpenter opened this issue Dec 13, 2018 · 1 comment
Assignees
Milestone

Comments

@bob-carpenter
Copy link
Member

bob-carpenter commented Dec 13, 2018

Summary:

This file should compile:

parameters {
  real<lower = 0> sigma;
}
model {
  sigma ~ inv_gamma(1e-4, 1e-4);
  { -1.0, 0.0, 1.0 } ~ normal(0, sigma);
}

Instead, I get

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

Illegal statement beginning with non-void expression parsed as
  -(1.0)
Not a legal assignment, sampling, or function statement.  Note that
  * Assignment statements only allow variables (with optional indexes) on the left;
  * Sampling statements allow arbitrary value-denoting expressions on the left.
  * Functions used as statements must be declared to have void returns

  error in 'model416374d59793_bad_gamma' at line 6, column 5
  -------------------------------------------------
     4: model {
     5:   sigma ~ inv_gamma(1e-4, 1e-4);
     6:   { -1.0, 0.0, 1.0 } ~ normal(0, sigma);
            ^
     7: }
  -------------------------------------------------

PARSER EXPECTED: "}"
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'bad-gamma' due to the above error.n

As an aside, it works if the array constructor is replaced with a vector constructor, [ -1.0, 0.0, 1.0 ].

Current Version:

v2.18.0

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.18.1       StanHeaders_2.18.0 ggplot2_2.2.1     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18       magrittr_1.5       munsell_0.4.3      colorspace_1.3-2  
 [5] R6_2.2.2           rlang_0.2.1        plyr_1.8.4         tools_3.5.0       
 [9] parallel_3.5.0     pkgbuild_1.0.2     grid_3.5.0         gtable_0.2.0      
[13] loo_2.0.0          cli_1.0.0          matrixStats_0.54.0 lazyeval_0.2.1    
[17] assertthat_0.2.0   tibble_1.4.2       crayon_1.3.4       processx_3.2.0    
[21] gridExtra_2.3      callr_3.0.0        codetools_0.2-15   base64enc_0.1-3   
[25] ps_1.2.0           inline_0.3.15      compiler_3.5.0     pillar_1.2.3      
[29] scales_0.5.0       prettyunits_1.0.2  stats4_3.5.0      
@VMatthijs
Copy link
Member

VMatthijs commented Dec 13, 2018

This has been fixed in the new compiler. (Just tested it.)

@mitzimorris mitzimorris modified the milestones: 2.18.1, 2.18.1++ Dec 23, 2018
@seantalts seantalts modified the milestones: 2.18.1++, 2.19.0++ Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants