1 #ifndef STAN_LANG_GRAMMARS_SEMANTIC_ACTIONS_DEF_CPP 2 #define STAN_LANG_GRAMMARS_SEMANTIC_ACTIONS_DEF_CPP 7 #include <boost/format.hpp> 8 #include <boost/spirit/include/qi.hpp> 9 #include <boost/variant/apply_visitor.hpp> 10 #include <boost/variant/recursive_variant.hpp> 46 if (f.
args_.size() > 0)
return;
49 || f.
name_ ==
"not_a_number" || f.
name_ ==
"positive_infinity" 50 || f.
name_ ==
"negative_infinity" || f.
name_ ==
"machine_precision")
64 if (f.
args_.size() == 1
71 else if (f.
args_.size() == 2
73 || f.
name_ ==
"hypot"))
75 else if (f.
args_.size() == 3 && f.
name_ ==
"fma")
85 const std::string& new_suffix,
fun& f) {
92 bool deprecate_fun(
const std::string& old_name,
const std::string& new_name,
93 fun& f, std::ostream& msgs) {
94 if (f.
name_ != old_name)
return false;
97 msgs <<
"Warning: Function name '" << old_name <<
"' is deprecated" 98 <<
" and will be removed in a later release; please replace" 99 <<
" with '" << new_name <<
"'" << std::endl;
104 const std::string& replacement,
fun& f,
105 std::ostream& msgs) {
107 msgs <<
"Warning: Deprecated function '" << f.
name_ <<
"';" 108 <<
" please replace suffix '" << deprecated_suffix
109 <<
"' with " << replacement << std::endl;
115 std::stringstream& error_msgs)
119 error_msgs <<
"expression denoting real required; found type=" 129 std::vector<expr_type> arg_types;
130 for (
size_t i = 0; i < fun.
args_.size(); ++i)
131 arg_types.push_back(fun.
args_[i].expression_type());
136 int num_dimss(std::vector<std::vector<stan::lang::expression> >& dimss) {
138 for (
size_t i = 0; i < dimss.size(); ++i)
139 sum += dimss[i].size();
143 template <
typename L,
typename R>
164 const std::vector<var_decl>&)
const;
166 const std::vector<idx>&)
const;
168 std::vector<std::vector<expression> >&,
169 const std::vector<std::vector<expression> >&)
const;
174 std::ostream& error_msgs)
const {
177 error_msgs <<
"expression is ill formed" << std::endl;
188 std::ostream& error_msgs)
const {
194 std::vector<expression> args;
195 args.push_back(expr1);
196 args.push_back(expr2);
205 std::ostream& error_msgs)
const {
211 std::vector<expression> args;
212 args.push_back(expr1);
213 args.push_back(expr2);
214 fun f(
"subtract", args);
230 std::ostream& error_msgs)
const {
233 error_msgs <<
"condition in ternary expression must be" 234 <<
" primitive int or real;" 235 <<
" found type=" << cond_type
245 bool types_compatible
246 = (true_val_type == false_val_type)
248 && (true_val_base_type == false_val_base_type
250 && false_val_base_type ==
INT_T)
251 || (true_val_base_type ==
INT_T 252 && false_val_base_type ==
DOUBLE_T)));
254 if (!types_compatible) {
255 error_msgs <<
"base type mismatch in ternary expression," 256 <<
" expression when true is: ";
258 error_msgs <<
"; expression when false is: ";
260 error_msgs << std::endl;
267 = (true_val_base_type == false_val_base_type)
271 conditional_op.
type_ = true_val_type;
277 boost::phoenix::function<validate_conditional_op>
281 const std::string& op,
282 const std::string& fun_name,
283 std::ostream& error_msgs)
const {
286 error_msgs <<
"binary infix operator " << op
287 <<
" with functional interpretation " << fun_name
288 <<
" requires arguments or primitive type (int or real)" 294 std::vector<expression> args;
295 args.push_back(expr1);
296 args.push_back(expr2);
297 fun f(fun_name, args);
305 std::ostream& error_msgs)
const {
308 error_msgs <<
"Functions cannot contain void argument types; " 309 <<
"found void argument." 312 boost::phoenix::function<validate_non_void_arg_function>
317 std::ostream& error_msgs)
const {
319 error_msgs <<
"Void return type may not have dimensions declared." 332 bool& allow_sampling,
334 bool is_void_function_origin
337 allow_sampling =
true;
338 origin = is_void_function_origin
341 }
else if (
ends_with(
"_rng", identifier)) {
342 allow_sampling =
false;
343 origin = is_void_function_origin
347 allow_sampling =
false;
348 origin = is_void_function_origin
353 boost::phoenix::function<set_allows_sampling_origin>
357 std::set<std::pair<std::string,
359 std::set<std::pair<std::string,
361 std::ostream& error_msgs,
362 bool allow_undefined)
const {
366 typedef set<pair<string, function_signature_t> >::iterator iterator_t;
367 if (!allow_undefined) {
368 for (iterator_t it = declared.begin(); it != declared.end(); ++it) {
369 if (defined.find(*it) == defined.end()) {
370 error_msgs <<
"Function declared, but not defined." 371 <<
" Function name=" << (*it).first
385 const std::pair<std::string,
387 bool name_only =
true) {
388 for (std::set<std::pair<std::string,
391 it != existing.end();
393 if (name_sig.first == (*it).first
395 || name_sig.second.second == (*it).second.second))
401 std::ostream& error_msgs)
const {
408 error_msgs <<
"Parse Error. Probability function already defined" 409 <<
" for " << dist_name << std::endl;
418 error_msgs <<
" Parse Error. CDF already defined for " 419 << dist_name << std::endl;
428 error_msgs <<
" Parse Error. CCDF already defined for " 429 << dist_name << std::endl;
439 std::set<std::pair<std::string, function_signature_t> >&
441 std::set<std::pair<std::string, function_signature_t> >&
443 std::ostream& error_msgs)
const {
447 std::vector<expr_type> arg_types;
448 for (
size_t i = 0; i < decl.
arg_decls_.size(); ++i)
453 std::pair<std::string, function_signature_t> name_sig(decl.
name_, sig);
456 &&
fun_exists(functions_declared, name_sig)) {
457 error_msgs <<
"Parse Error. Function already declared, name=" 464 if (
fun_exists(functions_defined, name_sig)) {
465 error_msgs <<
"Parse Error. Function already defined, name=" 474 error_msgs <<
"Parse Error. Function system defined, name=" 482 error_msgs <<
"Parse Error. Probability density functions require" 483 <<
" real variates (first argument)." 484 <<
" Found type = " << arg_types[0] << std::endl;
489 error_msgs <<
"Parse Error. Probability mass functions require" 490 <<
" integer variates (first argument)." 491 <<
" Found type = " << arg_types[0] << std::endl;
497 if (functions_declared.find(name_sig) == functions_declared.end()) {
498 functions_declared.insert(name_sig);
500 .
add(decl.
name_, result_type, arg_types);
506 functions_defined.insert(name_sig);
514 std::ostream& error_msgs)
519 error_msgs <<
"Parse Error. Probability functions require" 520 <<
" at least one argument." << std::endl;
526 error_msgs <<
"Parse Error. Probability density functions require" 527 <<
" real variates (first argument)." 528 <<
" Found type = " << variate_type << std::endl;
533 error_msgs <<
"Parse Error. Probability mass functions require" 534 <<
" integer variates (first argument)." 535 <<
" Found type = " << variate_type << std::endl;
540 boost::phoenix::function<validate_pmf_pdf_variate>
545 std::ostream& error_msgs)
const {
550 error_msgs <<
"Improper return in body of function." << std::endl;
561 error_msgs <<
"Require real return type for probability functions" 562 <<
" ending in _log, _lpdf, _lpmf, _lcdf, or _lccdf." 578 for (
size_t i = 0; i < decl.
arg_decls_.size(); ++i)
584 std::ostream& error_msgs)
const {
588 error_msgs <<
"duplicate declaration of variable, name=" 590 <<
"; attempt to redeclare as function argument" 591 <<
"; original declaration as ";
593 error_msgs << std::endl;
612 boost::phoenix::function<validate_int_expr_silent>
617 std::ostream& error_msgs)
620 error_msgs <<
"ERROR: Indexes must be expressions of integer type." 623 error_msgs <<
'.' << std::endl;
627 boost::phoenix::function<validate_int_expression_warn>
632 std::ostream& error_msgs)
const {
634 error_msgs <<
"ERROR: Container index must be integer; found type=";
636 error_msgs << std::endl;
643 error_msgs <<
"index must be integer or 1D integer array;" 644 <<
" found number of dimensions=" 657 boost::phoenix::function<validate_ints_expression>
679 std::stringstream& error_msgs)
const {
680 using boost::spirit::get_line;
684 size_t idx_errline = get_line(_where);
686 error_msgs << std::endl;
688 if (idx_errline > 0) {
689 error_msgs <<
"ERROR at line " << idx_errline
690 << std::endl << std::endl;
692 std::basic_stringstream<char> sprogram;
693 sprogram << boost::make_iterator_range(_begin, _end);
696 size_t idx_errcol = 0;
697 idx_errcol = get_column(_begin, _where) - 1;
699 std::string lineno =
"";
700 format fmt_lineno(
"% 3d: ");
702 std::string line_2before =
"";
703 std::string line_before =
"";
704 std::string line_err =
"";
705 std::string line_after =
"";
708 size_t idx_before = idx_errline - 1;
709 if (idx_before > 0) {
711 while (idx_before > idx_line) {
712 line_2before = line_before;
713 std::getline(sprogram, line_before);
716 if (line_2before.length() > 0) {
717 lineno = str(fmt_lineno % (idx_before - 1) );
718 error_msgs << lineno << line_2before << std::endl;
720 lineno = str(fmt_lineno % idx_before);
721 error_msgs << lineno << line_before << std::endl;
724 std::getline(sprogram, line_err);
725 lineno = str(fmt_lineno % idx_errline);
726 error_msgs << lineno << line_err << std::endl
727 << setw(idx_errcol + lineno.length()) <<
"^" << std::endl;
729 if (!sprogram.eof()) {
730 std::getline(sprogram, line_after);
731 lineno = str(fmt_lineno % (idx_errline+1));
732 error_msgs << lineno << line_after << std::endl;
735 error_msgs << std::endl;
742 std::stringstream& error_msgs)
745 error_msgs <<
"conditions in if-else statement must be" 746 <<
" primitive int or real;" 756 boost::phoenix::function<add_conditional_condition>
767 error_msgs <<
"Warning (non-fatal): assignment operator <- deprecated" 768 <<
" in the Stan language;" 772 boost::phoenix::function<deprecate_old_assignment_op>
776 std::ostream& error_msgs)
const {
780 error_msgs <<
"Returns only allowed from function bodies." 791 std::ostream& error_msgs)
796 error_msgs <<
"Void returns only allowed from function" 797 <<
" bodies of void return type." 804 boost::phoenix::function<validate_void_return_allowed>
811 std::ostream& error_msgs)
const {
820 && lhs_origin != origin_allowed) {
841 std::ostream& error_msgs)
const {
847 error_msgs <<
"Left-hand side indexing incompatible with variable." 857 bool types_compatible
858 = lhs_base_type == rhs_base_type
860 if (!types_compatible) {
861 error_msgs <<
"base type mismatch in assignment" 862 <<
"; variable name=" 866 error_msgs <<
"; right-hand side type=";
868 error_msgs << std::endl;
874 error_msgs <<
"dimension mismatch in assignment" 875 <<
"; variable name=" 877 <<
", num dimensions given=" 879 <<
"; right-hand side dimensions=" 888 error_msgs <<
"WARNING: left-hand side variable" 889 <<
" (name=" << name <<
")" 890 <<
" occurs on right-hand side of assignment, causing" 891 <<
" inefficient deep copy to avoid aliasing." 902 std::ostream& error_msgs)
const {
906 error_msgs <<
"unknown variable in assignment" 917 && lhs_origin != origin_allowed) {
918 error_msgs <<
"attempt to assign variable in wrong block." 919 <<
" left-hand-side variable origin=";
921 error_msgs << std::endl;
933 error_msgs <<
"Illegal to assign to function argument variables." 935 <<
"Use local variables instead." 951 error_msgs <<
"too many indexes for variable " 952 <<
"; variable name = " << name
953 <<
"; num dimensions given = " << num_index_dims
954 <<
"; variable array dimensions = " << lhs_var_num_dims
963 bool types_compatible
964 = lhs_base_type == rhs_base_type
966 if (!types_compatible) {
967 error_msgs <<
"base type mismatch in assignment" 968 <<
"; variable name = " 972 error_msgs <<
"; right-hand side type=";
974 error_msgs << std::endl;
980 error_msgs <<
"dimension mismatch in assignment" 981 <<
"; variable name = " 983 <<
", num dimensions given = " 985 <<
"; right-hand side dimensions = " 997 const std::vector<expr_type>& arg_types) {
1004 const std::vector<expr_type>& arg_types,
1005 std::ostream& error_msgs) {
1019 std::ostream& error_msgs)
const {
1020 static const bool user_facing =
true;
1021 std::vector<expr_type> arg_types;
1023 for (
size_t i = 0; i < s.
dist_.
args_.size(); ++i)
1024 arg_types.push_back(s.
dist_.
args_[i].expression_type());
1026 std::string internal_function_name =
get_prob_fun(function_name);
1030 if (internal_function_name.size() == 0) {
1032 error_msgs <<
"Error: couldn't find distribution named " 1033 << function_name << std::endl;
1037 if ((internal_function_name.find(
"multiply_log") != std::string::npos)
1038 || (internal_function_name.find(
"binomial_coefficient_log")
1039 != std::string::npos)) {
1040 error_msgs <<
"Only distribution names can be used with" 1041 <<
" sampling (~) notation; found non-distribution" 1042 <<
" function: " << function_name
1048 if (internal_function_name.find(
"cdf_log") != std::string::npos) {
1049 error_msgs <<
"CDF and CCDF functions may not be used with" 1050 <<
" sampling notation." 1051 <<
" Use increment_log_prob(" 1052 << internal_function_name <<
"(...)) instead." 1058 if (internal_function_name ==
"lkj_cov_log") {
1059 error_msgs <<
"Warning: the lkj_cov_log() sampling distribution" 1060 <<
" is deprecated. It will be removed in Stan 3." 1062 <<
"Code LKJ covariance in terms of an lkj_corr()" 1063 <<
" distribution on a correlation matrix" 1064 <<
" and independent lognormals on the scales." 1065 << std::endl << std::endl;
1069 error_msgs <<
"require real scalar return type for" 1070 <<
" probability function." << std::endl;
1076 error_msgs <<
"Warning (non-fatal):" 1078 <<
"Left-hand side of sampling statement (~) may contain a" 1079 <<
" non-linear transform of a parameter or local variable." 1081 <<
"If it does, you need to include a target += statement" 1082 <<
" with the log absolute determinant of the Jacobian of" 1083 <<
" the transform." 1085 <<
"Left-hand-side of sampling statement:" 1089 error_msgs <<
" ~ " << function_name <<
"(...)" 1095 error_msgs <<
"Outcomes in truncated distributions" 1096 <<
" must be univariate." 1098 <<
" Found outcome expression: ";
1100 error_msgs << std::endl
1101 <<
" with non-univariate type: " 1107 for (
size_t i = 0; i < s.
dist_.
args_.size(); ++i)
1109 error_msgs <<
"Parameters in truncated distributions" 1110 <<
" must be univariate." 1112 <<
" Found parameter expression: ";
1114 error_msgs << std::endl
1115 <<
" with non-univariate type: " 1124 error_msgs <<
"Lower bounds in truncated distributions" 1125 <<
" must be univariate." 1127 <<
" Found lower bound expression: ";
1129 error_msgs << std::endl
1130 <<
" with non-univariate type: " 1138 error_msgs <<
"Upper bounds in truncated distributions" 1139 <<
" must be univariate." 1141 <<
" Found upper bound expression: ";
1143 error_msgs << std::endl
1144 <<
" with non-univariate type: " 1154 std::vector<expr_type> arg_types_trunc(arg_types);
1160 error_msgs <<
"lower truncation not defined for specified" 1167 error_msgs <<
"lower bound in truncation type does not match" 1168 <<
" sampled variate in distribution's type" 1176 std::vector<expr_type> arg_types_trunc(arg_types);
1182 error_msgs <<
"upper truncation not defined for" 1183 <<
" specified arguments to " 1190 error_msgs <<
"upper bound in truncation type does not match" 1191 <<
" sampled variate in distribution's type" 1199 std::vector<expr_type> arg_types_trunc(arg_types);
1205 error_msgs <<
"lower truncation not defined for specified" 1212 error_msgs <<
"lower bound in truncation type does not match" 1213 <<
" sampled variate in distribution's type" 1226 std::stringstream& error_msgs)
const {
1227 static const bool user_facing =
true;
1229 error_msgs <<
"Illegal statement beginning with non-void" 1230 <<
" expression parsed as" 1231 << std::endl <<
" ";
1233 error_msgs << std::endl
1234 <<
"Not a legal assignment, sampling, or function" 1235 <<
" statement. Note that" 1237 <<
" * Assignment statements only allow variables" 1238 <<
" (with optional indexes) on the left;" 1240 <<
" if you see an outer function logical_lt (<)" 1241 <<
" with negated (-) second argument," 1243 <<
" it indicates an assignment statement A <- B" 1244 <<
" with illegal left" 1246 <<
" side A parsed as expression (A < (-B))." 1248 <<
" * Sampling statements allow arbitrary" 1249 <<
" value-denoting expressions on the left." 1251 <<
" * Functions used as statements must be" 1252 <<
" declared to have void returns" 1253 << std::endl << std::endl;
1263 for (
size_t i = 0; i < var_decls.size(); ++i)
1264 vm.
remove(var_decls[i].name());
1270 std::stringstream& error_msgs)
const {
1273 error_msgs <<
"conditions in while statement must be primitive" 1289 std::string& name_local,
1291 std::stringstream& error_msgs)
const {
1295 error_msgs <<
"ERROR: loop variable already declared." 1296 <<
" variable name=\"" << name <<
"\"" << std::endl;
1311 std::stringstream& error_msgs)
1314 error_msgs <<
"expression denoting integer required; found type=" 1324 std::stringstream& error_msgs)
const {
1325 error_msgs <<
"Warning (non-fatal): increment_log_prob(...);" 1326 <<
" is deprecated and will be removed in the future." 1328 <<
" Use target += ...; instead." 1331 boost::phoenix::function<deprecate_increment_log_prob>
1336 std::stringstream& error_msgs)
1338 pass = allow_sample;
1340 error_msgs <<
"Sampling statements (~) and increment_log_prob() are" 1342 <<
"only allowed in the model block." 1349 std::ostream& error_msgs)
1353 error_msgs <<
"attempt to increment log prob with void expression" 1356 boost::phoenix::function<validate_non_void_expression>
1381 error_msgs <<
"Warning: the integrate_ode() function is deprecated" 1382 <<
" in the Stan language; use integrate_ode_rk45() [non-stiff]" 1383 <<
" or integrate_ode_bdf() [stiff] instead." 1386 boost::phoenix::function<deprecated_integrate_ode>
1393 std::ostream& error_msgs) {
1397 std::vector<expr_type> sys_arg_types;
1405 .
is_defined(ode_fun.system_function_name_, system_signature)) {
1406 error_msgs <<
"first argument to " 1407 << ode_fun.integration_function_name_
1408 <<
" must be the name of a function with signature" 1409 <<
" (real, real[], real[], real[], int[]) : real[] ";
1415 error_msgs <<
"second argument to " 1416 << ode_fun.integration_function_name_
1417 <<
" must have type real[] for intial system state;" 1419 << ode_fun.y0_.expression_type()
1423 if (!ode_fun.t0_.expression_type().is_primitive()) {
1424 error_msgs <<
"third argument to " 1425 << ode_fun.integration_function_name_
1426 <<
" must have type real or int for initial time;" 1428 << ode_fun.t0_.expression_type()
1433 error_msgs <<
"fourth argument to " 1434 << ode_fun.integration_function_name_
1435 <<
" must have type real[]" 1436 <<
" for requested solution times; found type=" 1437 << ode_fun.ts_.expression_type()
1442 error_msgs <<
"fifth argument to " 1443 << ode_fun.integration_function_name_
1444 <<
" must have type real[] for parameters; found type=" 1445 << ode_fun.theta_.expression_type()
1450 error_msgs <<
"sixth argument to " 1451 << ode_fun.integration_function_name_
1452 <<
" must have type real[] for real data; found type=" 1453 << ode_fun.x_.expression_type()
1458 error_msgs <<
"seventh argument to " 1459 << ode_fun.integration_function_name_
1460 <<
" must have type int[] for integer data; found type=" 1461 << ode_fun.x_int_.expression_type()
1467 if (
has_var(ode_fun.t0_, var_map)) {
1468 error_msgs <<
"third argument to " 1469 << ode_fun.integration_function_name_
1470 <<
" (initial times)" 1471 <<
" must be data only and not reference parameters";
1474 if (
has_var(ode_fun.ts_, var_map)) {
1475 error_msgs <<
"fourth argument to " 1476 << ode_fun.integration_function_name_
1477 <<
" (solution times)" 1478 <<
" must be data only and not reference parameters";
1481 if (
has_var(ode_fun.x_, var_map)) {
1482 error_msgs <<
"sixth argument to " 1483 << ode_fun.integration_function_name_
1485 <<
" must be data only and not reference parameters";
1493 std::ostream& error_msgs)
const {
1502 std::ostream& error_msgs)
const {
1506 error_msgs <<
"eighth argument to " 1508 <<
" (relative tolerance) must have type real or int;" 1515 error_msgs <<
"ninth argument to " 1517 <<
" (absolute tolerance) must have type real or int;" 1524 error_msgs <<
"tenth argument to " 1526 <<
" (max steps) must have type real or int;" 1535 error_msgs <<
"eight argument to " 1537 <<
" (relative tolerance) must be data only" 1538 <<
" and not depend on parameters";
1542 error_msgs <<
"ninth argument to " 1544 <<
" (absolute tolerance ) must be data only" 1545 <<
" and not depend parameters";
1549 error_msgs <<
"tenth argument to " 1551 <<
" (max steps) must be data only" 1552 <<
" and not depend on parameters";
1556 boost::phoenix::function<validate_integrate_ode_control>
1562 std::ostream& error_msgs)
const {
1563 if (fun.
name_ ==
"get_lp")
1564 error_msgs <<
"Warning (non-fatal): get_lp() function deprecated." 1566 <<
" It will be removed in a future release." 1568 <<
" Use target() instead." 1570 if (fun.
name_ ==
"target")
1571 fun.
name_ =
"get_lp";
1573 std::vector<expr_type> arg_types;
1574 for (
size_t i = 0; i < fun.
args_.size(); ++i)
1575 arg_types.push_back(fun.
args_[i].expression_type());
1585 deprecate_fun(
"binomial_coefficient_log",
"lchoose", fun, error_msgs)
1586 ||
deprecate_fun(
"multiply_log",
"lmultiply", fun, error_msgs)
1590 "'_lpdf' for density functions or '_lpmf' for mass functions",
1612 error_msgs <<
"ERROR: random number generators only allowed in" 1613 <<
" transformed data block, generated quantities block" 1614 <<
" or user-defined functions with names ending in _rng" 1615 <<
"; found function=" << fun.
name_ <<
" in block=";
1617 error_msgs << std::endl;
1630 error_msgs <<
"Function target() or functions suffixed with _lp only" 1631 <<
" allowed in transformed parameter block, model block" 1633 <<
"or the body of a function with suffix _lp." 1635 <<
"Found function = " 1636 << (fun.
name_ ==
"get_lp" ?
"target or get_lp" : fun.
name_)
1639 error_msgs << std::endl;
1645 if (fun.
name_ ==
"max" || fun.
name_ ==
"min") {
1646 if (fun.
args_.size() == 2) {
1647 if (fun.
args_[0].expression_type().is_primitive_int()
1648 && fun.
args_[1].expression_type().is_primitive_int()) {
1654 if (fun.
name_ ==
"abs" 1655 && fun.
args_.size() > 0
1656 && fun.
args_[0].expression_type().is_primitive_double()) {
1657 error_msgs <<
"Warning: Function abs(real) is deprecated" 1658 <<
" in the Stan language." 1660 <<
" It will be removed in a future release." 1662 <<
" Use fabs(real) instead." 1663 << std::endl << std::endl;
1666 if (fun.
name_ ==
"lkj_cov_log") {
1667 error_msgs <<
"Warning: the lkj_cov_log() function" 1668 <<
" is deprecated. It will be removed in Stan 3." 1670 <<
"Code LKJ covariance in terms of an lkj_corr()" 1671 <<
" distribution on a correlation matrix" 1672 <<
" and independent lognormals on the scales." 1673 << std::endl << std::endl;
1676 if (fun.
name_ ==
"if_else") {
1677 error_msgs <<
"Warning (non-fatal): the if_else() function" 1678 <<
" is deprecated. " 1679 <<
"Use the conditional operator '?:' instead." 1693 std::ostream& error_msgs)
const {
1694 if (array_expr.
args_.size() == 0) {
1696 error_msgs <<
"array expression size 0, but must be > 0";
1702 et = array_expr.
args_[0].expression_type();
1703 for (
size_t i = 1; i < array_expr.
args_.size(); ++i) {
1705 et_next = array_expr.
args_[i].expression_type();
1707 error_msgs <<
"expressions for elements of array must have" 1708 <<
" same array sizes; found" 1709 <<
" previous type=" << et
1710 <<
"; type at position " << i <<
"=" << et_next;
1719 error_msgs <<
"expressions for elements of array must have" 1720 <<
" the same or promotable types; found" 1721 <<
" previous type=" << et
1722 <<
"; type at position " << i <<
"=" << et_next;
1729 array_expr.
type_ = et;
1741 std::ostream& error_msgs)
const {
1744 error_msgs <<
"arguments to ^ must be primitive (real or int)" 1745 <<
"; cannot exponentiate " 1751 error_msgs << std::endl;
1755 std::vector<expression> args;
1756 args.push_back(expr1);
1757 args.push_back(expr2);
1766 std::ostream& error_msgs)
const {
1772 std::vector<expression> args;
1773 args.push_back(expr1);
1774 args.push_back(expr2);
1775 fun f(
"multiply", args);
1783 std::ostream& error_msgs)
const {
1784 static const bool user_facing =
true;
1792 std::vector<expression> args;
1793 args.push_back(expr1);
1794 args.push_back(expr2);
1798 error_msgs <<
"Warning: integer division" 1799 <<
" implicitly rounds to integer." 1800 <<
" Found int division: ";
1802 error_msgs <<
" / ";
1804 error_msgs << std::endl
1805 <<
" Positive values rounded down," 1806 <<
" negative values rounded up or down" 1807 <<
" in platform-dependent way." 1810 fun f(
"divide", args);
1818 fun f(
"mdivide_right", args);
1823 fun f(
"divide", args);
1831 bool& pass, std::ostream& error_msgs)
const {
1834 error_msgs <<
"both operands of % must be int" 1835 <<
"; cannot modulo " 1839 error_msgs << std::endl;
1843 std::vector<expression> args;
1844 args.push_back(expr1);
1845 args.push_back(expr2);
1846 fun f(
"modulus", args);
1854 std::ostream& error_msgs)
const {
1855 std::vector<expression> args;
1856 args.push_back(expr1);
1857 args.push_back(expr2);
1861 fun f(
"mdivide_left", args);
1867 fun f(
"mdivide_left", args);
1876 std::ostream& error_msgs)
const {
1882 std::vector<expression> args;
1883 args.push_back(expr1);
1884 args.push_back(expr2);
1885 fun f(
"elt_multiply", args);
1893 std::ostream& error_msgs)
const {
1899 std::vector<expression> args;
1900 args.push_back(expr1);
1901 args.push_back(expr2);
1902 fun f(
"elt_divide", args);
1910 std::ostream& error_msgs)
const {
1915 std::vector<expression> args;
1916 args.push_back(expr);
1917 fun f(
"minus", args);
1925 std::ostream& error_msgs)
const {
1927 error_msgs <<
"logical negation operator !" 1928 <<
" only applies to int or real types; ";
1931 std::vector<expression> args;
1932 args.push_back(expr);
1933 fun f(
"logical_negation", args);
1940 std::ostream& error_msgs)
const {
1943 std::vector<expression> args;
1944 args.push_back(expr);
1945 fun f(
"transpose", args);
1953 bool& pass, std::ostream& error_msgs)
const {
1957 error_msgs <<
"Indexed expression must have at least as many" 1958 <<
" dimensions as number of indexes supplied:" 1960 <<
" indexed expression dims=" 1962 <<
"; num indexes=" << idxs.size()
1968 std::vector<std::vector<stan::lang::expression> >& dimss,
1969 bool& pass, std::ostream& error_msgs)
const {
1973 if (expr_dims < index_dims) {
1974 error_msgs <<
"Indexed expression must have at least as many" 1975 <<
" dimensions as number of indexes supplied: " 1977 <<
" indexed expression dimensionality = " << expr_dims
1978 <<
"; indexes supplied = " << dimss.size()
1985 error_msgs <<
"Indexed expression must have at least as many" 1986 <<
" dimensions as number of indexes supplied." 1998 std::ostream& error_msgs,
bool& pass)
const {
1999 std::string name = var_expr.
name_;
2000 if (name == std::string(
"lp__")) {
2001 error_msgs << std::endl
2002 <<
"ERROR (fatal): Use of lp__ is no longer supported." 2004 <<
" Use target += ... statement to increment log density." 2006 <<
" Use target() function to get log density." 2010 }
else if (name == std::string(
"params_r__")) {
2011 error_msgs << std::endl <<
"WARNING:" << std::endl
2012 <<
" Direct access to params_r__ yields an inconsistent" 2013 <<
" statistical model in isolation and no guarantee is" 2014 <<
" made that this model will yield valid inferences." 2016 <<
" Moreover, access to params_r__ is unsupported" 2017 <<
" and the variable may be removed without notice." 2024 error_msgs <<
"variable \"" << name <<
'"' <<
" does not exist." 2034 error_msgs <<
"Probabilty functions with suffixes _lpdf, _lpmf," 2035 <<
" _lcdf, and _lccdf," << std::endl
2036 <<
"require a vertical bar (|) between the first two" 2037 <<
" arguments." << std::endl;
2044 std::stringstream& error_msgs)
2045 : error_msgs_(error_msgs) { }
2054 <<
" found range constraint." << std::endl;
2063 <<
" found range constraint." << std::endl;
2072 <<
" found range constraint." << std::endl;
2081 <<
" found range constraint." << std::endl;
2090 <<
" found range constraint." << std::endl;
2097 error_msgs_ <<
"require unconstrained variable declaration." 2098 <<
" found unit_vector." << std::endl;
2103 error_msgs_ <<
"require unconstrained variable declaration." 2104 <<
" found simplex." << std::endl;
2109 error_msgs_ <<
"require unconstrained variable declaration." 2110 <<
" found ordered." << std::endl;
2115 error_msgs_ <<
"require unconstrained variable declaration." 2116 <<
" found positive_ordered." << std::endl;
2121 error_msgs_ <<
"require unconstrained variable declaration." 2122 <<
" found cholesky_factor." << std::endl;
2127 error_msgs_ <<
"require unconstrained variable declaration." 2128 <<
" found cholesky_factor_corr." << std::endl;
2133 error_msgs_ <<
"require unconstrained variable declaration." 2134 <<
" found cov_matrix." << std::endl;
2139 error_msgs_ <<
"require unconstrained variable declaration." 2140 <<
" found corr_matrix." << std::endl;
2160 for (
size_t i = 0; i < x.
args_.size(); ++i)
2161 if (!boost::apply_visitor(*
this, x.
args_[i].expr_))
2172 <<
" in dimension declarations." 2174 <<
" found variable=" << x.
name_ 2175 <<
"; declared in block=";
2182 return boost::apply_visitor(*
this, x.
y0_.
expr_)
2187 return boost::apply_visitor(*
this, x.
y0_.
expr_)
2191 for (
size_t i = 0; i < x.
args_.size(); ++i)
2192 if (!boost::apply_visitor(*
this, x.
args_[i].expr_))
2197 if (!boost::apply_visitor(*
this, x.
expr_.
expr_))
2199 for (
size_t i = 0; i < x.
dimss_.size(); ++i)
2200 for (
size_t j = 0; j < x.
dimss_[i].size(); ++j)
2201 if (!boost::apply_visitor(*
this, x.
dimss_[i][j].expr_))
2206 return boost::apply_visitor(*
this, x.
expr_.
expr_);
2209 return boost::apply_visitor(*
this, x.
cond_.
expr_)
2214 return boost::apply_visitor(*
this, x.
left.
expr_)
2215 && boost::apply_visitor(*
this, x.
right.
expr_);
2222 const bool& declaration_ok,
2225 std::stringstream& error_msgs)
2227 if (!declaration_ok) {
2228 error_msgs <<
"Problem with declaration." << std::endl;
2232 if (allow_constraints) {
2237 pass = boost::apply_visitor(vis, var_decl.
decl_);
2239 boost::phoenix::function<validate_decl_constraints>
2245 std::stringstream& error_msgs)
2247 if (!var_decl.
has_def())
return;
2252 error_msgs <<
"variable definition not possible in this block" 2259 var_decl.
dims().size());
2262 bool types_compatible
2263 = (decl_type.is_primitive()
2264 && def_type.is_primitive()
2265 && (decl_type.type() == def_type.type()
2267 && def_type.type() ==
INT_T)))
2268 || (decl_type.type() == def_type.type());
2269 if (!types_compatible) {
2270 error_msgs <<
"variable definition base type mismatch," 2271 <<
" variable declared as base type: ";
2273 error_msgs <<
" variable definition has base: ";
2278 if (decl_type.num_dims() != def_type.num_dims()) {
2279 error_msgs <<
"variable definition dimensions mismatch," 2280 <<
" definition specifies " 2281 << decl_type.num_dims()
2282 <<
", declaration specifies " 2283 << def_type.num_dims();
2288 boost::phoenix::function<validate_definition>
2293 reserved_word_set_.insert(w);
2296 const std::string& x)
const {
2297 return s.find(x) != s.end();
2301 return contains(reserved_word_set_, identifier)
2303 && !contains(const_fun_name_set_, identifier));
2308 const_fun_name_set_.insert(
"pi");
2309 const_fun_name_set_.insert(
"e");
2310 const_fun_name_set_.insert(
"sqrt2");
2311 const_fun_name_set_.insert(
"log2");
2312 const_fun_name_set_.insert(
"log10");
2313 const_fun_name_set_.insert(
"not_a_number");
2314 const_fun_name_set_.insert(
"positive_infinity");
2315 const_fun_name_set_.insert(
"negative_infinity");
2316 const_fun_name_set_.insert(
"epsilon");
2317 const_fun_name_set_.insert(
"negative_epsilon");
2318 const_fun_name_set_.insert(
"machine_precision");
2335 reserve(
"unit_vector");
2338 reserve(
"positive_ordered");
2339 reserve(
"row_vector");
2341 reserve(
"cholesky_factor_cov");
2342 reserve(
"cholesky_factor_corr");
2343 reserve(
"cov_matrix");
2344 reserve(
"corr_matrix");
2350 reserve(
"parameters");
2351 reserve(
"quantities");
2352 reserve(
"transformed");
2353 reserve(
"generated");
2357 reserve(
"STAN_MAJOR");
2358 reserve(
"STAN_MINOR");
2359 reserve(
"STAN_PATCH");
2360 reserve(
"STAN_MATH_MAJOR");
2361 reserve(
"STAN_MATH_MINOR");
2362 reserve(
"STAN_MATH_PATCH");
2377 reserve(
"char16_t");
2378 reserve(
"char32_t");
2382 reserve(
"constexpr");
2383 reserve(
"const_cast");
2384 reserve(
"continue");
2385 reserve(
"decltype");
2390 reserve(
"dynamic_cast");
2393 reserve(
"explicit");
2406 reserve(
"namespace");
2408 reserve(
"noexcept");
2412 reserve(
"operator");
2416 reserve(
"protected");
2418 reserve(
"register");
2419 reserve(
"reinterpret_cast");
2425 reserve(
"static_assert");
2426 reserve(
"static_cast");
2429 reserve(
"template");
2431 reserve(
"thread_local");
2437 reserve(
"typename");
2439 reserve(
"unsigned");
2443 reserve(
"volatile");
2455 set<string> fun_names = sigs.
key_set();
2456 for (set<string>::iterator it = fun_names.begin();
2457 it != fun_names.end();
2459 if (!contains(const_fun_name_set_, *it))
2465 std::stringstream& error_msgs)
const {
2466 int len = identifier.size();
2468 && identifier[len-1] ==
'_' 2469 && identifier[len-2] ==
'_') {
2470 error_msgs <<
"variable identifier (name) may" 2471 <<
" not end in double underscore (__)" 2473 <<
" found identifer=" << identifier << std::endl;
2477 size_t period_position = identifier.find(
'.');
2478 if (period_position != std::string::npos) {
2479 error_msgs <<
"variable identifier may not contain a period (.)" 2481 <<
" found period at position (indexed from 0)=" 2484 <<
" found identifier=" << identifier
2489 if (identifier_exists(identifier)) {
2490 error_msgs <<
"variable identifier (name) may not be reserved word" 2492 <<
" found identifier=" << identifier
2505 var_decl.
N_ = var_decl.
M_;
2507 boost::phoenix::function<copy_square_cholesky_dimension_if_necessary>
2511 std::stringstream& )
const {
2519 std::stringstream& error_msgs)
const {
2522 validator(expr, pass, error_msgs);
2529 std::stringstream& error_msgs)
const {
2532 validator(expr, pass, error_msgs);
2539 std::stringstream& error_msgs)
2542 error_msgs <<
"dimension declaration requires expression" 2543 <<
" denoting integer; found type=" 2552 bool only_data_dimensions = boost::apply_visitor(vis, expr.
expr_);
2553 pass = only_data_dimensions;
2566 std::stringstream& error_msgs)
2570 validator(expr, pass, error_msgs);
2577 std::stringstream& error_msgs)
2581 validator(expr, pass, error_msgs);
2585 template <
typename T>
2588 std::ostream& error_msgs)
const {
2589 if (vm.
exists(var_decl.name_)) {
2591 error_msgs <<
"duplicate declaration of variable, name=" 2594 error_msgs <<
"; attempt to redeclare as ";
2597 error_msgs <<
"; original declaration as ";
2600 error_msgs << std::endl;
2601 var_decl_result = var_decl;
2605 && var_decl.base_type_ ==
INT_T) {
2607 error_msgs <<
"integer parameters or transformed parameters" 2608 <<
" are not allowed; " 2609 <<
" found declared type int, parameter name=" 2612 var_decl_result = var_decl;
2616 vm.
add(var_decl.name_, var_decl, vo);
2617 var_decl_result = var_decl;
2623 std::ostream&)
const;
2626 std::ostream&)
const;
2629 std::ostream&)
const;
2632 std::ostream&)
const;
2635 std::ostream&)
const;
2638 std::ostream&)
const;
2641 std::ostream&)
const;
2644 std::ostream&)
const;
2648 std::ostream&)
const;
2652 std::ostream&)
const;
2655 std::ostream&)
const;
2658 std::ostream&)
const;
2661 std::ostream&)
const;
2664 std::ostream& error_msgs)
const {
2667 error_msgs <<
"ERROR: break and continue statements are only allowed" 2668 <<
" in the body of a for-loop or while-loop." 2674 std::ostream& error_msgs)
const {
2679 error_msgs <<
"ERROR: expected printable (non-void) expression." void operator()(while_statement &ws, const statement &s) const
An integer variable declaration and optional definition.
expr_type get_result_type(const std::string &name, const std::vector< expr_type > &args, std::ostream &error_msgs, bool sampling_error_style=false)
Return the result expression type resulting from applying a function of the speicified name and argum...
void operator()(conditional_statement &cs, const expression &e, bool &pass, std::stringstream &error_msgs) const
expression high_
Upper bound of range with nil value if only upper bound.
boost::phoenix::function< validate_return_allowed > validate_return_allowed_f
variable_dims var_dims_
Variable plus indexes.
boost::phoenix::function< require_vbar > require_vbar_f
void operator()(var_decl &var_decl_result, const T &var_decl, variable_map &vm, bool &pass, const var_origin &vo, std::ostream &error_msgs) const
bool is_primitive_int() const
Return true if this expression type is an integer type with zero dimensions.
bool fun_exists(const std::set< std::pair< std::string, function_signature_t > > &existing, const std::pair< std::string, function_signature_t > &name_sig, bool name_only=true)
Structure to hold the declaration of a positive ordered vector.
std::string strip_ccdf_suffix(const std::string &dist_fun)
Return the result of removing the suffix from the specified function name indicating it is a CCDF...
boost::phoenix::function< set_void_function > set_void_function_f
Structure to wrap the variant type of statements.
void operator()(function_decl_def &decl, bool &pass, std::ostream &error_msgs) const
bool is_ill_formed() const
Return true if the base type of this type is ill formed.
std::string family_
The name of the distribution.
void operator()(conditional_statement &cs, const statement &s) const
void add(const std::string &name, const expr_type &result_type, const std::vector< expr_type > &arg_types)
Add a built-in function with the specified name, result, type and arguments.
boost::phoenix::function< add_while_body > add_while_body_f
void operator()(variable &var_expr, expression &val, variable_map &vm, std::ostream &error_msgs, bool &pass) const
bool has_lp_suffix(const std::string &name)
Return true if the specified string has the suffix "_lp".
expr_type type_
Type of indexed expression.
const int function_argument_origin
The variable arose as a function argument to a non-void function that does not end in _lp or _rng...
boost::phoenix::function< set_int_range_upper > set_int_range_upper_f
bool is_no_op_statement() const
Return true if the basic statement held by the variant type in this wrapper is the no-op statement...
const int ROW_VECTOR_T
Row vector type; scalar type is real.
AST node for the type delclaration for function arguments.
void operator()(return_statement &s) const
void operator()(variable_map &vm) const
bool operator()(const nil &) const
expr_type type_
Type of result of applying function to arguments.
void operator()(range &range, const expression &expr, bool &pass, std::stringstream &error_msgs) const
boost::phoenix::function< validate_assgn > validate_assgn_f
range range_
Range constraint on values with optional lower and upper bounds.
Structure to hold a row vector variable declaration.
boost::phoenix::function< set_var_type > set_var_type_f
AST node for assignment to variable with multi-indexing.
bool has_def() const
Return true if this declaration also contains a definition.
void set_fun_type(fun &fun, std::ostream &error_msgs)
std::string name_
Name of variable.
const int derived_origin
The origin of the variable is ???.
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
void operator()(const std::string &identifier, bool &pass, std::stringstream &error_msgs) const
distribution dist_
Distribution of the variable.
std::vector< expression > dims_
Dimension sizes for variable.
void operator()(variable_map &vm) const
boost::phoenix::function< set_int_range_lower > set_int_range_lower_f
std::string original_name_
Original name of function being applied (before name transformation).
expr_type return_type_
Tyep of value returned by function.
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
boost::phoenix::function< binary_op_expr > binary_op_f
std::string strip_cdf_suffix(const std::string &dist_fun)
Return the result of removing the suffix from the specified function name indicating it is a CDF...
boost::phoenix::function< validate_expr_type3 > validate_expr_type3_f
void operator()(const bool &allow_constraints, const bool &declaration_ok, const var_decl &var_decl, bool &pass, std::stringstream &error_msgs) const
range truncation_
The truncation range for the distribution.
std::vector< expression > args_
Sequence of expressions for array values.
std::size_t num_dims_
The number of array dimensions.
void operator()(range &range, const expression &expr, bool &pass, std::stringstream &error_msgs) const
boost::phoenix::function< deprecated_integrate_ode > deprecated_integrate_ode_f
Node for holding a double literal.
void operator()(const expression &expr, bool &pass, std::ostream &error_msgs) const
int num_dimss(std::vector< std::vector< stan::lang::expression > > &dimss)
bool has_low() const
Return true if the lower bound is non-nil.
const int parameter_origin
The origin of the variable is the parameter block.
void operator()(var_origin origin, bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< set_fun_type_named > set_fun_type_named_f
bool has_cdf_suffix(const std::string &name)
Return true if the specified function name has a suffix indicating it is a CDF.
boost::phoenix::function< set_no_op > set_no_op_f
boost::phoenix::function< validate_conditional_op > validate_conditional_op_f
const int function_argument_origin_rng
The variable arose as an argument to a non-void function with the _rng suffix.
void qualify_builtins(fun &f)
Add qualifier "stan::math::" to nullary functions defined in the Stan language.
Probability, optimization and sampling library.
expression y0_
Initial state (array of real).
bool deprecate_fun(const std::string &old_name, const std::string &new_name, fun &f, std::ostream &msgs)
Structure to hold an array expression.
void operator()(range &range, const expression &expr, bool &pass, std::stringstream &error_msgs) const
std::string get_prob_fun(const std::string &dist_name)
Return the probability function (density or mass) for the specified distribution name.
void operator()(const function_decl_def &decl, bool &pass, std::set< std::pair< std::string, function_signature_t > > &functions_declared, std::set< std::pair< std::string, function_signature_t > > &functions_defined, std::ostream &error_msgs) const
static function_signatures & instance()
Return the instance of this singleton.
std::size_t num_dims() const
Return the number of dimensions for this type.
boost::phoenix::function< deprecate_increment_log_prob > deprecate_increment_log_prob_f
void operator()(expression &expr, bool &pass, std::ostream &error_msgs) const
Structure for an indexed expression.
This class is a singleton used to store the available functions in the Stan object language and their...
boost::phoenix::function< program_error > program_error_f
std::vector< expression > args_
Sequence of argument expressions for function.
validate_no_constraints_vis(std::stringstream &error_msgs)
void operator()(const std::string &s, bool &pass) const
void add(const std::string &name, const base_var_decl &base_decl, const var_origin &vo)
Add the specified declaration for a variable with the specified name originating in the specified blo...
void operator()(std::ostream &error_msgs) const
bool has_prob_fun_suffix(const std::string &name)
Return true if the function with the specified name has a suffix indicating it is a probability funct...
bool has_var_
True if the conditional operator contains a variable that is declared as a parameter, transformed parameter, or local variable.
std::string get_cdf(const std::string &dist_name)
Return the name of the CDF for the specified distribution name.
bool is_double_return(const std::string &function_name, const std::vector< expr_type > &arg_types, std::ostream &error_msgs)
void operator()(expression &e, array_expr &array_expr, const var_origin &var_origin, bool &pass, const variable_map &var_map, std::ostream &error_msgs) const
std::vector< statement > bodies_
The sequence of bodies to execute.
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
const int DOUBLE_T
Real scalar type.
Structure to hold a covariance matrix variable declaration.
void operator()(pos_iterator_t _begin, pos_iterator_t _end, pos_iterator_t _where, variable_map &vm, std::stringstream &error_msgs) const
bool is_primitive_double() const
Return true if this expression type is a real type with zero dimensions.
expr_type infer_type_indexing(const base_expr_type &base_type, std::size_t dims, std::size_t num_indexes)
Return the expression type resulting from indexing an expression of the specified base type and numbe...
int base_expr_type
The type of a base expression.
Structure for function application.
const int transformed_parameter_origin
The origin of the variable is the transformed parameter block.
bool has_prob_suffix(const std::string &s)
expression expr_
Expression being indexed.
expression y0_
Initial state.
void operator()(expression &expr_result, const expression &expr, std::ostream &error_msgs) const
void operator()(sample &s, const variable_map &var_map, bool &pass, std::ostream &error_msgs) const
void operator()(expression &expr1, bool &pass, const expression &expr2, std::ostream &error_msgs) const
boost::spirit::line_pos_iterator< input_iterator_t > pos_iterator_t
Structure of the type of an expression, which consists of a base type and a number of dimensions...
A map from function names to their base declarations and their origin.
boost::phoenix::function< validate_ints_expression > validate_ints_expression_f
AST node for sampling statements.
boost::phoenix::function< add_conditional_condition > add_conditional_condition_f
boost::phoenix::function< empty_range > empty_range_f
void operator()(const std::string &name, variable_map &vm) const
boost::phoenix::function< subtraction_expr3 > subtraction3_f
Structure for integrate diff eq statement.
boost::phoenix::function< addition_expr3 > addition3_f
void operator()(const std::string &name, const var_origin &origin_allowed, variable &v, bool &pass, const variable_map &vm, std::ostream &error_msgs) const
void operator()(const expression &expr, bool &pass, std::stringstream &error_msgs) const
void validate_integrate_ode_non_control_args(const T &ode_fun, const variable_map &var_map, bool &pass, std::ostream &error_msgs)
bool has_high() const
Return true if the upper bound is non-nil.
Structure to hold the declaration of a simplex.
void replace_suffix(const std::string &old_suffix, const std::string &new_suffix, fun &f)
void operator()(const expr_type &arg_type, bool &pass, std::ostream &error_msgs) const
expression max_num_steps_
Maximum number of steps (integer).
boost::phoenix::function< add_var > add_var_f
expr_type expression_type() const
base_var_decl var_type_
Type of the left hand side variable before indexing.
void operator()(const expression &expr, int var_origin, bool &pass, variable_map &var_map, std::stringstream &error_msgs) const
boost::phoenix::function< remove_lp_var > remove_lp_var_f
void operator()(statement &stmt, const pos_iterator_t &begin, const pos_iterator_t &end) const
Structure to hold a Cholesky factor for a correlation matrix variable declaration.
void operator()(std::stringstream &error_msgs) const
boost::phoenix::function< exponentiation_expr > exponentiation_f
boost::phoenix::function< add_loop_identifier > add_loop_identifier_f
expression cond_
Condition (integer).
expression true_val_
Return value if condition is true.
std::string name_
Name of function being applied.
var_origin var_origin_
Origin of this array expression.
std::string get_ccdf(const std::string &dist_name)
Return the CCDF for the specified distribution.
boost::phoenix::function< set_double_range_lower > set_double_range_lower_f
boost::phoenix::function< validate_void_return_allowed > validate_void_return_allowed_f
void operator()(const expression &e, bool &pass, std::ostream &error_msgs) const
const int function_argument_origin_lp
The variable arose as an argument to a non-void function with the _lp suffix.
void operator()(bool &pass, const stan::lang::expression &expr, std::stringstream &error_msgs) const
boost::phoenix::function< validate_non_void_arg_function > validate_non_void_arg_f
bool identifier_exists(const std::string &identifier) const
void operator()(var_origin origin, bool &pass, std::ostream &error_msgs) const
AST structure for a range object with a low and high value.
void print_var_origin(std::ostream &o, const var_origin &vo)
Write a user-readable version of the specified variable to origin to the specified output stream...
boost::phoenix::function< non_void_expression > non_void_expression_f
void operator()(expression &e, std::vector< idx > &idxs, bool &pass, std::ostream &error_msgs) const
void reserve(const std::string &w)
boost::phoenix::function< remove_loop_identifier > remove_loop_identifier_f
boost::phoenix::function< add_conditional_body > add_conditional_body_f
boost::phoenix::function< transpose_expr > transpose_f
boost::phoenix::function< validate_definition > validate_definition_f
void operator()(std::string &fname, bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< multiplication_expr > multiplication_f
bool is_nil(const expression &e)
Return true if the specified expression is nil.
var_decl_t decl_
The variable declaration variant type.
void operator()(expression &fun_result, fun &fun, const var_origin &var_origin, bool &pass, std::ostream &error_msgs) const
void operator()(conditional_op &cond_expr, const var_origin &var_origin, bool &pass, const variable_map &var_map, std::ostream &error_msgs) const
expression left
First argument.
boost::phoenix::function< validate_identifier > validate_identifier_f
void operator()(expression &expr_result, const expression &expr, bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< validate_int_expression_warn > validate_int_expression_warn_f
void operator()(const bool &allow_sample, bool &pass, std::stringstream &error_msgs) const
void remove(const std::string &name)
Remove the declaraiton for the variable with the specified name.
base_var_decl base_decl() const
Return the base declaration.
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
const int void_function_argument_origin_rng
The variable arose as an argument to a function returning void with an _rng suffix.
boost::phoenix::function< validate_int_expr > validate_int_expr_f
bool discrete_first_arg(const std::string &name) const
Return true if all of the function signatures for functions with the specified name have integer base...
bool fun_name_exists(const std::string &name)
Return true if the function name has been declared as a built-in or by the user.
expression rel_tol_
Relative tolerance (real).
void operator()(expression &expr1, const expression &expr2, const var_origin &var_origin, bool &pass, std::ostream &error_msgs) const
Structure to hold the declaration of a unit vector.
boost::phoenix::function< validate_decl_constraints > validate_decl_constraints_f
AST structure for representing all legal indexes.
void operator()(range &r, std::stringstream &) const
void operator()(while_statement &ws, const expression &e, bool &pass, std::stringstream &error_msgs) const
bool exists(const std::string &name) const
Return true if a variable has been declared with the specified name.
void operator()(no_op_statement &s) const
var_origin var_origin_
Origin of this conditional operator expression.
std::size_t get_num_dims(const std::string &name) const
Return the number of dimensions declared for the variable with the specified name.
bool ends_with(const std::string &suffix, const std::string &s)
Returns true if the specified suffix appears at the end of the specified string.
bool returns_type(const expr_type &return_type, const statement &statement, std::ostream &error_msgs)
Return true if the specified statement is a return statement returning an expression of the specified...
boost::phoenix::function< add_expression_dimss > add_expression_dimss_f
boost::phoenix::function< set_array_expr_type > set_array_expr_type_f
void operator()(function_decl_def &decl, bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< validate_prob_fun > validate_prob_fun_f
boost::phoenix::function< add_line_number > add_line_number_f
bool is_defined(const std::string &name, const function_signature_t &sig)
Return true if the specified function name is defined for the specified signature.
bool lhs_var_occurs_on_rhs() const
Return true if the variable being assigned is a subexpression of the value expression.
void operator()(const integrate_ode_control &ode_fun, const variable_map &var_map, bool &pass, std::ostream &error_msgs) const
void operator()(const expression &expr, bool &pass, std::stringstream &error_msgs) const
base_expr_type type() const
Return the base type of this expression type.
boost::phoenix::function< validate_int_data_expr > validate_int_data_expr_f
std::vector< idx > idxs_
Position(s) in variable being assigned.
void operator()(omni_idx &val) const
std::vector< expression > args_
The sequence of parameters for the distribution.
const int VOID_T
Void type.
boost::phoenix::function< validate_int_expr_silent > validate_int_expr_silent_f
std::size_t begin_line_
The line in the source code where the statement begins.
void operator()(assignment &a, const var_origin &origin_allowed, bool &pass, variable_map &vm, std::ostream &error_msgs) const
var_origin get_origin(const std::string &name) const
Return the origin of the variable declaration for the variable with the specified name...
expr_type indexed_type(const expression &e, const std::vector< idx > &idxs)
Return the type of the expression indexed by the generalized index sequence.
bool has_var_
True if there is a variable within any of the expressions that is a parameter, transformed parameter...
std::stringstream & error_msgs_
void operator()(expression &expr1, const expression &expr2, bool &pass, std::ostream &error_msgs) const
expression theta_
Parameters.
range range_
Range constraint on values with optional lower and upper bounds.
boost::phoenix::function< is_prob_fun > is_prob_fun_f
int var_origin
The type of a variable indicating where a variable was declared.
Structure to hold a matrix variable declaration.
const int void_function_argument_origin
The variable arose as an argument to a function returning void that does not have the _lp or _rng suf...
boost::phoenix::function< set_omni_idx > set_omni_idx_f
void generate_expression(const expression &e, std::ostream &o)
Write the code generated by the specified expression to the specified output stream.
expression N_
Number of columns.
base_expr_type base_type_
Base type for variable.
Structure to hold a Cholesky factor variable declaration.
void operator()(const expression &e, bool &pass, std::ostream &error_msgs) const
std::pair< expr_type, std::vector< expr_type > > function_signature_t
The type of a function signature, mapping a vector of argument expression types to a result expressio...
bool has_non_param_var(const expression &e, const variable_map &var_map)
Returns true if the specified expression contains a variable that requires a Jacobian warning...
expression rhs_
Value being assigned to left hand side variable at indexing position.
void operator()(function_decl_def &decl, variable_map &vm) const
void operator()(const integrate_ode &ode_fun, const variable_map &var_map, bool &pass, std::ostream &error_msgs) const
range range_
Optional lower and upper bound constraints.
range range_
Option lower and upper bounds for values in the vector.
boost::phoenix::function< validate_allow_sample > validate_allow_sample_f
const int data_origin
The origin of the variable is the data block.
boost::phoenix::function< assign_lhs > assign_lhs_f
expr_type type_
Type of array.
boost::phoenix::function< validate_integrate_ode > validate_integrate_ode_f
void operator()(variable_map &vm) const
const int void_function_argument_origin_lp
The variable arose as an argument to a function returning void with _lp suffix.
boost::phoenix::function< validate_double_expr > validate_double_expr_f
base_expr_type base_type_
The base expression type.
expression def() const
Return the definition included in this declaration.
boost::phoenix::function< expression_as_statement > expression_as_statement_f
const int INT_T
Integer type.
expression abs_tol_
Absolute tolerance (real).
std::string integration_function_name_
The name of the integrator.
Structure to hold a column vector variable declaration.
boost::phoenix::function< validate_pmf_pdf_variate > validate_pmf_pdf_variate_f
std::string name_
Name of the argument variable.
std::vector< expression > conditions_
The sequence of conditions (parallel with bodies).
bool contains(const std::set< std::string > &s, const std::string &x) const
void operator()(size_t &lhs) const
void operator()(const expression &e, bool &pass, std::ostream &error_msgs) const
std::vector< arg_decl > arg_decls_
Sequence of argument declarations.
void qualify(fun &f)
Set original name of specified function to name and add "stan::math::" namespace qualifier to name...
The variant structure to hold a variable declaration.
variable lhs_var_
The variable being assigned.
boost::phoenix::function< add_lp_var > add_lp_var_f
Structure to hold a correlation matrix variable declaration.
bool has_var(const expression &e, const variable_map &var_map)
Returns true if the specified expression contains a variable that is defined as a parameter...
base_var_decl base_variable_declaration() const
Return the base declaration corresponding to this argument declaration.
AST node for representing while statements.
boost::phoenix::function< elt_multiplication_expr > elt_multiplication_f
bool is_univariate(const expr_type &et)
expression expr_
The random variable.
void operator()(const std::vector< var_decl > &var_decls, variable_map &vm) const
void operator()(L &lhs, const R &rhs) const
AST structure for holding an expression with a sequence of indexes.
AST base class for variable declarations, which share most of their structure.
void operator()(const expression &e, bool &pass, std::ostream &error_msgs) const
bool is_primitive() const
Return true if this expression type is an integer or real type with zero dimensions.
std::vector< expression > dims_
Sequence of expressions for dimensions.
bool has_ccdf_suffix(const std::string &name)
Return true if the specified function name has a suffix indicating it is a CCDF.
void operator()(const assgn &a, bool &pass, std::ostream &error_msgs) const
void operator()(range &range, const expression &expr, bool &pass, std::stringstream &error_msgs) const
expression low_
Lower bound of range with nil value if only upper bound.
boost::phoenix::function< set_allows_sampling_origin > set_allows_sampling_origin_f
std::string name_
Name of the variable.
Structure for the conditional operator.
AST node for the no-operation statement.
boost::phoenix::function< logical_negate_expr > logical_negate_expr_f
expression expr_
Value being assigned, which appears on the right hand side of the assignment.
An integer variable declaration and optional definition.
boost::phoenix::function< validate_sample > validate_sample_f
boost::phoenix::function< increment_size_t > increment_size_t_f
std::set< std::string > key_set() const
Return the set of function names defined.
const int VECTOR_T
Column vector type; scalar type is real.
boost::phoenix::function< add_function_signature > add_function_signature_f
void operator()(std::ostream &error_msgs) const
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
Structure to hold a variable.
bool is_defined(const std::string &function_name, const std::vector< expr_type > &arg_types)
boost::phoenix::function< set_double_range_upper > set_double_range_upper_f
boost::phoenix::function< add_idxs > add_idxs_f
expression right
Second argument.
Structure to hold the declaration of an ordered vector.
range range_
Option lower and upper bounds for values in the vector.
std::string strip_prob_fun_suffix(const std::string &dist_fun)
Return the result of stripping the suffix indicating it is a probability function from the specified ...
void operator()(const std::string &identifier, bool &allow_sampling, int &origin) const
expression subject
Argument.
std::stringstream & error_msgs_
const int local_origin
The origin of the variable is as a local variable.
boost::phoenix::function< unscope_locals > unscope_locals_f
std::ostream & write_base_expr_type(std::ostream &o, base_expr_type type)
Write a user-readable version of the specified base expression type to the specified output stream...
std::string name_
Name of the function.
AST node for the return statement.
void set_user_defined(const std::pair< std::string, function_signature_t > &name_sig)
Set the specified name and signature to be a user-defined function.
boost::phoenix::function< division_expr > division_f
void operator()(const std::string &name, std::string &name_local, bool &pass, variable_map &vm, std::stringstream &error_msgs) const
boost::phoenix::function< unscope_variables > unscope_variables_f
std::size_t end_line_
The line in the source code where the statement ends.
boost::phoenix::function< elt_division_expr > elt_division_f
void operator()(bool &pass, std::set< std::pair< std::string, function_signature_t > > &declared, std::set< std::pair< std::string, function_signature_t > > &defined, std::ostream &error_msgs, bool allow_undefined) const
bool is_void() const
Return true if this type is void.
void operator()(const expr_type &return_type, var_origin &origin, bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< identifier_to_var > identifier_to_var_f
void operator()(cholesky_factor_var_decl &var_decl) const
boost::phoenix::function< validate_in_loop > validate_in_loop_f
void set_type(const base_expr_type &base_type, std::size_t num_dims)
Set the type of the variable to the expression type with the specified base type and number of dimens...
bool is_discrete_
Discreteness flag.
expression theta_
Parameters (array of real).
boost::phoenix::function< negate_expr > negate_expr_f
AST structure for unary operations consisting of an operation and argument.
AST node for a function declaration and definition including return type name, arguments, and body.
statement body_
The loop body.
boost::phoenix::function< copy_square_cholesky_dimension_if_necessary > copy_square_cholesky_dimension_if_necessary_f
bool operator()(const nil &) const
boost::phoenix::function< validate_return_type > validate_return_type_f
Node for storing binary operations consisting of an operation and left and right arguments.
void operator()(bool &pass, std::ostream &error_msgs) const
boost::phoenix::function< add_fun_var > add_fun_var_f
void operator()(const expression &e, bool &pass) const
std::vector< std::vector< expression > > dimss_
Sequence of sequences of indexes.
boost::phoenix::function< add_while_condition > add_while_condition_f
boost::phoenix::function< validate_assignment > validate_assignment_f
bool deprecate_suffix(const std::string &deprecated_suffix, const std::string &replacement, fun &f, std::ostream &msgs)
boost::phoenix::function< validate_integrate_ode_control > validate_integrate_ode_control_f
The nil structure used as a placeholder for undefined or empty values in several structures.
boost::phoenix::function< validate_declarations > validate_declarations_f
const int ILL_FORMED_T
Type denoting an ill-formed expression.
boost::phoenix::function< left_division_expr > left_division_f
boost::phoenix::function< set_void_return > set_void_return_f
const int MATRIX_T
Matrix type; scalar type is real.
boost::phoenix::function< modulus_expr > modulus_f
expression false_val_
Return value if condition is false.
base_expr_type get_base_type(const std::string &name) const
Return the type declared for the variable with the specified name.
bool has_rng_suffix(const std::string &name)
Return true if the specified string has the suffix "_rng".
expression M_
Number of rows.
data_only_expression(std::stringstream &error_msgs, variable_map &var_map)
boost::phoenix::function< scope_lp > scope_lp_f
Structure for a diff eq integration statement with control parameters for the integrator.
const int transformed_data_origin
The origin of the variable is the transformed data block.
boost::phoenix::function< deprecate_old_assignment_op > deprecate_old_assignment_op_f
void operator()(arg_decl &decl, bool &pass, variable_map &vm, std::ostream &error_msgs) const
void operator()(bool in_loop, bool &pass, std::ostream &error_msgs) const
void operator()(expression &expr1, const expression &expr2, std::ostream &error_msgs) const
base_var_decl get(const std::string &name) const
Return the type for the variable with the specified name.
void operator()(expression &expression, std::vector< std::vector< stan::lang::expression > > &dimss, bool &pass, std::ostream &error_msgs) const
std::vector< expression > dims() const
Return the sequence of array dimension sizes.
AST node for conditional statements.
statement body_
Body of the function.
boost::phoenix::function< validate_non_void_expression > validate_non_void_expression_f
AST node for assignment statements.
expression condition_
The loop condition.
void qualify_cpp11_builtins(fun &f)
Add namespace qualifier stan::math:: to specify Stan versions of functions to avoid ambiguities with ...
void operator()(const var_origin &origin, const var_decl &var_decl, bool &pass, std::stringstream &error_msgs) const
expression expr_
Expression being indexed.
void operator()(expression &expr1, const expression &expr2, const std::string &op, const std::string &fun_name, std::ostream &error_msgs) const
expr_type type_
Type of result.