generated code is incorrectly formatted
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
The generated C++ code is faulty.
Description:
The C++ code generation inserts the #include <rstan/rstaninc.hpp> line at an inappropriate position, be it either because the code generation is generally faulty or the steps before didn't produce as much output as they are supposed to (because the line looks incomplete). See below for how it looks like.
Reproducible Steps:
$ R
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(rstan)
Loading required package: ggplot2
rstan (Version 2.9.0-3, packaged: 2016-02-11 15:54:41 UTC, GitRev: 05c3d0058b6a)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.6 (Final)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstan_2.9.0-3 ggplot2_2.1.0
loaded via a namespace (and not attached):
[1] colorspace_1.2-6 scales_0.4.0 plyr_1.8.3 inline_0.3.14
[5] gtable_0.2.0 gridExtra_2.2.1 Rcpp_0.12.3 grid_3.2.3
[9] stats4_3.2.3 munsell_0.4.3
> model <- stan_demo()
Do you want to download the example models?
1: Download to the temporary directory
2: Do not download
Selection: 1
1: ARM/Ch.10/ideo_interactions.stan
2: ARM/Ch.10/ideo_reparam.stan
... excluded for brevity
420: misc/sur/sur.stan
Selection: 1
> "score1" <-
+ c(0.446, 0.334, -0.233, -0.304, -0.256, 0.515, -0.652, 0.271, -0.556,
+ 0.955, 0.307, -0.434, -0.272, -0.404, 0.415, 0.39, -0.755, 0. .... [TRUNCATED]
> "party" <-
+ c(1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,
+ 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 1, 0, 1, 1, 0 .... [TRUNCATED]
> "x" <-
+ c(0.62073, 0.50803, 0.38243, 0.29769, 0.32751, 0.53766, 0.20003, 0.52211,
+ 0.31267, 0.64143, 0.69113, 0.4386, 0.30166, 0.25836, 0.51547, .... [TRUNCATED]
> "N" <-
+ 357
file342030a544a6.cpp:79:49: error: stray ‘#’ in program
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:131:1: error: expected ‘}’ at end of input
}
^
file342030a544a6.cpp: In constructor ‘model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions::model3420212c8184_ideo_intera
ctions(stan::io::var_context&, std::ostream*)’:
file342030a544a6.cpp:79:50: error: ‘include’ was not declared in this scope
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:79:59: error: ‘rstan’ was not declared in this scope
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:79:65: error: ‘rstaninc’ was not declared in this scope
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:83:13: error: ‘stan_fit4model3420212c8184_ideo_interactions_mod’ was not declared in this scope
RCPP_MODULE(stan_fit4model3420212c8184_ideo_interactions_mod){
^
file342030a544a6.cpp:83:61: error: ‘RCPP_MODULE’ was not declared in this scope
RCPP_MODULE(stan_fit4model3420212c8184_ideo_interactions_mod){
^
file342030a544a6.cpp:131:1: error: expected ‘}’ at end of input
}
^
file342030a544a6.cpp: At global scope:
file342030a544a6.cpp:131:1: error: expected unqualified-id at end of input
file342030a544a6.cpp:131:1: error: expected ‘}’ at end of input
make: *** [file342030a544a6.o] Error 1
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1:
2: // includes from the plugin
3:
4:
5: // user includes
6: #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.9
7:
8: #include <stan/model/model_header.hpp>
9:
10: namespace model3420212c8184_ideo_interactions_namespace {
11:
12: using std::istream;
13: using std::string;
14: using std::stringstream;
15: using std::vector;
16: using stan::io::dump;
17: using stan::math::lgamma;
18: using stan::model::prob_grad;
19: using namespace stan::math;
20:
21: typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
22: typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
23: typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;
24:
25: static int current_statement_begin__;
26: class model3420212c8184_ideo_interactions : public prob_grad {
27: private:
28: int N;
29: vector_d party;
30: vector_d score1;
31: vector_d x;
32: vector_d inter;
33: public:
34: model3420212c8184_ideo_interactions(stan::io::var_context& context__,
35: std::ostream* pstream__ = 0)
36: : prob_grad(0) {
37: current_statement_begin__ = -1;
38:
39: static const char* function__ = "model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions";
40: (void) function__; // dummy call to supress warning
41: size_t pos__;
42: (void) pos__; // dummy call to supress warning
43: std::vector<int> vals_i__;
44: std::vector<double> vals_r__;
45: context__.validate_dims("data initialization", "N", "int", context__.to_vec());
46: N = int(0);
47: vals_i__ = context__.vals_i("N");
48: pos__ = 0;
49: N = vals_i__[pos__++];
50: validate_non_negative_index("party", "N", N);
51: party = vector_d(N);
52: context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
53: vals_r__ = context__.vals_r("party");
54: pos__ = 0;
55: size_t party_i_vec_lim__ = N;
56: for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
57: party[i_vec__] = vals_r__[pos__++];
58: }
59: validate_non_negative_index("score1", "N", N);
60: score1 = vector_d(N);
61: context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
62: vals_r__ = context__.vals_r("score1");
63: pos__ = 0;
64: size_t score1_i_vec_lim__ = N;
65: for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
66: score1[i_vec__] = vals_r__[pos__++];
67: }
68: validate_non_negative_index("x", "N", N);
69: x = vector_d(N);
70: context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
71: vals_r__ = context__.vals_r("x");
72: pos__ = 0;
73: size_t x_i_vec_lim__ = N;
74: for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
75: x[i_vec__] = vals_r__[pos__++];
76: }
77:
78: // validate data
79: check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
80: /**
81: * Define Rcpp Module to expose stan_fit's functions to R.
82: */
83: RCPP_MODULE(stan_fit4model3420212c8184_ideo_interactions_mod){
84: Rcpp::class_<rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions,
85: boost::random::ecuyer1988> >("stan_fit4model3420212c8184_ideo_interactions")
86: // .constructor<Rcpp::List>()
87: .constructor<SEXP, SEXP>()
88: // .constructor<SEXP, SEXP>()
89: .method("call_sampler",
90: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::call_
sampler)
91: .method("param_names",
92: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_names)
93: .method("param_names_oi",
94: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_names_oi)
95: .method("param_fnames_oi",
96: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_fnames_oi)
97: .method("param_dims",
98: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_dims)
99: .method("param_dims_oi",
100: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_dims_oi)
101: .method("update_param_oi",
102: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::updat
e_param_oi)
103: .method("param_oi_tidx",
104: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::param
_oi_tidx)
105: .method("grad_log_prob",
106: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::grad_
log_prob)
107: .method("log_prob",
108: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::log_p
rob)
109: .method("unconstrain_pars",
110: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::uncon
strain_pars)
111: .method("constrain_pars",
112: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::const
rain_pars)
113: .method("num_pars_unconstrained",
114: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::num_pars_unconstrained)
115: .method("unconstrained_param_names",
116: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::unconstrained_param_names)
117: .method("constrained_param_names",
118: &rstan::stan_fit<model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions, boost::random::ecuyer1988>::constrained_param_names)
119: ;
120: }
121:
122: // declarations
123: extern "C" {
124: SEXP file342030a544a6( ) ;
125: }
126:
127: // definition
128:
129: SEXP file342030a544a6( ){
130: return Rcpp::wrap("ideo_interactions");
131: }
132:
133:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file342030a544a6.cpp:79:49: error: stray ‘#’ in program
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:131:1: error: expected ‘}’ at end of input
}
^
file342030a544a6.cpp: In constructor ‘model3420212c8184_ideo_interactions_namespace::model3420212c8184_ideo_interactions::model3420212c8184_ideo_interactions(stan::io::var_context&, std::ostream*)’:
file342030a544a6.cpp:79:50: error: ‘include’ was not declared in this scope
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:79:59: error: ‘rstan’ was not declared in this scope
check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp>
^
file342030a544a6.cpp:79:65: error: ‘rs
In addition: Warning message:
running command '/usr/local/R/3.2.3-1/lib64/R/bin/R CMD SHLIB file342030a544a6.cpp 2> file342030a544a6.cpp.err.txt' had status 1
RStan Version:
2.9.0.3
R Version:
R version 3.2.3 (2015-12-10)
Operating System:
CentOS
Linux idiv1.eve.ufz.de 2.6.32-573.8.1.el6.x86_64 #1 SMP Tue Nov 10 18:01:38 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the RStan example-generation failure from the R session shown, then inspect the generated C++ output around the // validate data section and the misplaced #include <rstan/rstaninc.hpp> line. Done means generated C++ places the include outside expressions and compiles successfully for the demonstrated model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, r
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100