1 #ifndef STAN__GM__GENERATOR_HPP
2 #define STAN__GM__GENERATOR_HPP
4 #include <boost/variant/apply_visitor.hpp>
5 #include <boost/lexical_cast.hpp>
24 const std::string
EOL(
"\n");
25 const std::string
EOL2(
"\n\n");
26 const std::string
INDENT(
" ");
32 return !
is_nil(x.range_.low_.expr_) && !
is_nil(x.range_.high_.expr_);
36 return is_nil(x.range_.low_.expr_) && !
is_nil(x.range_.high_.expr_);
40 return !
is_nil(x.range_.low_.expr_) &&
is_nil(x.range_.high_.expr_);
51 for (
size_t k = 0; k < indent; ++k)
59 o <<
"(void) " << name <<
"; // dummy to suppress unused var warning";
72 o <<
"namespace " << name <<
"_namespace {" <<
EOL2;
76 o <<
"} // namespace" <<
EOL2;
82 o <<
"// " << msg <<
EOL;
88 const std::vector<expression> indexes,
94 size_t ai_size = indexes.size();
100 if (ai_size <= (e_num_dims + 1) || base_type !=
MATRIX_T) {
101 for (
size_t n = 0; n < ai_size; ++n)
102 o << (isLHS ?
"get_base1_lhs(" :
"get_base1(");
104 for (
size_t n = 0; n < ai_size; ++n) {
107 o <<
',' <<
'"' << expr <<
'"' <<
',' << (n+1) <<
')';
110 for (
size_t n = 0; n < ai_size - 1; ++n)
111 o << (isLHS ?
"get_base1_lhs(" :
"get_base1(");
113 for (
size_t n = 0; n < ai_size - 2; ++n) {
116 o <<
',' <<
'"' << expr <<
'"' <<
',' << (n+1) <<
')';
122 o <<
',' <<
'"' << expr <<
'"' <<
',' << (ai_size-1U) <<
')';
127 const std::vector<expression>& ,
130 for (
size_t i = 0; i < end; ++i) o <<
"std::vector<";
132 for (
size_t i = 0; i < end; ++i) {
138 struct expression_visgen : public visgen {
139 expression_visgen(std::ostream& o) : visgen(o) { }
140 void operator()(nil const& /*x*/) const {
143 void operator()(const int_literal& n) const { o_ << n.val_; }
144 void operator()(const double_literal& x) const {
145 std::string num_str = boost::lexical_cast<std::string>(x.val_);
147 if (num_str.find_first_of("eE.") == std::string::npos)
148 o_ << ".0"; // trailing 0 to ensure C++ makes it a double
150 void operator()(const array_literal& x) const {
151 o_ << "stan::math::new_array<";
152 generate_type("foobar",
157 for (size_t i = 0; i < x.args_.size(); ++i) {
159 generate_expression(x.args_[i],o_);
164 void operator()(const variable& v) const { o_ << v.name_; }
165 void operator()(int n) const { o_ << static_cast<long>(n); }
166 void operator()(double x) const { o_ << x; }
167 void operator()(const std::string& x) const { o_ << x; } // identifiers
168 void operator()(const index_op& x) const {
169 std::stringstream expr_o;
170 generate_expression(x.expr_,expr_o);
171 std::string expr_string = expr_o.str();
172 std::vector<expression> indexes;
173 size_t e_num_dims = x.expr_.expression_type().num_dims_;
174 base_expr_type base_type = x.expr_.expression_type().base_type_;
175 for (size_t i = 0; i < x.dimss_.size(); ++i)
176 for (size_t j = 0; j < x.dimss_[i].size(); ++j)
177 indexes.push_back(x.dimss_[i][j]); // wasteful copy, could use refs
178 generate_indexed_expr<false>(expr_string,indexes,base_type,e_num_dims,o_);
180 void operator()(const integrate_ode& fx) const {
181 o_ << "integrate_ode("
182 << fx.system_function_name_
185 generate_expression(fx.y0_, o_);
188 generate_expression(fx.t0_, o_);
191 generate_expression(fx.ts_, o_);
194 generate_expression(fx.theta_, o_);
197 generate_expression(fx.x_, o_);
200 generate_expression(fx.x_int_, o_);
201 o_ << ", pstream__)";
203 void operator()(const fun& fx) const {
204 // first test if short-circuit op (binary && and || applied to
205 // primitives; overloads are eager, not short-circuiting)
206 if (fx.name_ == "logical_or" || fx.name_ == "logical_and") {
207 o_ << "(primitive_value(";
208 boost::apply_visitor(*this, fx.args_[0].expr_);
209 o_ << ") " << ((fx.name_ == "logical_or") ? "||" : "&&") << " primitive_value(";
210 boost::apply_visitor(*this, fx.args_[1].expr_);
214 o_ << fx.name_ << '(
';
215 for (size_t i = 0; i < fx.args_.size(); ++i) {
216 if (i > 0) o_ << ',
';
217 boost::apply_visitor(*this, fx.args_[i].expr_);
219 if (fx.args_.size() > 0
220 && (has_rng_suffix(fx.name_) || has_lp_suffix(fx.name_)))
222 if (has_rng_suffix(fx.name_))
224 if (has_lp_suffix(fx.name_))
225 o_ << "lp__, lp_accum__";
226 if (is_user_defined(fx)) {
227 if (fx.args_.size() > 0
228 || has_rng_suffix(fx.name_)
229 || has_lp_suffix(fx.name_))
235 void operator()(const binary_op& expr) const {
237 boost::apply_visitor(*this, expr.left.expr_);
238 o_ << ' ' << expr.op << ' ';
239 boost::apply_visitor(*this, expr.right.expr_);
242 void operator()(const unary_op& expr) const {
243 o_ << expr.op << '(
';
244 boost::apply_visitor(*this, expr.subject.expr_);
249 void generate_expression(const expression& e, std::ostream& o) {
250 expression_visgen vis(o);
251 boost::apply_visitor(vis, e.expr_);
254 static void print_string_literal(std::ostream& o,
255 const std::string& s) {
257 for (size_t i = 0; i < s.size(); ++i) {
258 if (s[i] == '"' || s[i] == '\\
' || s[i] == '\
'' )
267 std::stringstream ss;
289 o <<
"using " << type <<
";" <<
EOL;
293 o <<
"using namespace " << ns <<
";" <<
EOL;
311 const std::string& abbrev,
313 o <<
"typedef" <<
" " << type <<
" " << abbrev <<
";" <<
EOL;
318 generate_typedef(
"Eigen::Matrix<double,1,Eigen::Dynamic>",
"row_vector_d",o);
319 generate_typedef(
"Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>",
"matrix_d",o);
324 o <<
"#include" <<
" " <<
"<" << lib_name <<
">" <<
EOL;
335 o <<
"// Code generated by Stan version "
341 o <<
"class " << model_name <<
" : public prob_grad {" <<
EOL;
345 o <<
"}; // model" <<
EOL2;
349 const std::string& base_type,
350 const std::vector<expression>&
dims,
353 for (
size_t i = 0; i < dims.size(); ++i) {
367 }
else if (!
is_nil(type_arg2.expr_)) {
374 for (
size_t i = 0; i < dims.size(); ++i)
381 const std::string& stage,
382 const std::string& var_name,
383 const std::string& base_type,
384 const std::vector<expression>& dims,
388 <<
"context__.validate_dims("
389 <<
'"' << stage <<
'"'
390 <<
", " <<
'"' << var_name <<
'"'
391 <<
", " <<
'"' << base_type <<
'"'
392 <<
", context__.to_vec(";
393 for (
size_t i = 0; i < dims.size(); ++i) {
398 if (dims.size() > 0) o <<
",";
462 o <<
"stan::math::validate_non_negative_index(\"" << var_name <<
"\", ";
470 const std::string& var_name,
471 const std::string& base_type,
472 const std::vector<expression>& dims,
476 for (
size_t i = 0; i < dims.size(); ++i)
485 << var_name <<
" = ";
540 for (
size_t i = 0; i < vs.size(); ++i)
541 boost::apply_visitor(vis, vs[i].decl_);
556 template <
typename D>
558 const std::string& read_fun_prefix,
559 const std::vector<expression>& dim_args)
const {
560 std::vector<expression> read_args;
561 std::string read_fun(read_fun_prefix);
564 read_args.push_back(x.range_.low_);
565 read_args.push_back(x.range_.high_);
568 read_args.push_back(x.range_.low_);
571 read_args.push_back(x.range_.high_);
573 for (
size_t i = 0; i < dim_args.size(); ++i)
574 read_args.push_back(dim_args[i]);
582 std::vector<expression> read_args;
586 std::vector<expression> read_args;
587 read_args.push_back(x.
M_);
591 std::vector<expression> read_args;
592 read_args.push_back(x.
N_);
596 std::vector<expression> read_args;
597 read_args.push_back(x.
M_);
598 read_args.push_back(x.
N_);
602 std::vector<expression> read_args;
603 read_args.push_back(x.
K_);
607 std::vector<expression> read_args;
608 read_args.push_back(x.
K_);
612 std::vector<expression> read_args;
613 read_args.push_back(x.
K_);
617 std::vector<expression> read_args;
618 read_args.push_back(x.
K_);
622 std::vector<expression> read_args;
623 read_args.push_back(x.
M_);
624 read_args.push_back(x.
N_);
629 std::vector<expression> read_args;
630 read_args.push_back(x.
K_);
632 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
638 std::vector<expression> read_args;
639 read_args.push_back(x.
K_);
644 std::vector<expression> read_args;
645 read_args.push_back(x.
K_);
650 const std::string& read_type,
651 const std::vector<expression>& read_args,
652 const std::string& name,
653 const std::vector<expression>& dims)
const {
656 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"vector<";
658 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"> ";
659 if (dims.size() == 0)
o_ <<
" ";
660 o_ << name <<
";" <<
EOL;
663 if (dims.size() == 0) {
669 o_ << name <<
" = in__." << read_type <<
"_constrain(";
670 for (
size_t j = 0; j < read_args.size(); ++j) {
671 if (j > 0)
o_ <<
",";
674 if (read_args.size() > 0)
683 o_ << name <<
" = in__." << read_type <<
"_constrain(";
684 for (
size_t j = 0; j < read_args.size(); ++j) {
685 if (j > 0)
o_ <<
",";
692 std::string name_dims(name);
693 for (
size_t i = 0; i < dims.size(); ++i) {
695 o_ <<
"size_t dim_" << name <<
"_" << i <<
"__ = ";
699 if (i < dims.size() - 1) {
701 o_ << name_dims <<
".resize(dim" <<
"_" << name <<
"_" << i <<
"__);"
703 name_dims.append(
"[k_").append(
to_string(i)).append(
"__]");
707 if (i == dims.size() - 1) {
708 o_ << name_dims <<
".reserve(dim_" << name <<
"_" << i <<
"__);" <<
EOL;
712 o_ <<
"for (size_t k_" << i <<
"__ = 0;"
713 <<
" k_" << i <<
"__ < dim_" << name <<
"_" << i <<
"__;"
714 <<
" ++k_" << i <<
"__) {" <<
EOL;
717 if (i == dims.size() - 1) {
719 o_ <<
"if (jacobian__)" <<
EOL;
724 o_ << name_dims <<
".push_back(in__." << read_type <<
"_constrain(";
725 for (
size_t j = 0; j < read_args.size(); ++j) {
726 if (j > 0)
o_ <<
",";
729 if (read_args.size() > 0)
740 o_ << name_dims <<
".push_back(in__." << read_type <<
"_constrain(";
741 for (
size_t j = 0; j < read_args.size(); ++j) {
742 if (j > 0)
o_ <<
",";
749 for (
size_t i = dims.size(); i > 0; --i) {
763 <<
"stan::io::reader<"
764 << (is_var ?
"T__" :
"double")
765 <<
"> in__(params_r__,params_i__);" <<
EOL2;
767 for (
size_t i = 0; i < vs.size(); ++i)
768 boost::apply_visitor(vis, vs[i].decl_);
775 o <<
"public:" <<
EOL;
779 o <<
"private:" <<
EOL;
793 for (
size_t i = 0; i < dims.size(); ++i) {
795 o_ <<
"for (int k" << i <<
"__ = 0;"
796 <<
" k" << i <<
"__ < ";
799 o_ <<
" ++k" << i <<
"__) {" <<
EOL;
803 for (
size_t i = 0; i < dims_size; ++i) {
810 size_t dims_size)
const {
812 for (
size_t i = 0; i < dims_size; ++i)
813 o_ <<
"[k" << i <<
"__]";
816 template <
typename T>
818 if (!(x.range_.has_low() || x.range_.has_high()))
822 o_ <<
"try { " <<
EOL;
823 if (x.range_.has_low()) {
825 o_ <<
"check_greater_or_equal(function__,";
831 o_ <<
"\", (double *)0);" <<
EOL;
833 if (x.range_.has_high()) {
835 o_ <<
"check_less_or_equal(function__,";
841 o_ <<
"\", (double *)0);" <<
EOL;
844 o_ <<
"} catch (const std::exception& e) { "
847 o_ <<
"throw std::domain_error(std::string(\"Invalid value of " << x.name_ <<
": \") + std::string(e.what()));"
868 template <
typename T>
873 o_ <<
"try { stan::math::check_" << type_name <<
"(function__,";
877 o_ <<
"\", (double *)0); } catch (const std::exception& e) { throw std::domain_error(std::string(\"Invalid value of " << x.name_ <<
": \") + std::string(e.what())); };" <<
EOL;
911 boost::apply_visitor(vis,decl.
decl_);
917 for (
size_t i = 0; i < decls.size(); ++i)
973 for (
size_t i = 0; i <
size; ++i) {
980 for (
size_t i = 1; i <
size; ++i) {
983 o_ <<
" " << name <<
";" <<
EOL;
991 for (
size_t i = 0; i < vs.size(); ++i)
992 boost::apply_visitor(vis,vs[i].decl_);
1011 std::vector<expression> ctor_args;
1015 std::vector<expression> ctor_args;
1018 : (
is_var_ ?
"T__" :
"double" ),
1022 std::vector<expression> ctor_args;
1023 ctor_args.push_back(x.
M_);
1025 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,1> "
1026 : (
is_var_ ?
"Eigen::Matrix<T__,Eigen::Dynamic,1> " :
"vector_d" ),
1030 std::vector<expression> ctor_args;
1031 ctor_args.push_back(x.
N_);
1033 ?
"Eigen::Matrix<fun_scalar_t__,1,Eigen::Dynamic> "
1035 ?
"Eigen::Matrix<T__,1,Eigen::Dynamic> "
1040 std::vector<expression> ctor_args;
1041 ctor_args.push_back(x.
M_);
1042 ctor_args.push_back(x.
N_);
1044 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,Eigen::Dynamic> "
1046 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1051 std::vector<expression> ctor_args;
1052 ctor_args.push_back(x.
K_);
1054 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,1> "
1055 : (
is_var_ ?
"Eigen::Matrix<T__,Eigen::Dynamic,1> " :
"vector_d" ),
1059 std::vector<expression> ctor_args;
1060 ctor_args.push_back(x.
K_);
1062 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,1> "
1063 : (
is_var_ ?
"Eigen::Matrix<T__,Eigen::Dynamic,1> " :
"vector_d"),
1067 std::vector<expression> ctor_args;
1068 ctor_args.push_back(x.
K_);
1070 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,1> "
1071 : (
is_var_ ?
"Eigen::Matrix<T__,Eigen::Dynamic,1> " :
"vector_d" ),
1075 std::vector<expression> ctor_args;
1076 ctor_args.push_back(x.
K_);
1078 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,1> "
1079 : (
is_var_ ?
"Eigen::Matrix<T__,Eigen::Dynamic,1> " :
"vector_d" ),
1083 std::vector<expression> ctor_args;
1084 ctor_args.push_back(x.
M_);
1085 ctor_args.push_back(x.
N_);
1087 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,Eigen::Dynamic> "
1089 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1094 std::vector<expression> ctor_args;
1095 ctor_args.push_back(x.
K_);
1096 ctor_args.push_back(x.
K_);
1098 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1103 std::vector<expression> ctor_args;
1104 ctor_args.push_back(x.
K_);
1105 ctor_args.push_back(x.
K_);
1107 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,Eigen::Dynamic> "
1109 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1114 std::vector<expression> ctor_args;
1115 ctor_args.push_back(x.
K_);
1116 ctor_args.push_back(x.
K_);
1118 ?
"Eigen::Matrix<fun_scalar_t__,Eigen::Dynamic,Eigen::Dynamic> "
1120 ?
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1125 size_t num_dims)
const {
1126 for (
size_t i = 0; i < num_dims; ++i)
1129 for (
size_t i = 0; i < num_dims; ++i) {
1130 if (i > 0)
o_ <<
" ";
1136 o_ <<
"(void) " << name <<
"; // dummy to suppress unused var warning";
1143 const std::vector<expression>& ctor_args,
1144 const std::vector<expression>& dims,
1146 if (dim < dims.size()) {
1149 if ((dim + 1 < dims.size()) || ctor_args.size() > 0) {
1154 }
else if (type ==
"var") {
1155 o_ <<
", DUMMY_VAR__";
1156 }
else if (type ==
"int") {
1158 }
else if (type ==
"double") {
1165 if (ctor_args.size() == 0) {
1166 if (type ==
"int") {
1168 }
else if (type ==
"double") {
1170 }
else if (type ==
"var") {
1171 o_ <<
"(DUMMY_VAR__)";
1176 else if (ctor_args.size() == 1) {
1180 }
else if (ctor_args.size() > 1) {
1190 const std::vector<expression>& ctor_args,
1191 const std::string& name,
1192 const std::vector<expression>& dims)
const {
1201 if (dims.size() == 0) {
1206 if (type ==
"Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic> "
1207 || type ==
"Eigen::Matrix<T__,1,Eigen::Dynamic> "
1208 || type ==
"Eigen::Matrix<T__,Eigen::Dynamic,1> ") {
1210 o_ <<
"stan::math::fill(" << name <<
",DUMMY_VAR__);" <<
EOL;
1219 bool is_fun_return) {
1221 for (
size_t i = 0; i < vs.size(); ++i)
1222 boost::apply_visitor(vis,vs[i].decl_);
1285 template <
typename T>
1288 o_ <<
"stan::math::initialize(" << x.name_ <<
", "
1289 << (
is_var_ ?
"DUMMY_VAR__" :
"std::numeric_limits<double>::quiet_NaN()")
1299 bool is_fun_return) {
1301 for (
size_t i = 0; i < vs.size(); ++i)
1302 boost::apply_visitor(vis,vs[i].decl_);
1317 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1321 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1325 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1329 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1333 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1337 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1341 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1345 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1349 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1353 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1357 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1361 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1365 o_ <<
"stan::math::fill(" << x.
name_ <<
",DUMMY_VAR__);" <<
EOL;
1374 generate_comment(
"initialized transformed params to avoid seg fault on val access",
1376 for (
size_t i = 0; i < vs.size(); ++i)
1377 boost::apply_visitor(vis,vs[i].decl_);
1399 dims.push_back(x.
M_);
1404 dims.push_back(x.
K_);
1409 dims.push_back(x.
K_);
1414 dims.push_back(x.
K_);
1419 dims.push_back(x.
K_);
1424 dims.push_back(x.
N_);
1429 dims.push_back(x.
M_);
1430 dims.push_back(x.
N_);
1435 dims.push_back(x.
M_);
1436 dims.push_back(x.
N_);
1441 dims.push_back(x.
K_);
1442 dims.push_back(x.
K_);
1447 dims.push_back(x.
K_);
1448 dims.push_back(x.
K_);
1453 dims.push_back(x.
K_);
1454 dims.push_back(x.
K_);
1458 const std::vector<expression>& dims,
1459 size_t matrix_dims)
const {
1461 size_t non_matrix_dims = dims.size() - matrix_dims;
1463 for (
size_t k = 0; k < dims.size(); ++k) {
1465 o_ <<
"for (int i" << k <<
"__ = 0; i" << k <<
"__ < ";
1467 o_ <<
"; ++i" << k <<
"__) {" <<
EOL;
1471 o_ <<
"if (stan::math::is_uninitialized(" << name;
1472 for (
size_t k = 0; k < non_matrix_dims; ++k)
1473 o_ <<
"[i" << k <<
"__]";
1474 if (matrix_dims > 0) {
1475 o_ <<
"(i" << non_matrix_dims <<
"__";
1476 if (matrix_dims > 1)
1477 o_ <<
",i" << (non_matrix_dims + 1) <<
"__";
1480 o_ <<
")) {" <<
EOL;
1482 o_ <<
"std::stringstream msg__;" <<
EOL;
1484 o_ <<
"msg__ << \"Undefined transformed parameter: "
1486 for (
size_t k = 0; k < dims.size(); ++k) {
1488 o_ <<
" << i" << k <<
"__";
1493 o_ <<
"throw std::runtime_error(msg__.str());" <<
EOL;
1497 for (
size_t k = 0; k < dims.size(); ++k) {
1509 for (
size_t i = 0; i < vs.size(); ++i)
1510 boost::apply_visitor(vis,vs[i].decl_);
1515 bool include_sampling,
bool is_var,
1516 bool is_fun_return);
1524 bool include_sampling,
1538 o_ <<
"stan::math::assign(";
1558 for (
size_t i = 0; i < x.
dist_.
args_.size(); ++i) {
1565 o_ <<
", pstream__";
1577 o_ <<
") lp_accum__.add(-std::numeric_limits<double>::infinity());" <<
EOL;
1587 o_ <<
") lp_accum__.add(-std::numeric_limits<double>::infinity());" <<
EOL;
1596 o_ <<
"lp_accum__.add(-log_diff_exp(";
1599 for (
size_t i = 0; i < x.
dist_.
args_.size(); ++i) {
1605 for (
size_t i = 0; i < x.
dist_.
args_.size(); ++i) {
1609 o_ <<
")));" <<
EOL;
1612 o_ <<
"lp_accum__.add(-";
1615 for (
size_t i = 0; i < x.
dist_.
args_.size(); ++i) {
1622 o_ <<
"lp_accum__.add(-";
1625 for (
size_t i = 0; i < x.
dist_.
args_.size(); ++i) {
1634 o_ <<
"lp_accum__.add(";
1641 if (has_local_vars) {
1654 if (has_local_vars) {
1661 o_ <<
"if (pstream__) {" <<
EOL;
1662 for (
size_t i = 0; i < ps.
printables_.size(); ++i) {
1664 o_ <<
"stan_print(pstream__,";
1669 o_ <<
"*pstream__ << std::endl;" <<
EOL;
1675 o_ <<
"std::stringstream errmsg_stream__;" <<
EOL;
1676 for (
size_t i = 0; i < ps.
printables_.size(); ++i) {
1678 o_ <<
"errmsg_stream__ << ";
1683 o_ <<
"throw std::domain_error(errmsg_stream__.str());" <<
EOL;
1690 o_ <<
"stan::math::promote_scalar<fun_return_scalar_t__>(";
1710 o_ <<
"while (as_bool(";
1712 o_ <<
")) {" <<
EOL;
1719 for (
size_t i = 0; i < x.
conditions_.size(); ++i) {
1724 o_ <<
"if (as_bool(";
1726 o_ <<
")) {" <<
EOL;
1733 o_ <<
" else {" <<
EOL;
1749 bool include_sampling,
1751 bool is_fun_return) {
1759 bool include_sampling,
1761 bool is_fun_return) {
1763 for (
size_t i = 0; i < ss.size(); ++i)
1764 boost::apply_visitor(vis,ss[i].statement_);
1773 o <<
INDENT <<
"template <bool propto__, bool jacobian__, typename T__>" <<
EOL;
1774 o <<
INDENT <<
"T__ log_prob(vector<T__>& params_r__," <<
EOL;
1775 o <<
INDENT <<
" vector<int>& params_i__," <<
EOL;
1776 o <<
INDENT <<
" std::ostream* pstream__ = 0) const {" <<
EOL2;
1779 o <<
INDENT2 <<
"T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" <<
EOL;
1780 o <<
INDENT2 <<
"(void) DUMMY_VAR__; // suppress unused var warning" <<
EOL2;
1783 o <<
INDENT2 <<
"stan::math::accumulator<T__> lp_accum__;" <<
EOL2;
1786 bool is_fun_return =
false;
1797 bool include_sampling =
true;
1799 is_var,is_fun_return);
1804 <<
"const char* function__ = \"validate transformed params %1%\";"
1807 <<
"(void) function__; // dummy to suppress unused var warning"
1814 is_var,is_fun_return);
1816 o <<
INDENT2 <<
"lp_accum__.add(lp__);" <<
EOL;
1817 o <<
INDENT2 <<
"return lp_accum__.sum();" <<
EOL2;
1820 o <<
INDENT <<
"template <bool propto, bool jacobian, typename T_>" <<
EOL;
1821 o <<
INDENT <<
"T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r," <<
EOL;
1822 o <<
INDENT <<
" std::ostream* pstream = 0) const {" <<
EOL;
1823 o <<
INDENT <<
" std::vector<T_> vec_params_r;" <<
EOL;
1824 o <<
INDENT <<
" vec_params_r.reserve(params_r.size());" <<
EOL;
1825 o <<
INDENT <<
" for (int i = 0; i < params_r.size(); ++i)" <<
EOL;
1826 o <<
INDENT <<
" vec_params_r.push_back(params_r(i));" <<
EOL;
1827 o <<
INDENT <<
" std::vector<int> vec_params_i;" <<
EOL;
1828 o <<
INDENT <<
" return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);" <<
EOL;
1842 std::vector<expression> dims = x.
dims_;
1847 size_t indentation = 1;
1848 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
1849 size_t dim = dims.size() - dim_up - 1U;
1852 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
1856 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_"
1857 << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim
1858 <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
1862 for (
size_t dim = 0; dim < dims.size(); ++dim)
1863 o_ <<
"[i_" << dim <<
"__]";
1864 o_ <<
" = vals_i__[pos__++];" <<
EOL;
1865 for (
size_t dim = 0; dim < dims.size(); ++dim) {
1872 std::vector<expression> dims = x.
dims_;
1877 size_t indentation = 1;
1878 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
1879 size_t dim = dims.size() - dim_up - 1U;
1882 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
1886 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
1890 for (
size_t dim = 0; dim < dims.size(); ++dim)
1891 o_ <<
"[i_" << dim <<
"__]";
1892 o_ <<
" = vals_r__[pos__++];" <<
EOL;
1893 for (
size_t dim = 0; dim < dims.size(); ++dim) {
1900 std::vector<expression> dims = x.
dims_;
1908 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
1909 size_t indentation = 2;
1910 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
1911 size_t dim = dims.size() - dim_up - 1U;
1914 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
1918 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
1922 for (
size_t dim = 0; dim < dims.size(); ++dim)
1923 o_ <<
"[i_" << dim <<
"__]";
1925 o_ <<
" = vals_r__[pos__++];" <<
EOL;
1926 for (
size_t dim = 0; dim < dims.size(); ++dim) {
1934 std::vector<expression> dims = x.
dims_;
1942 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
1943 size_t indentation = 2;
1944 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
1945 size_t dim = dims.size() - dim_up - 1U;
1948 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
1952 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
1956 for (
size_t dim = 0; dim < dims.size(); ++dim)
1957 o_ <<
"[i_" << dim <<
"__]";
1959 o_ <<
" = vals_r__[pos__++];" <<
EOL;
1960 for (
size_t dim = 0; dim < dims.size(); ++dim) {
1968 std::vector<expression> dims = x.
dims_;
1976 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
1977 size_t indentation = 2;
1978 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
1979 size_t dim = dims.size() - dim_up - 1U;
1982 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
1986 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
1990 for (
size_t dim = 0; dim < dims.size(); ++dim)
1991 o_ <<
"[i_" << dim <<
"__]";
1993 o_ <<
" = vals_r__[pos__++];" <<
EOL;
1994 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2002 std::vector<expression> dims = x.
dims_;
2010 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
2011 size_t indentation = 2;
2012 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2013 size_t dim = dims.size() - dim_up - 1U;
2016 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2020 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2024 for (
size_t dim = 0; dim < dims.size(); ++dim)
2025 o_ <<
"[i_" << dim <<
"__]";
2027 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2028 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2036 std::vector<expression> dims = x.
dims_;
2044 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
2045 size_t indentation = 2;
2046 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2047 size_t dim = dims.size() - dim_up - 1U;
2050 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2054 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2058 for (
size_t dim = 0; dim < dims.size(); ++dim)
2059 o_ <<
"[i_" << dim <<
"__]";
2061 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2062 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2070 std::vector<expression> dims = x.
dims_;
2078 o_ <<
INDENT2 <<
"for (size_t " <<
"i_vec__ = 0; " <<
"i_vec__ < " << x.
name_ <<
"_i_vec_lim__; ++i_vec__) {" <<
EOL;
2079 size_t indentation = 2;
2080 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2081 size_t dim = dims.size() - dim_up - 1U;
2084 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2088 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2092 for (
size_t dim = 0; dim < dims.size(); ++dim)
2093 o_ <<
"[i_" << dim <<
"__]";
2095 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2096 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2104 std::vector<expression> dims = x.
dims_;
2115 o_ <<
INDENT2 <<
"for (size_t " <<
"n_mat__ = 0; " <<
"n_mat__ < " << x.
name_ <<
"_n_mat_lim__; ++n_mat__) {" <<
EOL;
2116 o_ <<
INDENT3 <<
"for (size_t " <<
"m_mat__ = 0; " <<
"m_mat__ < " << x.
name_ <<
"_m_mat_lim__; ++m_mat__) {" <<
EOL;
2117 size_t indentation = 3;
2118 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2119 size_t dim = dims.size() - dim_up - 1U;
2122 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2126 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2130 for (
size_t dim = 0; dim < dims.size(); ++dim)
2131 o_ <<
"[i_" << dim <<
"__]";
2132 o_ <<
"(m_mat__,n_mat__)";
2133 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2134 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2143 std::vector<expression> dims = x.
dims_;
2151 o_ <<
INDENT2 <<
"for (size_t " <<
"n_mat__ = 0; " <<
"n_mat__ < " << x.
name_ <<
"_k_mat_lim__; ++n_mat__) {" <<
EOL;
2152 o_ <<
INDENT3 <<
"for (size_t " <<
"m_mat__ = 0; " <<
"m_mat__ < " << x.
name_ <<
"_k_mat_lim__; ++m_mat__) {" <<
EOL;
2153 size_t indentation = 3;
2154 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2155 size_t dim = dims.size() - dim_up - 1U;
2158 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2162 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2166 for (
size_t dim = 0; dim < dims.size(); ++dim)
2167 o_ <<
"[i_" << dim <<
"__]";
2168 o_ <<
"(m_mat__,n_mat__)";
2169 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2170 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2179 std::vector<expression> dims = x.
dims_;
2193 o_ <<
INDENT2 <<
"for (size_t " <<
"n_mat__ = 0; " <<
"n_mat__ < " << x.
name_ <<
"_n_mat_lim__; ++n_mat__) {" <<
EOL;
2194 o_ <<
INDENT3 <<
"for (size_t " <<
"m_mat__ = 0; " <<
"m_mat__ < " << x.
name_ <<
"_m_mat_lim__; ++m_mat__) {" <<
EOL;
2196 size_t indentation = 3;
2197 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2198 size_t dim = dims.size() - dim_up - 1U;
2201 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2205 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {"
2210 for (
size_t dim = 0; dim < dims.size(); ++dim)
2211 o_ <<
"[i_" << dim <<
"__]";
2212 o_ <<
"(m_mat__,n_mat__)";
2213 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2214 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2224 std::vector<expression> dims = x.
dims_;
2238 o_ <<
INDENT2 <<
"for (size_t " <<
"n_mat__ = 0; " <<
"n_mat__ < " << x.
name_ <<
"_n_mat_lim__; ++n_mat__) {" <<
EOL;
2239 o_ <<
INDENT3 <<
"for (size_t " <<
"m_mat__ = 0; " <<
"m_mat__ < " << x.
name_ <<
"_m_mat_lim__; ++m_mat__) {" <<
EOL;
2241 size_t indentation = 3;
2242 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2243 size_t dim = dims.size() - dim_up - 1U;
2246 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2250 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {"
2255 for (
size_t dim = 0; dim < dims.size(); ++dim)
2256 o_ <<
"[i_" << dim <<
"__]";
2257 o_ <<
"(m_mat__,n_mat__)";
2258 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2259 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2268 std::vector<expression> dims = x.
dims_;
2276 o_ <<
INDENT2 <<
"for (size_t " <<
"n_mat__ = 0; " <<
"n_mat__ < " << x.
name_ <<
"_k_mat_lim__; ++n_mat__) {" <<
EOL;
2277 o_ <<
INDENT3 <<
"for (size_t " <<
"m_mat__ = 0; " <<
"m_mat__ < " << x.
name_ <<
"_k_mat_lim__; ++m_mat__) {" <<
EOL;
2278 size_t indentation = 3;
2279 for (
size_t dim_up = 0U; dim_up < dims.size(); ++dim_up) {
2280 size_t dim = dims.size() - dim_up - 1U;
2283 o_ <<
"size_t " << x.
name_ <<
"_limit_" << dim <<
"__ = ";
2287 o_ <<
"for (size_t i_" << dim <<
"__ = 0; i_" << dim <<
"__ < " << x.
name_ <<
"_limit_" << dim <<
"__; ++i_" << dim <<
"__) {" <<
EOL;
2291 for (
size_t dim = 0; dim < dims.size(); ++dim)
2292 o_ <<
"[i_" << dim <<
"__]";
2293 o_ <<
"(m_mat__,n_mat__)";
2294 o_ <<
" = vals_r__[pos__++];" <<
EOL;
2295 for (
size_t dim = 0; dim < dims.size(); ++dim) {
2305 const std::string& var_name,
2307 o << indent <<
"(void) "
2309 <<
" // dummy call to supress warning"
2316 for (
size_t i = 0; i < vs.size(); ++i)
2317 boost::apply_visitor(vis, vs[i].decl_);
2323 <<
INDENT <<
"~" << model_name <<
"() { }"
2336 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2338 o_ <<
"for (size_t i_" << i <<
"__ = 0; ";
2339 o_ <<
"i_" << i <<
"__ < ";
2341 o_ <<
"; ++i_" << i <<
"__) {" <<
EOL;
2345 o_ <<
"param_ranges_i__.push_back(std::pair<int,int>(";
2351 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2373 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2384 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2397 o_ <<
INDENT2 <<
"num_params_r__ += ((";
2402 o_ <<
" + 1)) / 2 + (";
2409 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2417 o_ <<
INDENT2 <<
"num_params_r__ += ((";
2421 o_ <<
" - 1)) / 2)";
2422 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2430 o_ <<
INDENT2 <<
"num_params_r__ += ((";
2434 o_ <<
" - 1)) / 2 + ";
2437 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2444 o_ <<
INDENT2 <<
"num_params_r__ += ((";
2448 o_ <<
" - 1)) / 2)";
2449 for (
size_t i = 0; i < x.
dims_.size(); ++i) {
2457 if (dims.size() == 0) {
2462 for (
size_t i = 0; i < dims.size(); ++i) {
2463 if (i > 0)
o_ <<
" * ";
2469 if (dims.size() == 0) {
2474 for (
size_t i = 0; i < dims.size(); ++i) {
2475 if (i > 0)
o_ <<
" * ";
2481 std::vector<expression> dims)
const {
2484 for (
size_t i = 0; i < dims.size(); ++i) {
2492 std::vector<expression> dims)
const {
2497 for (
size_t i = 0; i < dims.size(); ++i) {
2509 o <<
INDENT2 <<
"num_params_r__ = 0U;" <<
EOL;
2510 o <<
INDENT2 <<
"param_ranges_i__.clear();" <<
EOL;
2512 for (
size_t i = 0; i < var_decls.size(); ++i)
2513 boost::apply_visitor(vis,var_decls[i].decl_);
2518 const std::string& model_name,
2520 o <<
INDENT << model_name <<
"(stan::io::var_context& context__," <<
EOL;
2521 o <<
INDENT <<
" std::ostream* pstream__ = 0)"
2523 o <<
INDENT2 <<
": prob_grad(0) {"
2525 o <<
INDENT2 <<
"static const char* function__ = \""
2526 << model_name <<
"_namespace::" << model_name <<
"(%1%)\";" <<
EOL;
2530 o <<
INDENT2 <<
"std::vector<int> vals_i__;" <<
EOL;
2531 o <<
INDENT2 <<
"std::vector<double> vals_r__;" <<
EOL;
2541 bool include_sampling =
false;
2543 bool is_fun_return =
false;
2546 2,o,include_sampling,is_var,is_fun_return);
2574 template <
typename D>
2577 std::stringstream ss;
2580 ss <<
"_lub_unconstrain(";
2586 ss <<
"_lb_unconstrain(";
2590 ss <<
"_ub_unconstrain(";
2594 ss <<
"_unconstrain(";
2688 const std::string& var_name,
2689 const std::vector<expression>& dims)
const {
2691 o_ <<
"try { writer__." << write_method_name;
2693 o_ <<
"); } catch (const std::exception& e) { "
2694 " throw std::runtime_error(std::string(\"Error transforming variable "
2695 << var_name <<
": \") + e.what()); }" <<
EOL;
2698 size_t num_dims)
const {
2700 for (
size_t i = 0; i < num_dims; ++i)
2701 o_ <<
"[i" << i <<
"__]";
2704 const std::string& base_type,
2705 const std::vector<expression>& dims,
2715 const std::vector<expression>& dims,
2723 const std::string& name,
2724 const std::vector<expression>& dims,
2727 int indent = 2U)
const {
2728 size_t size = dims.size();
2731 int extra_indent = is_matrix ? 2U : is_vector ? 1U : 0U;
2734 o_ <<
"for (int j2__ = 0U; j2__ < ";
2736 o_ <<
"; ++j2__)" <<
EOL;
2739 o_ <<
"for (int j1__ = 0U; j1__ < ";
2741 o_ <<
"; ++j1__)" <<
EOL;
2742 }
else if (is_vector) {
2744 o_ <<
"for (int j1__ = 0U; j1__ < ";
2746 o_ <<
"; ++j1__)" <<
EOL;
2748 for (
size_t i = 0; i <
size; ++i) {
2749 size_t idx = size - i - 1;
2751 o_ <<
"for (int i" << idx <<
"__ = 0U; i" << idx <<
"__ < ";
2753 o_ <<
"; ++i" << idx <<
"__)" <<
EOL;
2757 for (
size_t i = 0; i < dims.size(); ++i)
2758 o_ <<
"[i" << i <<
"__]";
2760 o_ <<
"(j1__,j2__)";
2763 o_ <<
" = vals_" << base_type <<
"__[pos__++];" <<
EOL;
2766 int indent = 2U)
const {
2767 size_t size = dims.size();
2768 for (
size_t i = 0; i <
size; ++i) {
2770 o_ <<
"for (int i" << i <<
"__ = 0U; i" << i <<
"__ < ";
2772 o_ <<
"; ++i" << i <<
"__)" <<
EOL;
2778 <<
"if (!(context__.contains_i(\"" << name <<
"\")))"
2780 <<
"throw std::runtime_error(\"variable " << name <<
" missing\");" <<
EOL;
2781 o_ <<
INDENT2 <<
"vals_i__ = context__.vals_i(\"" << name <<
"\");" <<
EOL;
2786 <<
"if (!(context__.contains_r(\"" << name <<
"\")))"
2788 <<
"throw std::runtime_error(\"variable " << name <<
" missing\");" <<
EOL;
2789 o_ <<
INDENT2 <<
"vals_r__ = context__.vals_r(\"" << name <<
"\");" <<
EOL;
2798 o <<
INDENT <<
"void transform_inits(const stan::io::var_context& context__," <<
EOL;
2799 o <<
INDENT <<
" std::vector<int>& params_i__," <<
EOL;
2800 o <<
INDENT <<
" std::vector<double>& params_r__) const {" <<
EOL;
2801 o <<
INDENT2 <<
"stan::io::writer<double> writer__(params_r__,params_i__);" <<
EOL;
2803 o <<
INDENT2 <<
"(void) pos__; // dummy call to supress warning" <<
EOL;
2804 o <<
INDENT2 <<
"std::vector<double> vals_r__;" <<
EOL;
2805 o <<
INDENT2 <<
"std::vector<int> vals_i__;" <<
EOL;
2808 for (
size_t i = 0; i < vs.size(); ++i)
2809 boost::apply_visitor(vis, vs[i].decl_);
2811 o <<
INDENT2 <<
"params_r__ = writer__.data_r();" <<
EOL;
2812 o <<
INDENT2 <<
"params_i__ = writer__.data_i();" <<
EOL;
2815 o <<
INDENT <<
"void transform_inits(const stan::io::var_context& context," <<
EOL;
2816 o <<
INDENT <<
" Eigen::Matrix<double,Eigen::Dynamic,1>& params_r) const {" <<
EOL;
2817 o <<
INDENT <<
" std::vector<double> params_r_vec;" <<
EOL;
2818 o <<
INDENT <<
" std::vector<int> params_i_vec;" <<
EOL;
2819 o <<
INDENT <<
" transform_inits(context, params_i_vec, params_r_vec);" <<
EOL;
2820 o <<
INDENT <<
" params_r.resize(params_r_vec.size());" <<
EOL;
2821 o <<
INDENT <<
" for (int i = 0; i < params_r.size(); ++i)" <<
EOL;
2822 o <<
INDENT <<
" params_r(i) = params_r_vec[i];" <<
EOL;
2839 std::vector<expression> matrix_args;
2840 matrix_args.push_back(x.
M_);
2844 std::vector<expression> matrix_args;
2845 matrix_args.push_back(x.
N_);
2849 std::vector<expression> matrix_args;
2850 matrix_args.push_back(x.
M_);
2851 matrix_args.push_back(x.
N_);
2855 std::vector<expression> matrix_args;
2856 matrix_args.push_back(x.
K_);
2860 std::vector<expression> matrix_args;
2861 matrix_args.push_back(x.
K_);
2865 std::vector<expression> matrix_args;
2866 matrix_args.push_back(x.
K_);
2870 std::vector<expression> matrix_args;
2871 matrix_args.push_back(x.
K_);
2875 std::vector<expression> matrix_args;
2876 matrix_args.push_back(x.
M_);
2877 matrix_args.push_back(x.
N_);
2881 std::vector<expression> matrix_args;
2882 matrix_args.push_back(x.
K_);
2883 matrix_args.push_back(x.
K_);
2887 std::vector<expression> matrix_args;
2888 matrix_args.push_back(x.
K_);
2889 matrix_args.push_back(x.
K_);
2893 std::vector<expression> matrix_args;
2894 matrix_args.push_back(x.
K_);
2895 matrix_args.push_back(x.
K_);
2900 const std::vector<expression>& array_dims_exprs)
2904 for (
size_t i = 0; i < array_dims_exprs.size(); ++i) {
2910 for (
size_t i = 0; i < matrix_dims_exprs.size(); ++i) {
2924 <<
"void get_dims(std::vector<std::vector<size_t> >& dimss__) const {"
2928 o <<
INDENT2 <<
"std::vector<size_t> dims__;" <<
EOL;
2935 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i) {
2936 boost::apply_visitor(vis,prog.
derived_decl_.first[i].decl_);
2995 <<
"names__.push_back(\"" << name <<
"\");"
3005 <<
"void get_param_names(std::vector<std::string>& names__) const {"
3009 <<
"names__.resize(0);"
3017 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i) {
3018 boost::apply_visitor(vis,prog.
derived_decl_.first[i].decl_);
3043 std::vector<expression> matrix_args;
3044 matrix_args.push_back(x.
M_);
3048 std::vector<expression> matrix_args;
3049 matrix_args.push_back(x.
N_);
3053 std::vector<expression> matrix_args;
3054 matrix_args.push_back(x.
M_);
3055 matrix_args.push_back(x.
N_);
3059 std::vector<expression> matrix_args;
3060 matrix_args.push_back(x.
K_);
3064 std::vector<expression> matrix_args;
3065 matrix_args.push_back(x.
K_);
3069 std::vector<expression> matrix_args;
3070 matrix_args.push_back(x.
K_);
3074 std::vector<expression> matrix_args;
3075 matrix_args.push_back(x.
K_);
3079 std::vector<expression> matrix_args;
3080 matrix_args.push_back(x.
M_);
3081 matrix_args.push_back(x.
N_);
3085 std::vector<expression> matrix_args;
3086 matrix_args.push_back(x.
K_);
3087 matrix_args.push_back(x.
K_);
3091 std::vector<expression> matrix_args;
3092 matrix_args.push_back(x.
K_);
3093 matrix_args.push_back(x.
K_);
3097 std::vector<expression> matrix_args;
3098 matrix_args.push_back(x.
K_);
3099 matrix_args.push_back(x.
K_);
3104 const std::string& name,
3105 const std::vector<expression>& dims)
const {
3108 std::vector<expression> combo_dims(dims);
3109 for (
size_t i = 0; i < matrix_dims.size(); ++i)
3110 combo_dims.push_back(matrix_dims[i]);
3112 for (
size_t i = combo_dims.size(); i-- > 0; ) {
3114 o_ <<
"for (int k_" << i <<
"__ = 1;"
3115 <<
" k_" << i <<
"__ <= ";
3117 o_ <<
"; ++k_" << i <<
"__) {" <<
EOL;
3122 o_ <<
"writer__.comma();" <<
EOL;
3125 o_ <<
"o__ << \"" << name <<
'"';
3126 for (
size_t i = 0; i < combo_dims.size(); ++i)
3127 o_ <<
" << '.' << k_" << i <<
"__";
3131 for (
size_t i = 0; i < combo_dims.size(); ++i) {
3176 o <<
EOL <<
INDENT <<
"void write_csv_header(std::ostream& o__) const {" <<
EOL;
3177 o <<
INDENT2 <<
"stan::io::csv_writer writer__(o__);" <<
EOL;
3184 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i) {
3185 boost::apply_visitor(vis,prog.
derived_decl_.first[i].decl_);
3191 o <<
INDENT2 <<
"writer__.newline();" <<
EOL;
3208 std::vector<expression> matrix_args;
3209 matrix_args.push_back(x.
M_);
3213 std::vector<expression> matrix_args;
3214 matrix_args.push_back(x.
N_);
3218 std::vector<expression> matrix_args;
3219 matrix_args.push_back(x.
M_);
3220 matrix_args.push_back(x.
N_);
3224 std::vector<expression> matrix_args;
3225 matrix_args.push_back(x.
K_);
3229 std::vector<expression> matrix_args;
3230 matrix_args.push_back(x.
K_);
3234 std::vector<expression> matrix_args;
3235 matrix_args.push_back(x.
K_);
3239 std::vector<expression> matrix_args;
3240 matrix_args.push_back(x.
K_);
3244 std::vector<expression> matrix_args;
3245 matrix_args.push_back(x.
M_);
3246 matrix_args.push_back(x.
N_);
3250 std::vector<expression> matrix_args;
3251 matrix_args.push_back(x.
K_);
3252 matrix_args.push_back(x.
K_);
3256 std::vector<expression> matrix_args;
3257 matrix_args.push_back(x.
K_);
3258 matrix_args.push_back(x.
K_);
3262 std::vector<expression> matrix_args;
3263 matrix_args.push_back(x.
K_);
3264 matrix_args.push_back(x.
K_);
3269 const std::string& name,
3270 const std::vector<expression>& dims)
const {
3273 std::vector<expression> combo_dims(dims);
3274 for (
size_t i = 0; i < matrix_dims.size(); ++i)
3275 combo_dims.push_back(matrix_dims[i]);
3277 for (
size_t i = combo_dims.size(); i-- > 0; ) {
3279 o_ <<
"for (int k_" << i <<
"__ = 1;"
3280 <<
" k_" << i <<
"__ <= ";
3282 o_ <<
"; ++k_" << i <<
"__) {" <<
EOL;
3286 o_ <<
"param_name_stream__.str(std::string());" <<
EOL;
3289 o_ <<
"param_name_stream__ << \"" << name <<
'"';
3291 for (
size_t i = 0; i < combo_dims.size(); ++i)
3292 o_ <<
" << '.' << k_" << i <<
"__";
3296 o_ <<
"param_names__.push_back(param_name_stream__.str());" <<
EOL;
3299 for (
size_t i = 0; i < combo_dims.size(); ++i) {
3311 <<
"void constrained_param_names(std::vector<std::string>& param_names__,"
3313 <<
" bool include_tparams__ = true,"
3315 <<
" bool include_gqs__ = true) const {"
3317 <<
"std::stringstream param_name_stream__;" <<
EOL;
3326 <<
"if (!include_gqs__ && !include_tparams__) return;"
3330 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i) {
3331 boost::apply_visitor(vis,prog.
derived_decl_.first[i].decl_);
3335 <<
"if (!include_gqs__) return;"
3359 std::vector<expression> matrix_args;
3360 matrix_args.push_back(x.
M_);
3364 std::vector<expression> matrix_args;
3365 matrix_args.push_back(x.
N_);
3369 std::vector<expression> matrix_args;
3370 matrix_args.push_back(x.
M_);
3371 matrix_args.push_back(x.
N_);
3375 std::vector<expression> matrix_args;
3380 std::vector<expression> matrix_args;
3385 std::vector<expression> matrix_args;
3386 matrix_args.push_back(x.
K_);
3390 std::vector<expression> matrix_args;
3391 matrix_args.push_back(x.
K_);
3396 std::vector<expression> matrix_args;
3415 std::vector<expression> matrix_args;
3427 std::vector<expression> matrix_args;
3440 std::vector<expression> matrix_args;
3453 const std::string& name,
3454 const std::vector<expression>& dims)
const {
3457 std::vector<expression> combo_dims(dims);
3458 for (
size_t i = 0; i < matrix_dims.size(); ++i)
3459 combo_dims.push_back(matrix_dims[i]);
3461 for (
size_t i = combo_dims.size(); i-- > 0; ) {
3463 o_ <<
"for (int k_" << i <<
"__ = 1;"
3464 <<
" k_" << i <<
"__ <= ";
3466 o_ <<
"; ++k_" << i <<
"__) {" <<
EOL;
3470 o_ <<
"param_name_stream__.str(std::string());" <<
EOL;
3473 o_ <<
"param_name_stream__ << \"" << name <<
'"';
3475 for (
size_t i = 0; i < combo_dims.size(); ++i)
3476 o_ <<
" << '.' << k_" << i <<
"__";
3480 o_ <<
"param_names__.push_back(param_name_stream__.str());" <<
EOL;
3483 for (
size_t i = 0; i < combo_dims.size(); ++i) {
3494 <<
"void unconstrained_param_names(std::vector<std::string>& param_names__,"
3496 <<
" bool include_tparams__ = true,"
3498 <<
" bool include_gqs__ = true) const {"
3500 <<
"std::stringstream param_name_stream__;" <<
EOL;
3509 <<
"if (!include_gqs__ && !include_tparams__) return;"
3513 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i) {
3514 boost::apply_visitor(vis,prog.
derived_decl_.first[i].decl_);
3518 <<
"if (!include_gqs__) return;"
3535 template <
typename D>
3537 const std::string& read_fun_prefix,
3538 const std::vector<expression>& dim_args)
const {
3539 std::vector<expression> read_args;
3540 std::string read_fun(read_fun_prefix);
3543 read_args.push_back(x.range_.low_);
3544 read_args.push_back(x.range_.high_);
3547 read_args.push_back(x.range_.low_);
3550 read_args.push_back(x.range_.high_);
3552 for (
size_t i = 0; i < dim_args.size(); ++i)
3553 read_args.push_back(dim_args[i]);
3562 std::vector<expression> read_args;
3566 std::vector<expression> read_args;
3567 read_args.push_back(x.
M_);
3571 std::vector<expression> read_args;
3572 read_args.push_back(x.
N_);
3576 std::vector<expression> read_args;
3577 read_args.push_back(x.
M_);
3578 read_args.push_back(x.
N_);
3582 std::vector<expression> read_args;
3583 read_args.push_back(x.
K_);
3587 std::vector<expression> read_args;
3588 read_args.push_back(x.
K_);
3592 std::vector<expression> read_args;
3593 read_args.push_back(x.
K_);
3597 std::vector<expression> read_args;
3598 read_args.push_back(x.
K_);
3602 std::vector<expression> read_args;
3603 read_args.push_back(x.
M_);
3604 read_args.push_back(x.
N_);
3608 std::vector<expression> read_args;
3609 read_args.push_back(x.
K_);
3613 std::vector<expression> read_args;
3614 read_args.push_back(x.
K_);
3618 std::vector<expression> read_args;
3619 read_args.push_back(x.
K_);
3623 const std::string& read_type,
3624 const std::vector<expression>& read_args,
3625 const std::string& name,
3626 const std::vector<expression>& dims)
const {
3627 if (dims.size() == 0) {
3629 o_ << var_type <<
" ";
3630 o_ << name <<
" = in__." << read_type <<
"_constrain(";
3631 for (
size_t j = 0; j < read_args.size(); ++j) {
3632 if (j > 0)
o_ <<
",";
3636 o_ <<
INDENT2 <<
"writer__.write(" << name <<
");" <<
EOL;
3640 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"vector<";
3642 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"> ";
3643 o_ << name <<
";" <<
EOL;
3644 std::string name_dims(name);
3645 for (
size_t i = 0; i < dims.size(); ++i) {
3647 o_ <<
"size_t dim_" << name <<
"_" << i <<
"__ = ";
3650 if (i < dims.size() - 1) {
3652 o_ << name_dims <<
".resize(dim_" << name <<
"_" << i <<
"__);"
3654 name_dims.append(
"[k_").append(
to_string(i)).append(
"__]");
3657 o_ <<
"for (size_t k_" << i <<
"__ = 0;"
3658 <<
" k_" << i <<
"__ < dim_" << name <<
"_" << i <<
"__;"
3659 <<
" ++k_" << i <<
"__) {" <<
EOL;
3660 if (i == dims.size() - 1) {
3662 o_ << name_dims <<
".push_back(in__." << read_type <<
"_constrain(";
3663 for (
size_t j = 0; j < read_args.size(); ++j) {
3664 if (j > 0)
o_ <<
",";
3671 o_ <<
"writer__.write(" << name;
3672 if (dims.size() > 0) {
3674 for (
size_t i = 0; i < dims.size(); ++i) {
3675 if (i > 0)
o_ <<
"][";
3676 o_ <<
"k_" << i <<
"__";
3682 for (
size_t i = dims.size(); i > 0; --i) {
3738 const std::vector<expression>& dims)
const {
3739 if (dims.size() == 0) {
3740 o_ <<
INDENT2 <<
"writer__.write(" << name <<
");" <<
EOL;
3743 for (
size_t i = 0; i < dims.size(); ++i) {
3745 o_ <<
"for (int k_" << i <<
"__ = 0;"
3746 <<
" k_" << i <<
"__ < ";
3748 o_ <<
"; ++k_" << i <<
"__) {" <<
EOL;
3752 o_ <<
"writer__.write(" << name;
3753 if (dims.size() > 0) {
3755 for (
size_t i = 0; i < dims.size(); ++i) {
3756 if (i > 0)
o_ <<
"][";
3757 o_ <<
"k_" << i <<
"__";
3763 for (
size_t i = dims.size(); i > 0; --i) {
3772 const std::string& model_name,
3774 o <<
INDENT <<
"template <typename RNG>" <<
EOL;
3775 o <<
INDENT <<
"void write_csv(RNG& base_rng__," <<
EOL;
3776 o <<
INDENT <<
" std::vector<double>& params_r__," <<
EOL;
3777 o <<
INDENT <<
" std::vector<int>& params_i__," <<
EOL;
3778 o <<
INDENT <<
" std::ostream& o__," <<
EOL;
3779 o <<
INDENT <<
" std::ostream* pstream__ = 0) const {" <<
EOL;
3780 o <<
INDENT2 <<
"stan::io::reader<double> in__(params_r__,params_i__);"
3782 o <<
INDENT2 <<
"stan::io::csv_writer writer__(o__);" <<
EOL;
3783 o <<
INDENT2 <<
"static const char* function__ = \""
3784 << model_name <<
"_namespace::write_csv(%1%)\";" <<
EOL;
3803 o <<
INDENT2 <<
"stan::math::accumulator<double> lp_accum__;" <<
EOL2;
3805 bool is_fun_return =
false;
3807 is_var,is_fun_return);
3809 bool include_sampling =
false;
3811 is_var,is_fun_return);
3818 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i)
3819 boost::apply_visitor(vis_writer, prog.
derived_decl_.first[i].decl_);
3826 is_var,is_fun_return);
3835 boost::apply_visitor(vis_writer, prog.
generated_decl_.first[i].decl_);
3839 o <<
INDENT2 <<
"writer__.newline();" <<
EOL;
3842 o <<
INDENT <<
"template <typename RNG>" <<
EOL;
3843 o <<
INDENT <<
"void write_csv(RNG& base_rng," <<
EOL;
3844 o <<
INDENT <<
" Eigen::Matrix<double,Eigen::Dynamic,1>& params_r," <<
EOL;
3845 o <<
INDENT <<
" std::ostream& o," <<
EOL;
3846 o <<
INDENT <<
" std::ostream* pstream = 0) const {" <<
EOL;
3847 o <<
INDENT <<
" std::vector<double> params_r_vec(params_r.size());" <<
EOL;
3848 o <<
INDENT <<
" for (int i = 0; i < params_r.size(); ++i)" <<
EOL;
3849 o <<
INDENT <<
" params_r_vec[i] = params_r(i);" <<
EOL;
3850 o <<
INDENT <<
" std::vector<int> params_i_vec; // dummy" <<
EOL;
3851 o <<
INDENT <<
" write_csv(base_rng, params_r_vec, params_i_vec, o, pstream);" <<
EOL;
3867 template <
typename D>
3869 const std::string& read_fun_prefix,
3870 const std::vector<expression>& dim_args)
const {
3871 std::vector<expression> read_args;
3872 std::string read_fun(read_fun_prefix);
3875 read_args.push_back(x.range_.low_);
3876 read_args.push_back(x.range_.high_);
3879 read_args.push_back(x.range_.low_);
3882 read_args.push_back(x.range_.high_);
3884 for (
size_t i = 0; i < dim_args.size(); ++i)
3885 read_args.push_back(dim_args[i]);
3890 std::vector<expression> read_args;
3894 std::vector<expression> read_args;
3895 read_args.push_back(x.
M_);
3899 std::vector<expression> read_args;
3900 read_args.push_back(x.
N_);
3904 std::vector<expression> read_args;
3905 read_args.push_back(x.
M_);
3906 read_args.push_back(x.
N_);
3910 std::vector<expression> read_args;
3911 read_args.push_back(x.
K_);
3915 std::vector<expression> read_args;
3916 read_args.push_back(x.
K_);
3920 std::vector<expression> read_args;
3921 read_args.push_back(x.
K_);
3925 std::vector<expression> read_args;
3926 read_args.push_back(x.
K_);
3930 std::vector<expression> read_args;
3931 read_args.push_back(x.
M_);
3932 read_args.push_back(x.
N_);
3936 std::vector<expression> read_args;
3937 read_args.push_back(x.
K_);
3941 std::vector<expression> read_args;
3942 read_args.push_back(x.
K_);
3946 std::vector<expression> read_args;
3947 read_args.push_back(x.
K_);
3951 const std::string& read_type,
3952 const std::vector<expression>& read_args,
3953 const std::string& name,
3954 const std::vector<expression>& dims)
const {
3955 if (dims.size() == 0) {
3957 o_ << var_type <<
" ";
3958 o_ << name <<
" = in__." << read_type <<
"_constrain(";
3959 for (
size_t j = 0; j < read_args.size(); ++j) {
3960 if (j > 0)
o_ <<
",";
3967 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"vector<";
3969 for (
size_t i = 0; i < dims.size(); ++i)
o_ <<
"> ";
3970 o_ << name <<
";" <<
EOL;
3971 std::string name_dims(name);
3972 for (
size_t i = 0; i < dims.size(); ++i) {
3974 o_ <<
"size_t dim_" << name <<
"_" << i <<
"__ = ";
3977 if (i < dims.size() - 1) {
3979 o_ << name_dims <<
".resize(dim_" << name <<
"_" << i <<
"__);"
3981 name_dims.append(
"[k_").append(
to_string(i)).append(
"__]");
3984 o_ <<
"for (size_t k_" << i <<
"__ = 0;"
3985 <<
" k_" << i <<
"__ < dim_" << name <<
"_" << i <<
"__;"
3986 <<
" ++k_" << i <<
"__) {" <<
EOL;
3987 if (i == dims.size() - 1) {
3989 o_ << name_dims <<
".push_back(in__." << read_type <<
"_constrain(";
3990 for (
size_t j = 0; j < read_args.size(); ++j) {
3991 if (j > 0)
o_ <<
",";
3998 for (
size_t i = dims.size(); i > 0; --i) {
4024 dims.push_back(x.
M_);
4029 dims.push_back(x.
N_);
4033 std::vector<expression> matdims;
4034 matdims.push_back(x.
M_);
4035 matdims.push_back(x.
N_);
4040 dims.push_back(x.
K_);
4045 dims.push_back(x.
K_);
4050 dims.push_back(x.
K_);
4055 dims.push_back(x.
K_);
4059 std::vector<expression> matdims;
4060 matdims.push_back(x.
M_);
4061 matdims.push_back(x.
N_);
4065 std::vector<expression> matdims;
4066 matdims.push_back(x.
K_);
4067 matdims.push_back(x.
K_);
4071 std::vector<expression> matdims;
4072 matdims.push_back(x.
K_);
4073 matdims.push_back(x.
K_);
4077 std::vector<expression> matdims;
4078 matdims.push_back(x.
K_);
4079 matdims.push_back(x.
K_);
4083 const std::vector<expression>& arraydims,
4084 const std::vector<expression>& matdims)
const {
4086 std::vector<expression>
dims(arraydims);
4087 for (
size_t i = 0; i < matdims.size(); ++i)
4088 dims.push_back(matdims[i]);
4090 if (dims.size() == 0) {
4091 o_ <<
INDENT2 <<
"vars__.push_back(" << name <<
");" <<
EOL;
4096 for (
size_t i = dims.size(); i > 0; ) {
4099 o_ <<
"for (int k_" << i <<
"__ = 0;"
4100 <<
" k_" << i <<
"__ < ";
4102 o_ <<
"; ++k_" << i <<
"__) {" <<
EOL;
4106 o_ <<
"vars__.push_back(" << name;
4107 if (arraydims.size() > 0) {
4109 for (
size_t i = 0; i < arraydims.size(); ++i) {
4110 if (i > 0)
o_ <<
"][";
4111 o_ <<
"k_" << i <<
"__";
4115 if (matdims.size() > 0) {
4116 o_ <<
"(k_" << arraydims.size() <<
"__";
4117 if (matdims.size() > 1)
4118 o_ <<
", k_" << (arraydims.size() + 1) <<
"__";
4123 for (
size_t i = dims.size(); i > 0; --i) {
4132 const std::string& model_name,
4134 o <<
INDENT <<
"template <typename RNG>" <<
EOL;
4135 o <<
INDENT <<
"void write_array(RNG& base_rng__," <<
EOL;
4136 o <<
INDENT <<
" std::vector<double>& params_r__," <<
EOL;
4137 o <<
INDENT <<
" std::vector<int>& params_i__," <<
EOL;
4138 o <<
INDENT <<
" std::vector<double>& vars__," <<
EOL;
4139 o <<
INDENT <<
" bool include_tparams__ = true," <<
EOL;
4140 o <<
INDENT <<
" bool include_gqs__ = true," <<
EOL;
4141 o <<
INDENT <<
" std::ostream* pstream__ = 0) const {" <<
EOL;
4143 o <<
INDENT2 <<
"stan::io::reader<double> in__(params_r__,params_i__);" <<
EOL;
4144 o <<
INDENT2 <<
"static const char* function__ = \""
4145 << model_name <<
"_namespace::write_array(%1%)\";" <<
EOL;
4162 o <<
INDENT2 <<
"if (!include_tparams__) return;"
4167 o <<
INDENT2 <<
"stan::math::accumulator<double> lp_accum__;" <<
EOL2;
4169 bool is_fun_return =
false;
4172 bool include_sampling =
false;
4174 is_var,is_fun_return);
4182 for (
size_t i = 0; i < prog.
derived_decl_.first.size(); ++i)
4183 boost::apply_visitor(vis_writer, prog.
derived_decl_.first[i].decl_);
4186 o <<
INDENT2 <<
"if (!include_gqs__) return;"
4190 is_var,is_fun_return);
4193 is_var,is_fun_return);
4202 boost::apply_visitor(vis_writer, prog.
generated_decl_.first[i].decl_);
4208 o <<
INDENT <<
"template <typename RNG>" <<
EOL;
4209 o <<
INDENT <<
"void write_array(RNG& base_rng," <<
EOL;
4210 o <<
INDENT <<
" Eigen::Matrix<double,Eigen::Dynamic,1>& params_r," <<
EOL;
4211 o <<
INDENT <<
" Eigen::Matrix<double,Eigen::Dynamic,1>& vars," <<
EOL;
4212 o <<
INDENT <<
" bool include_tparams = true," <<
EOL;
4213 o <<
INDENT <<
" bool include_gqs = true," <<
EOL;
4214 o <<
INDENT <<
" std::ostream* pstream = 0) const {" <<
EOL;
4215 o <<
INDENT <<
" std::vector<double> params_r_vec(params_r.size());" <<
EOL;
4216 o <<
INDENT <<
" for (int i = 0; i < params_r.size(); ++i)" <<
EOL;
4217 o <<
INDENT <<
" params_r_vec[i] = params_r(i);" <<
EOL;
4218 o <<
INDENT <<
" std::vector<double> vars_vec;" <<
EOL;
4219 o <<
INDENT <<
" std::vector<int> params_i_vec;" <<
EOL;
4220 o <<
INDENT <<
" write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);" <<
EOL;
4221 o <<
INDENT <<
" vars.resize(vars_vec.size());" <<
EOL;
4222 o <<
INDENT <<
" for (int i = 0; i < vars.size(); ++i)" <<
EOL;
4223 o <<
INDENT <<
" vars(i) = vars_vec[i];" <<
EOL;
4229 std::ostream& out) {
4230 out <<
INDENT <<
"static std::string model_name() {" <<
EOL
4231 <<
INDENT2 <<
"return \"" << model_name <<
"\";" <<
EOL
4236 std::ostream& out) {
4237 out <<
"typedef " << model_name <<
"_namespace::" << model_name
4238 <<
" stan_model;" <<
EOL2;
4242 const std::string& scalar_t_name,
4243 std::ostream& out) {
4244 for (
size_t d = 0; d < t.
num_dims_; ++d)
4245 out <<
"std::vector<";
4247 bool is_template_type =
false;
4251 is_template_type =
false;
4254 out << scalar_t_name;
4255 is_template_type =
false;
4258 out <<
"Eigen::Matrix<"
4260 <<
", Eigen::Dynamic,1>";
4261 is_template_type =
true;
4264 out <<
"Eigen::Matrix<"
4266 <<
", 1,Eigen::Dynamic>";
4267 is_template_type =
true;
4270 out <<
"Eigen::Matrix<"
4272 <<
", Eigen::Dynamic,Eigen::Dynamic>";
4273 is_template_type =
true;
4279 out <<
"UNKNOWN TYPE";
4282 for (
size_t d = 0; d < t.
num_dims_; ++d) {
4283 if (d > 0 || is_template_type)
4292 const std::string& scalar_t_name,
4293 std::ostream& out) {
4299 out <<
" " << decl.
name_;
4303 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i)
4317 std::stringstream ss;
4318 ss <<
"typename boost::math::tools::promote_args<";
4319 int num_open_brackets = 1;
4320 int num_generated_params = 0;
4321 for (
size_t i = 0; i < num_args; ++i) {
4324 if (num_generated_params > 0)
4326 if (num_generated_params == 4) {
4327 ss <<
"typename boost::math::tools::promote_args<";
4328 num_generated_params = 0;
4329 ++num_open_brackets;
4331 ss <<
"T" << i <<
"__";
4332 ++num_generated_params;
4336 if (num_generated_params > 0)
4341 for (
int i = 0; i < num_open_brackets; ++i)
4347 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i) {
4360 std::ostream& out) {
4362 out <<
"template <";
4363 bool continuing_tps =
false;
4365 out <<
"bool propto";
4366 continuing_tps =
true;
4368 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i) {
4373 out <<
"typename T" << i <<
"__";
4374 continuing_tps =
true;
4381 continuing_tps =
true;
4386 out <<
"typename T_lp__, typename T_lp_accum__";
4387 continuing_tps =
true;
4393 out <<
"template <class RNG>" <<
EOL;
4395 out <<
"template <typename T_lp__, typename T_lp_accum__>"
4397 }
else if (is_log) {
4398 out <<
"template <bool propto>"
4405 const std::string& scalar_t_name,
4406 std::ostream& out) {
4407 out <<
"inline" <<
EOL;
4413 std::ostream& out) {
4422 std::ostream& out) {
4425 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i) {
4426 std::string template_type_i
4427 =
"T" + boost::lexical_cast<std::string>(i) +
"__";
4431 for (
size_t i = 0; i <= fun.
name_.size(); ++i)
4435 if ((is_rng || is_lp) && fun.
arg_decls_.size() > 0)
4438 out <<
"RNG& base_rng__";
4440 out <<
"T_lp__& lp__, T_lp_accum__& lp_accum__";
4441 if (is_rng || is_lp || fun.
arg_decls_.size() > 0)
4443 out <<
"std::ostream* pstream__";
4451 std::ostream& out) {
4454 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i) {
4459 if ((is_rng || is_lp) && fun.
arg_decls_.size() > 0)
4462 out <<
"base_rng__";
4464 out <<
"lp__, lp_accum__";
4465 if (is_rng || is_lp || fun.
arg_decls_.size() > 0)
4474 const std::string& scalar_t_name,
4475 std::ostream& out) {
4483 <<
"typedef " << scalar_t_name <<
" fun_scalar_t__;"
4488 ?
"int" :
"fun_scalar_t__")
4489 <<
" fun_return_scalar_t__;"
4492 <<
"const static bool propto__ = true;"
4495 <<
"(void) propto__;"
4498 bool is_fun_return =
true;
4499 bool include_sampling =
true;
4501 include_sampling,is_var,is_fun_return);
4506 std::ostream& out) {
4508 out <<
INDENT <<
"return ";
4509 out << fun.
name_ <<
"<false>(";
4510 for (
size_t i = 0; i < fun.
arg_decls_.size(); ++i) {
4523 const std::string& scalar_t_name,
4524 std::ostream& out) {
4544 std::ostream& out) {
4549 std::string scalar_t_name
4565 std::ostream& out) {
4572 std::string scalar_t_name
4578 out <<
"_functor__ {"
4585 out <<
"operator()";
4607 std::ostream& out) {
4608 for (
size_t i = 0; i < funs.size(); ++i) {
4615 const std::string& model_name,
4616 std::ostream& out) {
void operator()(const positive_ordered_var_decl &x) const
generic visitor with output for extension
void operator()(const double_var_decl &x) const
void operator()(const simplex_var_decl &x) const
void operator()(cholesky_corr_var_decl const &x) const
Placeholder struct for boost::variant default ctors.
void operator()(unit_vector_var_decl const &x) const
void operator()(nil const &) const
void generate_void_statement(const std::string &name, const size_t indent, std::ostream &o)
void generate_function_functor(const function_decl_def &fun, std::ostream &out)
void operator()(corr_matrix_var_decl const &x) const
void operator()(const row_vector_var_decl &x) const
void generate_initialize_array_bounded(const D &x, const std::string &base_type, const std::string &read_fun_prefix, const std::vector< expression > &dim_args) const
void generate_begin_for_dims(const std::vector< expression > &dims) const
void generate_statements(const std::vector< statement > &ss, int indent, std::ostream &o, bool include_sampling, bool is_var, bool is_fun_return)
void operator()(vector_var_decl const &x) const
void generate_expression(const expression &e, std::ostream &o)
void operator()(simplex_var_decl const &x) const
void operator()(unit_vector_var_decl const &x) const
void operator()(vector_var_decl const &x) const
void operator()(const double_var_decl &x) const
bool is_no_op_statement() const
void operator()(const corr_matrix_var_decl &x) const
void generate_initialization(std::ostream &o, const std::string &var_name, const std::string &base_type, const std::vector< expression > &dims, const expression &type_arg1=expression(), const expression &type_arg2=expression())
void write_array(const std::string &name, const std::vector< expression > &arraydims, const std::vector< expression > &matdims) const
bool ends_with(const std::string &suffix, const std::string &s)
void generate_buffer_loop(const std::string &base_type, const std::string &name, const std::vector< expression > &dims, const expression &dim1=expression(), const expression &dim2=expression(), int indent=2U) const
void generate_dims_loop_fwd(const std::vector< expression > &dims, int indent=2U) const
void operator()(nil const &) const
std::pair< std::vector< var_decl >, std::vector< statement > > derived_data_decl_
void suppress_warning(const std::string &indent, const std::string &var_name, std::ostream &o)
std::vector< expression > conditions_
const std::vector< expression > EMPTY_EXP_VECTOR(0)
void operator()(const positive_ordered_var_decl &x) const
void operator()(const double_var_decl &x) const
void generate_type(const std::string &type, size_t num_dims) const
void operator()(cov_matrix_var_decl const &x) const
static void print_string_literal(std::ostream &o, const std::string &s)
std::vector< expression > dims_
base_expr_type base_type_
void generate_model_name_method(const std::string &model_name, std::ostream &out)
void operator()(double_var_decl const &x) const
void generate_param_names_array(const std::vector< expression > &matrix_dims, const std::string &name, const std::vector< expression > &dims) const
void operator()(row_vector_var_decl const &x) const
void operator()(const unit_vector_var_decl &x) const
void operator()(const cholesky_factor_var_decl &x) const
void generate_validate_transformed_params(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void operator()(row_vector_var_decl const &x) const
void generate_using(const std::string &type, std::ostream &o)
void operator()(const int_var_decl &x) const
statement_visgen(size_t indent, bool include_sampling, bool is_var, bool is_fun_return, std::ostream &o)
bool is_user_defined_prob_function(const std::string &name, const expression &variate, const std::vector< expression > ¶ms)
void operator()(const row_vector_var_decl &x) const
void operator()(cholesky_corr_var_decl const &x) const
void operator()(const nil &) const
void operator()(const unit_vector_var_decl &x) const
void operator()(nil const &) const
void operator()(const positive_ordered_var_decl &x) const
void generate_functions(const std::vector< function_decl_def > &funs, std::ostream &out)
void operator()(const row_vector_var_decl &x) const
const std::string INDENT3(" ")
void operator()(const cholesky_corr_var_decl &x) const
void operator()(expression const &x) const
void operator()(const cholesky_corr_var_decl &x) const
void generate_var_resizing(const std::vector< var_decl > &vs, std::ostream &o)
void generate_propto_default_function(const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &out)
void operator()(const vector_var_decl &x) const
void generate_set_param_ranges(const std::vector< var_decl > &var_decls, std::ostream &o)
var_size_validating_visgen var_size_validator_
void operator()(int_var_decl const &x) const
void operator()(simplex_var_decl const &x) const
void operator()(const positive_ordered_var_decl &x) const
void generate_init_args(const std::string &type, const std::vector< expression > &ctor_args, const std::vector< expression > &dims, size_t dim) const
void operator()(const unit_vector_var_decl &x) const
void generate_increment(expression K, std::vector< expression > dims) const
void operator()(simplex_var_decl const &x) const
void operator()(const unit_vector_var_decl &x) const
void generate_check_double(const std::string &name, size_t) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(cholesky_corr_var_decl const &x) const
void operator()(ordered_var_decl const &x) const
void generate_validate_context_size(std::ostream &o, const std::string &stage, const std::string &var_name, const std::string &base_type, const std::vector< expression > &dims, const expression &type_arg1=expression(), const expression &type_arg2=expression())
void operator()(row_vector_var_decl const &x) const
void operator()(const corr_matrix_var_decl &x) const
void generate_member_var_decls(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void generate_printable(const printable &p, std::ostream &o)
void operator()(positive_ordered_var_decl const &x) const
write_dims_visgen(std::ostream &o)
void operator()(const cholesky_factor_var_decl &x) const
const std::string INDENT(" ")
void operator()(const unit_vector_var_decl &x) const
void generate_local_var_init_nan(const std::vector< var_decl > &vs, int indent, std::ostream &o, bool is_var, bool is_fun_return)
std::pair< std::vector< var_decl >, std::vector< statement > > generated_decl_
void write_array(const std::string &name, const std::vector< expression > &dims) const
void operator()(const int_var_decl &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(corr_matrix_var_decl const &x) const
void operator()(ordered_var_decl const &x) const
void operator()(nil const &) const
void operator()(const corr_matrix_var_decl &x) const
std::vector< var_decl > data_decl_
void generate_dims_method(const program &prog, std::ostream &o)
generate_init_vars_visgen(int indent, std::ostream &o)
void operator()(const cov_matrix_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
void operator()(int_var_decl const &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(const matrix_var_decl &x) const
void operator()(const unit_vector_var_decl &x) const
void generate_include(const std::string &lib_name, std::ostream &o)
void operator()(const simplex_var_decl &x) const
void generate_arg_decl(bool gen_const, bool gen_ref, const arg_decl &decl, const std::string &scalar_t_name, std::ostream &out)
void operator()(corr_matrix_var_decl const &x) const
write_csv_visgen(std::ostream &o)
void generate_check_int(const std::string &name, size_t) const
void operator()(const simplex_var_decl &x) const
void operator()(ordered_var_decl const &x) const
void generate_constructor(const program &prog, const std::string &model_name, std::ostream &o)
void operator()(simplex_var_decl const &x) const
void operator()(const int_var_decl &x) const
void operator()(const double_var_decl &x) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(const nil &) const
void operator()(const int_var_decl &x) const
void operator()(const matrix_var_decl &x) const
void operator()(const row_vector_var_decl &x) const
void generate_increment(std::vector< expression > dims) const
void generate_name_dims(const std::string name, size_t num_dims) const
void operator()(const vector_var_decl &x) const
void operator()(const positive_ordered_var_decl &x) const
void generate_unconstrained_param_names_method(const program &prog, std::ostream &o)
void operator()(positive_ordered_var_decl const &x) const
void operator()(sample const &x) const
void generate_function_name(const function_decl_def &fun, std::ostream &out)
void operator()(const matrix_var_decl &x) const
void operator()(const row_vector_var_decl &x) const
void generate_initialize_array_bounded(const D &x, const std::string &base_type, const std::string &read_fun_prefix, const std::vector< expression > &dim_args) const
void operator()(const int_var_decl &x) const
void generate_constrained_param_names_method(const program &prog, std::ostream &o)
void generate_function(const function_decl_def &fun, std::ostream &out)
Generate the specified function and optionally its default for propto=false for functions ending in _...
void generate_function_template_parameters(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
void generate_local_var_inits(std::vector< var_decl > vs, bool is_var, bool declare_vars, std::ostream &o)
void operator()(const positive_ordered_var_decl &x) const
void generate_validate_var_decls(const std::vector< var_decl > decls, int indent, std::ostream &o)
void operator()(matrix_var_decl const &x) const
void operator()(const vector_var_decl &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(const reject_statement &ps) const
generate_local_var_init_nan_visgen(bool declare_vars, bool is_var, bool is_fun_return, int indent, std::ostream &o)
void operator()(const unit_vector_var_decl &x) const
void generate_destructor(const std::string &model_name, std::ostream &o)
void generate_indent(size_t indent, std::ostream &o)
void operator()(corr_matrix_var_decl const &x) const
void operator()(const positive_ordered_var_decl &x) const
void operator()(double_var_decl const &x) const
void generate_initialize_array(const std::string &var_type, const std::string &read_type, const std::vector< expression > &read_args, const std::string &name, const std::vector< expression > &dims) const
var_size_validating_visgen(std::ostream &o, const std::string &stage)
dump_member_var_visgen(std::ostream &o)
void operator()(const matrix_var_decl &x) const
void operator()(const positive_ordered_var_decl &x) const
void generate_validate_var_decl(const var_decl &decl, int indent, std::ostream &o)
void operator()(vector_var_decl const &x) const
std::string to_string(T i)
void generate_dims_array(const std::vector< expression > &matrix_dims_exprs, const std::vector< expression > &array_dims_exprs) const
void operator()(positive_ordered_var_decl const &x) const
void generate_param_names_array(const std::vector< expression > &matrix_dims, const std::string &name, const std::vector< expression > &dims) const
void operator()(const double_var_decl &x) const
void operator()(const simplex_var_decl &x) const
void generate_bare_type(const expr_type &t, const std::string &scalar_t_name, std::ostream &out)
var_resizing_visgen var_resizer_
init_local_var_visgen(bool declare_vars, bool is_var, std::ostream &o)
void generate_model_typedef(const std::string &model_name, std::ostream &out)
void operator()(unit_vector_var_decl const &x) const
void operator()(const cholesky_factor_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
void generate_functor_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
void operator()(const matrix_var_decl &x) const
void operator()(const int_var_decl &x) const
void operator()(const increment_log_prob_statement &x) const
void operator()(const cov_matrix_var_decl &x) const
void generate_indexed_expr(const std::string &expr, const std::vector< expression > indexes, base_expr_type base_type, size_t e_num_dims, std::ostream &o)
void generate_function_inline_return_type(const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &out)
void operator()(unit_vector_var_decl const &x) const
base_expr_type base_type_
void operator()(const cov_matrix_var_decl &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(simplex_var_decl const &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(positive_ordered_var_decl const &x) const
std::vector< var_decl > parameter_decl_
bool needs_template_params(const function_decl_def &fun)
void operator()(simplex_var_decl const &x) const
void generate_function_body(const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &out)
void operator()(positive_ordered_var_decl const &x) const
void operator()(matrix_var_decl const &x) const
write_array_vars_visgen(std::ostream &o)
void operator()(const std::string &s) const
void operator()(const vector_var_decl &x) const
void operator()(const double_var_decl &x) const
void operator()(const ordered_var_decl &x) const
void generate_initialize_array(const std::string &var_type, const std::string &read_type, const std::vector< expression > &read_args, const std::string &name, const std::vector< expression > &dims) const
void generate_propto_default_function_body(const function_decl_def &fun, std::ostream &out)
void operator()(const cov_matrix_var_decl &x) const
std::vector< statement > bodies_
void operator()(row_vector_var_decl const &x) const
void operator()(const corr_matrix_var_decl &x) const
unconstrained_param_names_visgen(std::ostream &o)
void operator()(double_var_decl const &x) const
void operator()(const vector_var_decl &x) const
void operator()(const ordered_var_decl &x) const
void generate_indent_num_dims(size_t base_indent, const std::vector< expression > &dims, const expression &dim1, const expression &dim2) const
void operator()(const double_var_decl &x) const
void generate_write_loop(const std::string &write_method_name, const std::string &var_name, const std::vector< expression > &dims) const
void operator()(int_var_decl const &x) const
write_array_visgen(std::ostream &o)
void operator()(const simplex_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
void operator()(cholesky_factor_var_decl const &x) const
bool has_only_int_args(const function_decl_def &fun)
void operator()(const cov_matrix_var_decl &x) const
void operator()(unit_vector_var_decl const &x) const
void generate_typedef(const std::string &type, const std::string &abbrev, std::ostream &o)
void operator()(const ordered_var_decl &x) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(row_vector_var_decl const &x) const
void operator()(const nil &) const
const std::string MINOR_VERSION
Minor version number for Stan package.
void operator()(double_var_decl const &x) const
void operator()(vector_var_decl const &x) const
std::pair< std::vector< var_decl >, std::vector< statement > > derived_decl_
void operator()(cov_matrix_var_decl const &x) const
void generate_end_namespace(std::ostream &o)
void generate_class_decl(const std::string &model_name, std::ostream &o)
void operator()(const cholesky_corr_var_decl &x) const
void dims(const T &x, std::vector< int > &result)
void operator()(const row_vector_var_decl &x) const
void generate_includes(std::ostream &o)
void operator()(unit_vector_var_decl const &x) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(const simplex_var_decl &x) const
void generate_cpp(const program &prog, const std::string &model_name, std::ostream &out)
void operator()(matrix_var_decl const &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(const simplex_var_decl &x) const
void operator()(unit_vector_var_decl const &x) const
std::vector< expression > dims_
void operator()(vector_var_decl const &x) const
void operator()(const vector_var_decl &x) const
void operator()(const ordered_var_decl &x) const
void operator()(const positive_ordered_var_decl &x) const
void generate_typedefs(std::ostream &o)
void operator()(const matrix_var_decl &x) const
void operator()(const unit_vector_var_decl &x) const
void generate_init(const T &x) const
void operator()(const int_var_decl &x) const
void generate_local_var_decls(const std::vector< var_decl > &vs, int indent, std::ostream &o, bool is_var, bool is_fun_return)
void operator()(const cholesky_factor_var_decl &x) const
void generate_function_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
std::string function_args(const std::string &fun_prefix, const D &x) const
void operator()(const row_vector_var_decl &x) const
void operator()(const simplex_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
void operator()(ordered_var_decl const &x) const
validate_var_decl_visgen(int indents, std::ostream &o)
void operator()(row_vector_var_decl const &x) const
void generate_version_comment(std::ostream &o)
void operator()(positive_ordered_var_decl const &x) const
void operator()(vector_var_decl const &x) const
void operator()(matrix_var_decl const &x) const
void operator()(corr_matrix_var_decl const &x) const
void operator()(const cholesky_factor_var_decl &x) const
void operator()(simplex_var_decl const &x) const
void operator()(const row_vector_var_decl &x) const
void operator()(positive_ordered_var_decl const &x) const
void generate_initialize_array(const std::string &var_type, const std::string &read_type, const std::vector< expression > &read_args, const std::string &name, const std::vector< expression > &dims) const
void operator()(ordered_var_decl const &x) const
void operator()(const int_var_decl &x) const
static void print_quoted_expression(std::ostream &o, const expression &e)
std::vector< arg_decl > arg_decls_
write_param_names_visgen(std::ostream &o)
void operator()(corr_matrix_var_decl const &x) const
void operator()(vector_var_decl const &x) const
void operator()(const while_statement &x) const
void operator()(const cholesky_corr_var_decl &x) const
void operator()(int_var_decl const &x) const
var_resizing_visgen(std::ostream &o)
void operator()(nil const &) const
void operator()(const corr_matrix_var_decl &x) const
void operator()(positive_ordered_var_decl const &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(vector_var_decl const &x) const
set_param_ranges_visgen(std::ostream &o)
void generate_statement(statement const &s, int indent, std::ostream &o, bool include_sampling, bool is_var, bool is_fun_return)
void operator()(matrix_var_decl const &x) const
write_csv_vars_visgen(std::ostream &o)
void generate_increment_i(std::vector< expression > dims) const
void operator()(const nil &) const
void operator()(const vector_var_decl &x) const
void operator()(cholesky_corr_var_decl const &x) const
void operator()(const positive_ordered_var_decl &x) const
void operator()(simplex_var_decl const &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(const cholesky_factor_var_decl &x) const
void generate_param_names_method(const program &prog, std::ostream &o)
void operator()(corr_matrix_var_decl const &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(const int_var_decl &x) const
void operator()(double_var_decl const &x) const
void operator()(int_var_decl const &x) const
void operator()(matrix_var_decl const &x) const
void operator()(ordered_var_decl const &x) const
void operator()(corr_matrix_var_decl const &x) const
void generate_type(const std::string &base_type, const std::vector< expression > &, size_t end, std::ostream &o)
void operator()(const matrix_var_decl &x) const
void operator()(const corr_matrix_var_decl &x) const
void generate_using_namespace(const std::string &ns, std::ostream &o)
void operator()(const nil &) const
var_size_validating_visgen var_size_validator_
void operator()(const int_var_decl &x) const
void generate_declaration(const std::string &name, const std::string &base_type, const std::vector< expression > &dims, const expression &type_arg1=expression(), const expression &type_arg2=expression()) const
void generate_log_prob(program const &p, std::ostream &o)
void generate_member_var_inits(const std::vector< var_decl > &vs, std::ostream &o)
const std::string EOL2("\n\n")
void operator()(row_vector_var_decl const &x) const
void operator()(nil const &) const
void operator()(int_var_decl const &x) const
void generate_start_namespace(std::string name, std::ostream &o)
void generate_initialize_array_bounded(const D &x, const std::string &base_type, const std::string &read_fun_prefix, const std::vector< expression > &dim_args) const
void operator()(const cholesky_factor_var_decl &x) const
void declare_array(std::string const &type, std::string const &name, size_t size) const
void basic_validate(T const &x) const
void operator()(const corr_matrix_var_decl &x) const
void operator()(const no_op_statement &) const
void operator()(const corr_matrix_var_decl &x) const
local_var_decl_visgen(int indents, bool is_var, bool is_fun_return, std::ostream &o)
void operator()(const cholesky_corr_var_decl &x) const
void operator()(const vector_var_decl &x) const
void generate_comment(std::string const &msg, int indent, std::ostream &o)
void operator()(const cholesky_factor_var_decl &x) const
void generate_end_for_dims(size_t dims_size) const
void operator()(const ordered_var_decl &x) const
bool is_nil(const expression &e)
void operator()(const nil &) const
void operator()(const unit_vector_var_decl &x) const
double e()
Return the base of the natural logarithm.
void operator()(const int_var_decl &x) const
void operator()(cholesky_factor_var_decl const &x) const
void operator()(cholesky_corr_var_decl const &x) const
void declare_array(const std::string &type, const std::vector< expression > &ctor_args, const std::string &name, const std::vector< expression > &dims) const
void operator()(const nil &) const
void operator()(const return_statement &rs) const
printable_visgen(std::ostream &o)
void operator()(row_vector_var_decl const &x) const
void operator()(int_var_decl const &x) const
void operator()(const simplex_var_decl &x) const
void generate_write_csv_method(const program &prog, const std::string &model_name, std::ostream &o)
std::vector< function_decl_def > function_decl_defs_
void operator()(cholesky_corr_var_decl const &x) const
std::vector< printable > printables_
int size(const std::vector< T > &x)
void operator()(const nil &) const
bool is_ill_formed() const
void generate_end_class_decl(std::ostream &o)
void operator()(int_var_decl const &x) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(const double_var_decl &x) const
void generate_initializer(std::ostream &o, const std::string &base_type, const std::vector< expression > &dims, const expression &type_arg1=expression(), const expression &type_arg2=expression())
void generate_void_statement(const std::string &name) const
void operator()(const simplex_var_decl &x) const
void generate_increment(expression M, expression N, std::vector< expression > dims) const
void generate_usings(std::ostream &o)
void operator()(const nil &) const
void operator()(assignment const &x) const
void operator()(ordered_var_decl const &x) const
void operator()(const cholesky_factor_var_decl &x) const
void operator()(matrix_var_decl const &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(const conditional_statement &x) const
void generate_loop_var(const std::string &name, size_t dims_size) const
void operator()(nil const &) const
void operator()(const row_vector_var_decl &x) const
void operator()(const ordered_var_decl &x) const
generate_init_visgen(std::ostream &o)
void operator()(const cholesky_corr_var_decl &x) const
std::string fun_scalar_type(const function_decl_def &fun, bool is_lp)
void operator()(const cholesky_corr_var_decl &x) const
void generate_public_decl(std::ostream &o)
void operator()(matrix_var_decl const &x) const
void operator()(nil const &) const
void operator()(const corr_matrix_var_decl &x) const
bool is_matrix(const std::string ¶meter_name)
void operator()(const unit_vector_var_decl &x) const
void operator()(const cholesky_factor_var_decl &x) const
void operator()(cov_matrix_var_decl const &x) const
void operator()(double_var_decl const &x) const
std::vector< expression > args_
void operator()(double_var_decl const &x) const
void operator()(const vector_var_decl &x) const
void operator()(const ordered_var_decl &x) const
const std::string MAJOR_VERSION
Major version number for Stan package.
void operator()(const row_vector_var_decl &x) const
void operator()(const cholesky_factor_var_decl &x) const
constrained_param_names_visgen(std::ostream &o)
void generate_init_vars(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void operator()(const matrix_var_decl &x) const
void operator()(const row_vector_var_decl &x) const
void operator()(const corr_matrix_var_decl &x) const
void operator()(const matrix_var_decl &x) const
void nonbasic_validate(const T &x, const std::string &type_name) const
void operator()(const double_var_decl &x) const
void operator()(const ordered_var_decl &x) const
void operator()(const cov_matrix_var_decl &x) const
void operator()(const simplex_var_decl &x) const
const std::string EOL("\n")
void generate_validate_positive(const std::string &var_name, const expression &expr, std::ostream &o)
void operator()(const double_var_decl &x) const
void operator()(const matrix_var_decl &x) const
void operator()(const positive_ordered_var_decl &x) const
void operator()(const unit_vector_var_decl &x) const
void operator()(const matrix_var_decl &x) const
member_var_decl_visgen(int indents, std::ostream &o)
void operator()(const ordered_var_decl &x) const
void operator()(const nil &) const
void operator()(const ordered_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
std::vector< var_decl > local_decl_
std::vector< printable > printables_
expr_type expression_type() const
void operator()(const expression &e) const
void operator()(const corr_matrix_var_decl &x) const
void operator()(const cholesky_corr_var_decl &x) const
void operator()(const vector_var_decl &x) const
void operator()(double_var_decl const &x) const
void operator()(const print_statement &ps) const
void operator()(ordered_var_decl const &x) const
const std::string INDENT2(" ")
void operator()(const for_statement &x) const
void operator()(unit_vector_var_decl const &x) const
void generate_init_method(const std::vector< var_decl > &vs, std::ostream &o)
std::vector< statement > statements_
void operator()(const statements &x) const
const bool is_fun_return_
void operator()(const double_var_decl &x) const
void generate_private_decl(std::ostream &o)
void generate_write_csv_header_method(const program &prog, std::ostream &o)
void operator()(const ordered_var_decl &x) const
void generate_write_array_method(const program &prog, const std::string &model_name, std::ostream &o)
void operator()(cholesky_factor_var_decl const &x) const
void operator()(nil const &) const
void generate_param_names(const std::string &name) const
void operator()(const vector_var_decl &x) const
void operator()(const nil &) const