stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.03k stars 264 forks source link

generated code is incorrectly formatted #321

Open wookietreiber opened 8 years ago

wookietreiber commented 8 years ago

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
wookietreiber commented 8 years ago

I also know about this post, but my locales are not German, as you can see, so I don't know if it's a duplicate or not.

bgoodri commented 8 years ago

I'm not seeing this behavior. Can you upgrade to 2.11? If that does not fix the problem, try

library(rstan)
code <- stanc("https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.10/ideo_interactions.stan")
cat(code$cppcode, file = "/tmp/ideo_interactions.cpp", sep = "\n")

and then attach "/tmp/ideo_interactions.cpp" here.

wookietreiber commented 8 years ago

Out of curiosity, I ran the example with the current version. The output just stops:

$ cat ideo_interactions.cpp
// Code generated by Stan version 2.9

#include <stan/model/model_header.hpp>

namespace model131b625a95c5f_ideo_interactions_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;

static int current_statement_begin__;
class model131b625a95c5f_ideo_interactions : public prob_grad {
private:
    int N;
    vector_d party;
    vector_d score1;
    vector_d x;
    vector_d inter;
public:
    model131b625a95c5f_ideo_interactions(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        current_statement_begin__ = -1;

        static const char* function__ = "model131b625a95c5f_ideo_interactions_namespace::model131b625a95c5f_ideo_interactions";
        (void) function__; // dummy call to supress warning
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        context__.validate_dims("data initialization", "N", "int", context__.to_vec());
        N = int(0);
        vals_i__ = context__.vals_i("N");
        pos__ = 0;
        N = vals_i__[pos__++];
        validate_non_negative_index("party", "N", N);
        party = vector_d(N);
        context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("party");
        pos__ = 0;
        size_t party_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
            party[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("score1", "N", N);
        score1 = vector_d(N);
        context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("score1");
        pos__ = 0;
        size_t score1_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
            score1[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("x", "N", N);
        x = vector_d(N);
        context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("x");
        pos__ = 0;
        size_t x_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
            x[i_vec__] = vals_r__[pos__++];
        }

        // validate data
        check_greater_or_equal(function__,"N",N,
wookietreiber commented 8 years ago

I tried installing 2.11.1, which is currently the latest on CRAN, but it failed:

install.packages("http://cran.r-project.org/src/contrib/StanHeaders_2.11.0.tar.gz", repos = NULL, type = "source")
...
install.packages("http://cran.r-project.org/src/contrib/rstan_2.11.1.tar.gz", repos = NULL, type = "source")
...
/usr/local/gcc/5.2.0-1/bin/g++ -shared -L/usr/local/R/3.2.3-1/lib64/R/lib -L/usr/local/libxt/1.1.4-1/lib -L/usr/local/libsm/1.2.2-1/lib -L/usr/local/libice/1.0.9-1/lib -L/usr/local/lapack/3.5.0-2/lib -L/usr/local/cairo/1.14.2-1/lib -L/usr/local/glib/2.45.4-1/lib -L/usr/local/libffi/3.2.1-1/lib -L/usr/local/fontconfig/2.11.94-1/lib -L/usr/local/freetype/2.5.5-1/lib -L/usr/local/libpng/1.6.16-1/lib -L/usr/local/bzip2/1.0.6-3/lib -L/usr/local/expat/2.1.0-4/lib -L/usr/local/pixman/0.32.6-1/lib -L/usr/local/libxml2/2.9.2-1/lib -L/usr/local/zlib/1.2.8-4/lib -L/usr/local/libxrender/0.9.8-2/lib -L/usr/local/libxinerama/1.1.3-1/lib -L/usr/local/libxext/1.3.1-1/lib -L/usr/local/libxmu/1.1.2-1/lib -L/usr/local/readline/6.3-2/lib -L/usr/local/ncurses/5.9-1/lib -L/usr/local/libx11/1.5.0-1/lib -L/usr/local/libxcb/1.9-1/lib -L/usr/local/libxdmcp/1.1.1-1/lib -L/usr/local/xproto/7.0.23-1/lib -L/usr/local/libxau/1.0.7-1/lib -o rstan.so chains.o init.o lang__ast_def.o lang__grammars__bare_type_grammar_inst.o lang__grammars__expression07_grammar_inst.o lang__grammars__expression_grammar_inst.o lang__grammars__functions_grammar_inst.o lang__grammars__indexes_grammar_inst.o lang__grammars__program_grammar_inst.o lang__grammars__semantic_actions.o lang__grammars__statement_2_grammar_inst.o lang__grammars__statement_grammar_inst.o lang__grammars__term_grammar_inst.o lang__grammars__var_deccls_grammar_inst.o lang__grammars__whitespace_grammar_inst.o misc.o sparse_extractors.o stanc.o -L/usr/local/R/3.2.3-1/lib64/R/lib -lR
lto1: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:211
0x625c8d add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:211
0x6264b3 add_references_to_partition
        ../.././gcc/lto/lto-partition.c:115
0x625c3a add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:196
0x6264b3 add_references_to_partition
        ../.././gcc/lto/lto-partition.c:115
0x625c3a add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:196
0x625cfb add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:181
0x625cfb add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:181
0x625cfb add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:181
0x625cfb add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:181
0x625c71 add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:210
0x625c71 add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:210
0x625c71 add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:210
0x625c71 add_symbol_to_partition_1
        ../.././gcc/lto/lto-partition.c:210
0x626db6 lto_balanced_map(int)
        ../.././gcc/lto/lto-partition.c:550
0x620a5b do_whole_program_analysis
        ../.././gcc/lto/lto.c:3324
0x620a5b lto_main()
        ../.././gcc/lto/lto.c:3485
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: fatal error: /usr/local/gcc/5.2.0-1/bin/g++ returned 1 exit status
compilation terminated.
collect2: fatal error: lto-wrapper returned 1 exit status
compilation terminated.
make: *** [rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’
bgoodri commented 8 years ago

LTO is being weird. Try it without the -flto -ffat-lto-objects in CXXFLAGS in ~/.R/Makevars.

wookietreiber commented 8 years ago

@bgoodri Thanks, that fixed the compilation.


> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.8 (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.11.1       StanHeaders_2.11.0 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
data {
  int<lower=0> N;
  vector[N] party;
  vector[N] score1;
  vector[N] x;
}

transformed data {
  vector[N] inter;

  inter = party .* x;
}

parameters {
  vector[4] beta;
  real<lower=0> sigma;
}

model {
  score1 ~ normal(beta[1] + beta[2] * party + beta[3] * x + beta[4] * inter,sigma);
}
code = stanc("ideo_interactions.stan")
// Code generated by Stan version 2.11

#include <stan/model/model_header.hpp>

namespace model150223a80d177_ideo_interactions_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;

static int current_statement_begin__;

class model150223a80d177_ideo_interactions : public prob_grad {
private:
    int N;
    vector_d party;
    vector_d score1;
    vector_d x;
    vector_d inter;
public:
    model150223a80d177_ideo_interactions(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        typedef boost::ecuyer1988 rng_t;
        rng_t base_rng(0);  // 0 seed default
        ctor_body(context__, base_rng, pstream__);
    }

    template <class RNG>
    model150223a80d177_ideo_interactions(stan::io::var_context& context__,
        RNG& base_rng__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, base_rng__, pstream__);
    }

    template <class RNG>
    void ctor_body(stan::io::var_context& context__,
                   RNG& base_rng__,
                   std::ostream* pstream__) {
        current_statement_begin__ = -1;

        static const char* function__ = "model150223a80d177_ideo_interactions_namespace::model150223a80d177_ideo_interactions";
        (void) function__; // dummy call to supress warning
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        context__.validate_dims("data initialization", "N", "int", context__.to_vec());
        N = int(0);
        vals_i__ = context__.vals_i("N");
        pos__ = 0;
        N = vals_i__[pos__++];
        validate_non_negative_index("party", "N", N);
        party = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("party");
        pos__ = 0;
        size_t party_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
            party[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("score1", "N", N);
        score1 = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("score1");
        pos__ = 0;
        size_t score1_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
            score1[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("x", "N", N);
        x = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("x");
        pos__ = 0;
        size_t x_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
            x[i_vec__] = vals_r__[pos__++];
        }

        // validate data
        check_greater_or_equal(function__,"N",N,>

Again, as before, there is no final newline, the output just stops.

annebj commented 7 years ago

Dear @bgoodri and all,

I am having the same problem as @wookietreiber (we are using the same system). The relevant part of the error output message (I think) is as follows (and see wookietreiber's initial post for more detail):

Compilation argument: /usr/local/R/3.2.3-1/lib64/R/bin/R CMD SHLIB file8e446c9d33ef.cpp 2> file8e446c9d33ef.cpp.err.txt /usr/local/gcc/5.2.0-1/bin/g++ -I/usr/local/R/3.2.3-1/lib64/R/include -DNDEBUG -isystem"/gpfs0/global/local/R/3.2.3-1/lib64/R/library/Rcpp/include/" -isystem"/gpfs0/gl$ file8e446c9d33ef.cpp:105:29: error: stray ‘#’ in program size_t siteyrlimit#include <rstan/rstaninc.hpp> ^ file8e446c9d33ef.cpp:157:1: error: expected ‘}’ at end of input } ^ Has anyone come across this problem and found a solution, or any additional thoughts on how we might be able to fix this? Any help would be greatly appreciated!

bgoodri commented 7 years ago

Did you try it without the -flto -ffat-lto-objects in CXXFLAGS in ~/.R/Makevars?

annebj commented 7 years ago

I didn't but @wookietreiber did (see his post just above mine). It fixed the compilation but the output still just stops.

bgoodri commented 7 years ago

It works for me. Try downloading https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.10/ideo_interactions.stan , then change the variable inter to something that does not start with int, and then call the stan_model() function on it to see if it compiles.

annebj commented 7 years ago

I ran ideo_interactions.stan (I changed "inter" to "notinter") but still get the same error:

Loading required package: ggplot2 Loading required package: StanHeaders rstan (Version 2.10.0, packaged: , GitRev: 85f7a56811da) For execution on a local, multicore CPU with excess RAM we recommend calling rstan_options(auto_write = TRUE) options(mc.cores = parallel::detectCores()) DIAGNOSTIC(S) FROM PARSER: Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.

file62151fd247e2.cpp:80:49: error: stray ‘#’ in program check_greater_or_equal(function,"N",N,#include <rstan/rstaninc.hpp> ^ file62151fd247e2.cpp:132:1: error: expected ‘}’ at end of input } ^ file62151fd247e2.cpp: In constructor ‘model62151951d859_ideo_interactions_namespace::model62151951d859_ideo_interactions::model62151951d859_ideo_interactions(stan::io::var_context&,$ file62151fd247e2.cpp:80:50: error: ‘include’ was not declared in this scope check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp> ^ file62151fd247e2.cpp:80:59: error: ‘rstan’ was not declared in this scope check_greater_or_equal(function,"N",N,#include <rstan/rstaninc.hpp> ^ file62151fd247e2.cpp:80:65: error: ‘rstaninc’ was not declared in this scope check_greater_or_equal(function__,"N",N,#include <rstan/rstaninc.hpp> ^ file62151fd247e2.cpp:84:13: error: ‘stan_fit4model62151951d859_ideo_interactions_mod’ was not declared in this scope RCPP_MODULE(stan_fit4model62151951d859_ideo_interactions_mod){ ^ file62151fd247e2.cpp:84:61: error: ‘RCPP_MODULE’ was not declared in this scope RCPP_MODULE(stan_fit4model62151951d859_ideo_interactions_mod){ ^ file62151fd247e2.cpp:132:1: error: expected ‘}’ at end of input } ^ file62151fd247e2.cpp: At global scope: file62151fd247e2.cpp:132:1: error: expected unqualified-id at end of input file62151fd247e2.cpp:132:1: error: expected ‘}’ at end of input make: *\ [file62151fd247e2.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

(Please let me know if you'd like me to provide the full output). Everything works fine on my personal computer, it's only when running it on the cluster that I run into problems. This post discusses the same problem, but as wookietreiber said, our locales are apparently in English (though we are based at a German institution, which does seem perhaps a little too coincidental?).

wookietreiber commented 7 years ago

I got an update from a user who is also working on our cluster. He has been using an older version of R with a newer version of rstan and this combination apparently works. Here is his session info:

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] rstan_2.12.1       StanHeaders_2.12.0 ggplot2_2.1.0

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 grid_3.1.2       gridExtra_2.2.1  gtable_0.1.2
 [5] inline_0.3.13    munsell_0.4.2    plyr_1.8.1       Rcpp_0.12.7
 [9] scales_0.4.0     stats4_3.1.2 

As you can see, his locale settings are a bit more mixed, but it seems to work anyway.

bgoodri commented 7 years ago

You definitely want to be using rstan 2.12 rather than 2.10 because 2.10 yields wrong answers not because of this bug. I would also be surprised if the R version makes any difference. But I don't know what is causing this problem.

wookietreiber commented 7 years ago

@bgoodri Would you be so kind to paste your sessionInfo() and also the compiler with version you used to compile R and rstan / rcpp? Then, I will try to reproduce as much of it on our system as I can.

wookietreiber commented 7 years ago

I finally managed to install the new gcc and R versions:


Thus, my suspicion is that rstan does not work with gcc 5+. Maybe, gcc 5+ can be tuned in some way that it returns correct results for the rstan c++ code generation.

syclik commented 7 years ago

Would you mind sending over the generated code for 4.9.4, 5.4.0, and 6.2.0? I'm curious to see this behavior. This could indicate some deeper issues with the Stan compiler under different compiler versions. And the Stan program used to generate the C++. If this is an issue with Stan itself, I'll move the issue there after verifying.

On Fri, Oct 7, 2016 at 10:21 AM, Christian Krause notifications@github.com wrote:

I finally managed to install the new gcc and R versions:

-

I compiled the latest versions of gcc 4, 5 and 6:

  • gcc 4.9.4

    • gcc 5.4.0

    - gcc 6.2.0

    these were all built with the following configure options:

    ./configure \ --prefix=/usr/local/gcc/ \ --enable-languages=c,c++,fortran,lto \ --enable-static \ --disable-shared \ --with-pic \ --enable-threads=posix \ --enable-lto \ --enable-plugin \ --enable-install-libiberty \ --with-linker-hash-style=gnu \ --disable-multilib \ --disable-werror \ --enable-checking=release \ --enable-__cxa_atexit \ --disable-libunwind-exceptions \ --enable-clocale=gnu \ --disable-libstdcxx-pch \ --disable-libssp \ --enable-gnu-unique-object \ --enable-linker-build-id

    I have built the recent version of R, 3.3.1, with each of these compilers to three different prefixes:

    /usr/local/R/gcc-4/3.3.1-1/bin/R /usr/local/R/gcc-5/3.3.1-1/bin/R /usr/local/R/gcc-6/3.3.1-1/bin/R

    I installed rstan for each of them, i.e.:

    rstan_2.12.1 StanHeaders_2.12.0 ggplot2_2.1.0

    Then, I tested both the example from @bgoodri https://github.com/bgoodri (https://raw.githubusercontent.com/stan- dev/example-models/master/ARM/Ch.10/ideo_interactions.stan https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.10/ideo_interactions.stan) as well as the original stan file from @annebj https://github.com/annebj:

    The generated codes are correct only for the gcc 4.9.4 installation. They are incorrect for both gcc 5.4.0 and gcc 6.2.0.


Thus, my suspicion is that rstan does not work with gcc 5+. Maybe, gcc 5+ can be tuned in some way that it returns correct results for the rstan c++ code generation.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/321#issuecomment-252265065, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZ_FwGJatPZsZrfXlZeqvDWJDqug1Thks5qxlVMgaJpZM4JaXAF .

wookietreiber commented 7 years ago

@syclik I have been testing with the example from @bgoodri from this comment.

GCC 4.9.4

// Code generated by Stan version 2.12

#include <stan/model/model_header.hpp>

namespace model9c772b6b8634_ideo_interactions_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;

static int current_statement_begin__;

class model9c772b6b8634_ideo_interactions : public prob_grad {
private:
    int N;
    vector_d party;
    vector_d score1;
    vector_d x;
    vector_d inter;
public:
    model9c772b6b8634_ideo_interactions(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        typedef boost::ecuyer1988 rng_t;
        rng_t base_rng(0);  // 0 seed default
        ctor_body(context__, base_rng, pstream__);
    }

    template <class RNG>
    model9c772b6b8634_ideo_interactions(stan::io::var_context& context__,
        RNG& base_rng__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, base_rng__, pstream__);
    }

    template <class RNG>
    void ctor_body(stan::io::var_context& context__,
                   RNG& base_rng__,
                   std::ostream* pstream__) {
        current_statement_begin__ = -1;

        static const char* function__ = "model9c772b6b8634_ideo_interactions_namespace::model9c772b6b8634_ideo_interactions";
        (void) function__; // dummy call to supress warning
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        context__.validate_dims("data initialization", "N", "int", context__.to_vec());
        N = int(0);
        vals_i__ = context__.vals_i("N");
        pos__ = 0;
        N = vals_i__[pos__++];
        validate_non_negative_index("party", "N", N);
        party = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("party");
        pos__ = 0;
        size_t party_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
            party[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("score1", "N", N);
        score1 = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("score1");
        pos__ = 0;
        size_t score1_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
            score1[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("x", "N", N);
        x = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("x");
        pos__ = 0;
        size_t x_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
            x[i_vec__] = vals_r__[pos__++];
        }

        // validate data
        check_greater_or_equal(function__,"N",N,0);
        validate_non_negative_index("inter", "N", N);
        inter = vector_d(static_cast<Eigen::VectorXd::Index>(N));

        double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

        // initialize transformed variables to avoid seg fault on val access
        stan::math::fill(inter,DUMMY_VAR__);

        try {
            current_statement_begin__ = 10;
            stan::math::assign(inter, elt_multiply(party,x));
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e,current_statement_begin__);
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        // validate transformed data

        // set parameter ranges
        num_params_r__ = 0U;
        param_ranges_i__.clear();
        num_params_r__ += 4;
        ++num_params_r__;
    }

    ~model9c772b6b8634_ideo_interactions() { }

    void transform_inits(const stan::io::var_context& context__,
                         std::vector<int>& params_i__,
                         std::vector<double>& params_r__,
                         std::ostream* pstream__) const {
        stan::io::writer<double> writer__(params_r__,params_i__);
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<double> vals_r__;
        std::vector<int> vals_i__;

        if (!(context__.contains_r("beta")))
            throw std::runtime_error("variable beta missing");
        vals_r__ = context__.vals_r("beta");
        pos__ = 0U;
        context__.validate_dims("initialization", "beta", "vector_d", context__.to_vec(4));
        vector_d beta(static_cast<Eigen::VectorXd::Index>(4));
        for (int j1__ = 0U; j1__ < 4; ++j1__)
            beta(j1__) = vals_r__[pos__++];
        try {
            writer__.vector_unconstrain(beta);
        } catch (const std::exception& e) { 
            throw std::runtime_error(std::string("Error transforming variable beta: ") + e.what());
        }

        if (!(context__.contains_r("sigma")))
            throw std::runtime_error("variable sigma missing");
        vals_r__ = context__.vals_r("sigma");
        pos__ = 0U;
        context__.validate_dims("initialization", "sigma", "double", context__.to_vec());
        double sigma(0);
        sigma = vals_r__[pos__++];
        try {
            writer__.scalar_lb_unconstrain(0,sigma);
        } catch (const std::exception& e) { 
            throw std::runtime_error(std::string("Error transforming variable sigma: ") + e.what());
        }

        params_r__ = writer__.data_r();
        params_i__ = writer__.data_i();
    }

    void transform_inits(const stan::io::var_context& context,
                         Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
                         std::ostream* pstream__) const {
      std::vector<double> params_r_vec;
      std::vector<int> params_i_vec;
      transform_inits(context, params_i_vec, params_r_vec, pstream__);
      params_r.resize(params_r_vec.size());
      for (int i = 0; i < params_r.size(); ++i)
        params_r(i) = params_r_vec[i];
    }

    template <bool propto__, bool jacobian__, typename T__>
    T__ log_prob(vector<T__>& params_r__,
                 vector<int>& params_i__,
                 std::ostream* pstream__ = 0) const {

        T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

        T__ lp__(0.0);
        stan::math::accumulator<T__> lp_accum__;

        // model parameters
        stan::io::reader<T__> in__(params_r__,params_i__);

        Eigen::Matrix<T__,Eigen::Dynamic,1>  beta;
        (void) beta;  // dummy to suppress unused var warning
        if (jacobian__)
            beta = in__.vector_constrain(4,lp__);
        else
            beta = in__.vector_constrain(4);

        T__ sigma;
        (void) sigma;  // dummy to suppress unused var warning
        if (jacobian__)
            sigma = in__.scalar_lb_constrain(0,lp__);
        else
            sigma = in__.scalar_lb_constrain(0);

        // transformed parameters

        // initialize transformed variables to avoid seg fault on val access

        try {
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e,current_statement_begin__);
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        // validate transformed parameters

        const char* function__ = "validate transformed params";
        (void) function__;  // dummy to suppress unused var warning

        // model body
        try {
            current_statement_begin__ = 17;
            lp_accum__.add(normal_log<propto__>(score1, add(add(add(get_base1(beta,1,"beta",1),multiply(get_base1(beta,2,"beta",1),party)),multiply(get_base1(beta,3,"beta",1),x)),multiply(get_base1(beta,4,"beta",1),inter)), sigma));
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e,current_statement_begin__);
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        lp_accum__.add(lp__);
        return lp_accum__.sum();

    } // log_prob()

    template <bool propto, bool jacobian, typename T_>
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
               std::ostream* pstream = 0) const {
      std::vector<T_> vec_params_r;
      vec_params_r.reserve(params_r.size());
      for (int i = 0; i < params_r.size(); ++i)
        vec_params_r.push_back(params_r(i));
      std::vector<int> vec_params_i;
      return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
    }

    void get_param_names(std::vector<std::string>& names__) const {
        names__.resize(0);
        names__.push_back("beta");
        names__.push_back("sigma");
    }

    void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
        dimss__.resize(0);
        std::vector<size_t> dims__;
        dims__.resize(0);
        dims__.push_back(4);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dimss__.push_back(dims__);
    }

    template <typename RNG>
    void write_array(RNG& base_rng__,
                     std::vector<double>& params_r__,
                     std::vector<int>& params_i__,
                     std::vector<double>& vars__,
                     bool include_tparams__ = true,
                     bool include_gqs__ = true,
                     std::ostream* pstream__ = 0) const {
        vars__.resize(0);
        stan::io::reader<double> in__(params_r__,params_i__);
        static const char* function__ = "model9c772b6b8634_ideo_interactions_namespace::write_array";
        (void) function__; // dummy call to supress warning
        // read-transform, write parameters
        vector_d beta = in__.vector_constrain(4);
        double sigma = in__.scalar_lb_constrain(0);
        for (int k_0__ = 0; k_0__ < 4; ++k_0__) {
            vars__.push_back(beta[k_0__]);
        }
        vars__.push_back(sigma);

        if (!include_tparams__) return;
        // declare and define transformed parameters
        double lp__ = 0.0;
        (void) lp__; // dummy call to supress warning
        stan::math::accumulator<double> lp_accum__;

        try {
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e,current_statement_begin__);
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        // validate transformed parameters

        // write transformed parameters

        if (!include_gqs__) return;
        // declare and define generated quantities

        double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

        // initialize transformed variables to avoid seg fault on val access

        try {
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e,current_statement_begin__);
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        // validate generated quantities

        // write generated quantities
    }

    template <typename RNG>
    void write_array(RNG& base_rng,
                     Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
                     Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
                     bool include_tparams = true,
                     bool include_gqs = true,
                     std::ostream* pstream = 0) const {
      std::vector<double> params_r_vec(params_r.size());
      for (int i = 0; i < params_r.size(); ++i)
        params_r_vec[i] = params_r(i);
      std::vector<double> vars_vec;
      std::vector<int> params_i_vec;
      write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
      vars.resize(vars_vec.size());
      for (int i = 0; i < vars.size(); ++i)
        vars(i) = vars_vec[i];
    }

    static std::string model_name() {
        return "model9c772b6b8634_ideo_interactions";
    }

    void constrained_param_names(std::vector<std::string>& param_names__,
                                 bool include_tparams__ = true,
                                 bool include_gqs__ = true) const {
        std::stringstream param_name_stream__;
        for (int k_0__ = 1; k_0__ <= 4; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "beta" << '.' << k_0__;
            param_names__.push_back(param_name_stream__.str());
        }
        param_name_stream__.str(std::string());
        param_name_stream__ << "sigma";
        param_names__.push_back(param_name_stream__.str());

        if (!include_gqs__ && !include_tparams__) return;

        if (!include_gqs__) return;
    }

    void unconstrained_param_names(std::vector<std::string>& param_names__,
                                   bool include_tparams__ = true,
                                   bool include_gqs__ = true) const {
        std::stringstream param_name_stream__;
        for (int k_0__ = 1; k_0__ <= 4; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "beta" << '.' << k_0__;
            param_names__.push_back(param_name_stream__.str());
        }
        param_name_stream__.str(std::string());
        param_name_stream__ << "sigma";
        param_names__.push_back(param_name_stream__.str());

        if (!include_gqs__ && !include_tparams__) return;

        if (!include_gqs__) return;
    }

}; // model

} // namespace

typedef model9c772b6b8634_ideo_interactions_namespace::model9c772b6b8634_ideo_interactions stan_model;

GCC 5.4.0

// Code generated by Stan version 2.12

#include <stan/model/model_header.hpp>

namespace model9c762417ed15_ideo_interactions_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;

static int current_statement_begin__;

class model9c762417ed15_ideo_interactions : public prob_grad {
private:
    int N;
    vector_d party;
    vector_d score1;
    vector_d x;
    vector_d inter;
public:
    model9c762417ed15_ideo_interactions(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        typedef boost::ecuyer1988 rng_t;
        rng_t base_rng(0);  // 0 seed default
        ctor_body(context__, base_rng, pstream__);
    }

    template <class RNG>
    model9c762417ed15_ideo_interactions(stan::io::var_context& context__,
        RNG& base_rng__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, base_rng__, pstream__);
    }

    template <class RNG>
    void ctor_body(stan::io::var_context& context__,
                   RNG& base_rng__,
                   std::ostream* pstream__) {
        current_statement_begin__ = -1;

        static const char* function__ = "model9c762417ed15_ideo_interactions_namespace::model9c762417ed15_ideo_interactions";
        (void) function__; // dummy call to supress warning
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        context__.validate_dims("data initialization", "N", "int", context__.to_vec());
        N = int(0);
        vals_i__ = context__.vals_i("N");
        pos__ = 0;
        N = vals_i__[pos__++];
        validate_non_negative_index("party", "N", N);
        party = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("party");
        pos__ = 0;
        size_t party_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
            party[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("score1", "N", N);
        score1 = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("score1");
        pos__ = 0;
        size_t score1_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
            score1[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("x", "N", N);
        x = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("x");
        pos__ = 0;
        size_t x_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
            x[i_vec__] = vals_r__[pos__++];
        }

        // validate data
        check_greater_or_equal(function__,"N",N,

GCC 6.2.0

// Code generated by Stan version 2.12

#include <stan/model/model_header.hpp>

namespace model9c781b402936_ideo_interactions_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;

static int current_statement_begin__;

class model9c781b402936_ideo_interactions : public prob_grad {
private:
    int N;
    vector_d party;
    vector_d score1;
    vector_d x;
    vector_d inter;
public:
    model9c781b402936_ideo_interactions(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        typedef boost::ecuyer1988 rng_t;
        rng_t base_rng(0);  // 0 seed default
        ctor_body(context__, base_rng, pstream__);
    }

    template <class RNG>
    model9c781b402936_ideo_interactions(stan::io::var_context& context__,
        RNG& base_rng__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, base_rng__, pstream__);
    }

    template <class RNG>
    void ctor_body(stan::io::var_context& context__,
                   RNG& base_rng__,
                   std::ostream* pstream__) {
        current_statement_begin__ = -1;

        static const char* function__ = "model9c781b402936_ideo_interactions_namespace::model9c781b402936_ideo_interactions";
        (void) function__; // dummy call to supress warning
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        context__.validate_dims("data initialization", "N", "int", context__.to_vec());
        N = int(0);
        vals_i__ = context__.vals_i("N");
        pos__ = 0;
        N = vals_i__[pos__++];
        validate_non_negative_index("party", "N", N);
        party = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "party", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("party");
        pos__ = 0;
        size_t party_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < party_i_vec_lim__; ++i_vec__) {
            party[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("score1", "N", N);
        score1 = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "score1", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("score1");
        pos__ = 0;
        size_t score1_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < score1_i_vec_lim__; ++i_vec__) {
            score1[i_vec__] = vals_r__[pos__++];
        }
        validate_non_negative_index("x", "N", N);
        x = vector_d(static_cast<Eigen::VectorXd::Index>(N));
        context__.validate_dims("data initialization", "x", "vector_d", context__.to_vec(N));
        vals_r__ = context__.vals_r("x");
        pos__ = 0;
        size_t x_i_vec_lim__ = N;
        for (size_t i_vec__ = 0; i_vec__ < x_i_vec_lim__; ++i_vec__) {
            x[i_vec__] = vals_r__[pos__++];
        }

        // validate data
        check_greater_or_equal(function__,"N",N,