Classes | Typedefs | Functions | Variables
stan::lang Namespace Reference

Classes

struct  add_array_loop_identifier
 
struct  add_conditional_body
 
struct  add_conditional_condition
 
struct  add_expression_dimss
 
struct  add_fun_var
 
struct  add_function_signature
 
struct  add_idxs
 
struct  add_line_number
 
struct  add_loop_identifier
 
struct  add_matrix_loop_identifier
 
struct  add_params_var
 
struct  add_var
 
struct  add_while_body
 
struct  add_while_condition
 
struct  addition_expr3
 
struct  algebra_solver
 
struct  algebra_solver_control
 
struct  arg_decl
 
struct  array_expr
 
struct  assgn
 
struct  assign_lhs
 
struct  bare_type_grammar
 
struct  base_expr_type
 
struct  base_var_decl
 
struct  binary_op
 
struct  binary_op_expr
 
struct  break_continue_statement
 
struct  cholesky_corr_var_decl
 
struct  cholesky_factor_var_decl
 
struct  conditional_op
 
struct  conditional_statement
 
struct  constrained_param_names_visgen
 
struct  copy_square_cholesky_dimension_if_necessary
 
struct  corr_matrix_var_decl
 
struct  cov_matrix_var_decl
 
struct  data_only_expression
 
struct  deprecate_increment_log_prob
 
struct  deprecate_old_assignment_op
 
struct  deprecate_pound_comment
 
struct  deprecated_integrate_ode
 
struct  distribution
 
struct  division_expr
 
struct  double_literal
 
struct  double_type
 
struct  double_var_decl
 
struct  dump_member_var_visgen
 
struct  elt_division_expr
 
struct  elt_multiplication_expr
 
struct  empty_range
 
struct  exponentiation_expr
 
struct  expr_type
 
struct  expression
 
struct  expression07_grammar
 
struct  expression_as_statement
 
struct  expression_grammar
 
struct  expression_type_vis
 
struct  expression_visgen
 
struct  for_array_statement
 
struct  for_matrix_statement
 
struct  for_statement
 
struct  fun
 
struct  function_arg_type
 
struct  function_decl_def
 
struct  function_decl_defs
 
class  function_signatures
 
struct  functions_grammar
 
struct  has_non_param_var_vis
 
struct  has_var_vis
 
struct  idx
 
struct  idx_user_visgen
 
struct  idx_visgen
 
struct  ill_formed_type
 
struct  increment_log_prob_statement
 
struct  increment_size_t
 
struct  index_op
 
struct  index_op_sliced
 
struct  indexes_grammar
 
struct  infer_array_expr_type
 
struct  infer_vec_or_matrix_expr_type
 
struct  init_local_var_visgen
 
struct  init_vars_visgen
 
struct  init_visgen
 
struct  int_literal
 
struct  int_type
 
struct  int_var_decl
 
struct  integrate_ode
 
struct  integrate_ode_control
 
struct  is_multi_index_vis
 
struct  is_nil_vis
 
struct  is_no_op_statement_vis
 
struct  is_numbered_statement_vis
 
struct  is_prob_fun
 
struct  lb_idx
 
struct  left_division_expr
 
struct  local_var_decl_visgen
 
struct  local_var_init_nan_visgen
 
struct  located_exception
 
struct  logical_negate_expr
 
struct  lub_idx
 
struct  map_rect
 
struct  matrix_expr
 
struct  matrix_type
 
struct  matrix_var_decl
 
struct  member_var_decl_visgen
 
struct  modulus_expr
 
struct  multi_idx
 
struct  multiplication_expr
 
struct  name_vis
 
struct  negate_expr
 
struct  nil
 
struct  no_op_statement
 
struct  non_void_expression
 
struct  non_void_return_msg
 
struct  omni_idx
 
struct  ordered_var_decl
 
struct  phoenix_functor_binary
 
struct  phoenix_functor_quaternary
 
struct  phoenix_functor_quinary
 
struct  phoenix_functor_senary
 
struct  phoenix_functor_septenary
 
struct  phoenix_functor_ternary
 
struct  phoenix_functor_unary
 
struct  positive_ordered_var_decl
 
struct  print_statement
 
struct  printable
 
struct  printable_visgen
 
struct  program
 
struct  program_error
 
struct  program_grammar
 
struct  range
 
struct  reject_statement
 
struct  remove_loop_identifier
 
struct  remove_params_var
 
struct  require_vbar
 
struct  reset_var_scope
 
struct  return_statement
 
struct  returns_type_vis
 
struct  row_vector_expr
 
struct  row_vector_type
 
struct  row_vector_var_decl
 
struct  sample
 
class  scope
 
struct  set_allows_sampling_origin
 
struct  set_data_origin
 
struct  set_double_range_lower
 
struct  set_double_range_upper
 
struct  set_fun_params_scope
 
struct  set_fun_type_named
 
struct  set_int_range_lower
 
struct  set_int_range_upper
 
struct  set_lhs_var_assgn
 
struct  set_no_op
 
struct  set_omni_idx
 
struct  set_param_ranges_visgen
 
struct  set_var_scope
 
struct  set_var_scope_local
 
struct  set_var_type
 
struct  set_void_function
 
struct  set_void_return
 
struct  simplex_var_decl
 
struct  statement
 
struct  statement_2_grammar
 
struct  statement_grammar
 
struct  statement_visgen
 
struct  statements
 
struct  store_loop_identifier
 
struct  subtraction_expr3
 
struct  term_grammar
 
struct  trace
 
struct  transpose_expr
 
struct  ub_idx
 
struct  unary_op
 
struct  unconstrained_param_names_visgen
 
struct  uni_idx
 
struct  unit_vector_var_decl
 
struct  unscope_locals
 
struct  unscope_variables
 
struct  validate_algebra_solver
 
struct  validate_algebra_solver_control
 
struct  validate_allow_sample
 
struct  validate_assgn
 
struct  validate_conditional_op
 
struct  validate_decl_constraints
 
struct  validate_declarations
 
struct  validate_definition
 
struct  validate_double_expr
 
struct  validate_expr_type3
 
struct  validate_identifier
 
struct  validate_in_loop
 
struct  validate_int_data_expr
 
struct  validate_int_expr
 
struct  validate_int_expr_no_error_msgs
 
struct  validate_int_expr_silent
 
struct  validate_int_expression_warn
 
struct  validate_integrate_ode
 
struct  validate_integrate_ode_control
 
struct  validate_ints_expression
 
struct  validate_lhs_var_assgn
 
struct  validate_map_rect
 
struct  validate_no_constraints_vis
 
struct  validate_non_void_arg_function
 
struct  validate_non_void_expression
 
struct  validate_pmf_pdf_variate
 
struct  validate_prob_fun
 
struct  validate_return_allowed
 
struct  validate_return_type
 
struct  validate_sample
 
struct  validate_transformed_params_visgen
 
struct  validate_var_decl_visgen
 
struct  validate_void_return_allowed
 
struct  var_decl
 
struct  var_decl_base_type_vis
 
struct  var_decl_def_vis
 
struct  var_decl_dims_vis
 
struct  var_decl_has_def_vis
 
struct  var_decls_grammar
 
struct  var_occurs_vis
 
struct  var_resizing_visgen
 
struct  var_size_validating_visgen
 
struct  variable
 
struct  variable_dims
 
struct  variable_map
 
struct  vector_type
 
struct  vector_var_decl
 
struct  visgen
 
struct  void_type
 
struct  while_statement
 
struct  whitespace_grammar
 
struct  write_array_vars_visgen
 
struct  write_array_visgen
 
struct  write_dims_visgen
 
struct  write_param_names_visgen
 

Typedefs

typedef int origin_block
 
typedef std::pair< expr_type, std::vector< function_arg_type > > function_signature_t
 
typedef std::string::const_iterator input_iterator_t
 
typedef boost::spirit::line_pos_iterator< input_iterator_tpos_iterator_t
 

Functions

std::ostream & operator<< (std::ostream &o, const expr_type &et)
 
bool ends_with (const std::string &suffix, const std::string &s)
 
bool fun_name_exists (const std::string &name)
 
void generate_expression (const expression &e, bool user_facing, std::ostream &o)
 
std::string get_ccdf (const std::string &dist_name)
 
std::string get_cdf (const std::string &dist_name)
 
std::string get_prob_fun (const std::string &dist_name)
 
bool has_ccdf_suffix (const std::string &name)
 
bool has_cdf_suffix (const std::string &name)
 
bool has_lp_suffix (const std::string &name)
 
bool has_non_param_var (const expression &e, const variable_map &var_map)
 
bool is_linear_function (const std::string &name)
 
bool has_prob_fun_suffix (const std::string &name)
 
bool has_rng_suffix (const std::string &name)
 
bool has_var (const expression &e, const variable_map &var_map)
 
expr_type indexed_type (const expression &e, const std::vector< idx > &idxs)
 
expr_type infer_type_indexing (const base_expr_type &base_type, std::size_t dims, std::size_t num_indexes)
 
expr_type infer_type_indexing (const expression &expr, std::size_t num_indexes)
 
expr_type infer_type_indexing (const base_expr_type &expr_base_type, size_t num_expr_dims, size_t num_index_dims)
 
expr_type infer_type_indexing (const expression &expr, size_t num_index_dims)
 
bool is_assignable (const expr_type &l_type, const expr_type &r_type, const std::string &failure_message, std::ostream &error_msgs)
 
bool is_multi_index (const idx &idx)
 
bool is_nil (const expression &e)
 
bool is_nonempty (const std::string &s)
 
bool is_space (char c)
 
bool is_user_defined (const fun &fx)
 
bool is_user_defined (const std::string &name, const std::vector< expression > &args)
 
bool is_user_defined_prob_function (const std::string &name, const expression &variate, const std::vector< expression > &params)
 
std::ostream & operator<< (std::ostream &o, const function_arg_type &fa_type)
 
void print_scope (std::ostream &o, const scope &var_scope)
 
expr_type promote_primitive (const expr_type &et)
 
expr_type promote_primitive (const expr_type &et1, const expr_type &et2)
 
bool returns_type (const expr_type &return_type, const statement &statement, std::ostream &error_msgs)
 
std::string strip_ccdf_suffix (const std::string &dist_fun)
 
std::string strip_cdf_suffix (const std::string &dist_fun)
 
std::string strip_prob_fun_suffix (const std::string &dist_fun)
 
std::size_t total_dims (const std::vector< std::vector< expression > > &dimss)
 
std::ostream & write_base_expr_type (std::ostream &o, base_expr_type type)
 
bool is_binary_operator (const std::string &name)
 
bool is_unary_operator (const std::string &name)
 
bool is_unary_postfix_operator (const std::string &name)
 
bool is_operator (const std::string &name)
 
std::string fun_name_to_operator (const std::string &name)
 
void print_signature (const std::string &name, const std::vector< expr_type > &arg_types, bool sampling_error_style, std::ostream &msgs)
 
void print_signature (const std::string &name, const std::vector< function_arg_type > &arg_types, bool sampling_error_style, std::ostream &msgs)
 
bool compile_functions (std::ostream *msgs, std::istream &stan_funcs_in, std::ostream &cpp_out, const std::vector< std::string > &namespaces, const bool allow_undefined=false, const std::string &filename="unknown file name", const std::vector< std::string > &include_paths=std::vector< std::string >())
 
bool compile (std::ostream *msgs, std::istream &in, std::ostream &out, const std::string &name, const bool allow_undefined=false, const std::string &filename="unknown file name", const std::vector< std::string > &include_paths=std::vector< std::string >())
 
const std::string EOL ("\n")
 
const std::string EOL2 ("\n\n")
 
const std::string INDENT (" ")
 
const std::string INDENT2 (" ")
 
const std::string INDENT3 (" ")
 
const std::vector< expressionEMPTY_EXP_VECTOR (0)
 
const bool USER_FACING (true)
 
const bool NOT_USER_FACING (false)
 
void generate_array_builder_adds (const std::vector< expression > &elements, bool user_facing, std::ostream &o)
 
void generate_idxs (const std::vector< idx > &idxs, std::ostream &o)
 
void generate_idxs_user (const std::vector< idx > &idxs, std::ostream &o)
 
std::string fun_scalar_type (const function_decl_def &fun, bool is_lp)
 
void generate_idx_user (const idx &i, std::ostream &o)
 
void generate_arg_decl (bool gen_const, bool gen_ref, const arg_decl &decl, const std::string &scalar_t_name, std::ostream &o)
 
void generate_array_var_type (const base_expr_type &base_type, const std::string &real_var_type, std::ostream &o)
 
void generate_bare_type (const expr_type &t, const std::string &scalar_t_name, std::ostream &o)
 
void generate_catch_throw_located (int indent, std::ostream &o)
 
void generate_class_decl (const std::string &model_name, std::ostream &o)
 
void generate_class_decl_end (std::ostream &o)
 
void generate_comment (const std::string &msg, int indent, std::ostream &o)
 
void generate_constrained_param_names_method (const program &prog, std::ostream &o)
 
void generate_constructor (const program &prog, const std::string &model_name, std::ostream &o)
 
void generate_cpp (const program &prog, const std::string &model_name, const std::vector< io::preproc_event > &history, std::ostream &o)
 
void generate_destructor (const std::string &model_name, std::ostream &o)
 
void generate_dims_method (const program &prog, std::ostream &o)
 
void generate_eigen_index_expression (const expression &e, std::ostream &o)
 
void generate_function_instantiation_template_parameters (const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, const std::string &rng_class, std::ostream &out)
 
void generate_function (const function_decl_def &fun, std::ostream &out)
 
void generate_function_arguments (const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o, bool double_only=false, std::string rng_type="RNG", bool parameter_defaults=false)
 
void generate_function_body (const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &o)
 
void generate_function_functor (const function_decl_def &fun, std::ostream &o)
 
void generate_function_inline_return_type (const function_decl_def &fun, const std::string &scalar_t_name, int indent, std::ostream &out)
 
void generate_function_instantiation (const function_decl_def &fun, const std::vector< std::string > &namespaces, std::ostream &out)
 
void generate_function_instantiation_body (const function_decl_def &fun, const std::vector< std::string > &namespaces, bool is_rng, bool is_lp, bool is_log, const std::string &rng_class, std::ostream &o)
 
void generate_function_instantiation_name (const function_decl_def &fun, std::ostream &out)
 
void generate_function_instantiations (const std::vector< function_decl_def > &funs, const std::vector< std::string > &namespaces, std::ostream &o)
 
void generate_function_name (const function_decl_def &fun, std::ostream &o)
 
void generate_function_template_parameters (const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
 
void generate_functions (const std::vector< function_decl_def > &funs, std::ostream &o)
 
void generate_functor_arguments (const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o)
 
void generate_globals (std::ostream &o)
 
void generate_idx (const idx &i, std::ostream &o)
 
void generate_idxs (size_t pos, const std::vector< idx > &idxs, std::ostream &o)
 
void generate_include (const std::string &lib_name, std::ostream &o)
 
void generate_includes (std::ostream &o)
 
void generate_indent (size_t indent, std::ostream &o)
 
template<bool isLHS>
void generate_indexed_expr (const std::string &expr, const std::vector< expression > &indexes, base_expr_type base_type, size_t e_num_dims, bool user_facing, std::ostream &o)
 
void generate_indexed_expr_user (const std::string &expr, const std::vector< expression > indexes, std::ostream &o)
 
void generate_init_method (const std::vector< var_decl > &vs, std::ostream &o)
 
void generate_initialization (std::ostream &o, size_t indent, 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 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())
 
template<typename T >
void generate_line_number (const T &line, int indent, std::ostream &o)
 
template void generate_line_number (const var_decl &, int indent, std::ostream &o)
 
template void generate_line_number (const statement &, int indent, std::ostream &o)
 
void generate_local_var_decls (const std::vector< var_decl > &vs, int indent, std::ostream &o)
 
void generate_local_var_inits (std::vector< var_decl > vs, bool declare_vars, int indent, std::ostream &o)
 
void generate_log_prob (const program &p, std::ostream &o)
 
void generate_member_var_decls (const std::vector< var_decl > &vs, int indent, std::ostream &o)
 
void generate_member_var_decls_all (const program &prog, std::ostream &o)
 
void generate_member_var_inits (const std::vector< var_decl > &vs, int indent, std::ostream &o)
 
void generate_model_name_method (const std::string &model_name, std::ostream &o)
 
void generate_model_typedef (const std::string &model_name, std::ostream &o)
 
void generate_namespace_end (std::ostream &o)
 
void generate_namespace_start (const std::string &name, std::ostream &o)
 
void generate_param_names_method (const program &prog, std::ostream &o)
 
void generate_printable (const printable &p, std::ostream &o)
 
void generate_private_decl (std::ostream &o)
 
void generate_program_reader_fun (const std::vector< io::preproc_event > &history, std::ostream &o)
 
void generate_propto_default_function (const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &o)
 
void generate_propto_default_function_body (const function_decl_def &fun, std::ostream &o)
 
void generate_public_decl (std::ostream &o)
 
void generate_quoted_expression (const expression &e, std::ostream &o)
 
void generate_quoted_string (const std::string &s, std::ostream &o)
 
void generate_real_var_type (const scope &var_scope, bool has_var, std::ostream &o)
 
void generate_register_mpi (const std::string &model_name, std::ostream &o)
 
void generate_set_param_ranges (const std::vector< var_decl > &var_decls, int indent, std::ostream &o)
 
void generate_standalone_functions (const program &prog, const std::vector< std::string > &namespaces, const std::vector< io::preproc_event > &history, std::ostream &o)
 
void generate_statement (const statement &s, int indent, std::ostream &o)
 
void generate_statements (const std::vector< statement > statements, int indent, std::ostream &o)
 
void generate_try (int indent, std::ostream &o)
 
void generate_type (const std::string &base_type, const std::vector< expression > &, size_t end, std::ostream &o)
 
void generate_typedef (const std::string &type, const std::string &abbrev, std::ostream &o)
 
void generate_typedefs (std::ostream &o)
 
void generate_unconstrained_param_names_method (const program &prog, std::ostream &o)
 
void generate_using (const std::string &type, std::ostream &o)
 
void generate_using_namespace (const std::string &ns, std::ostream &o)
 
void generate_usings (std::ostream &o)
 
void generate_usings_standalone_functions (std::ostream &o)
 
void generate_validate_context_size (size_t indent, 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 generate_validate_positive (const std::string &var_name, const expression &expr, int indents, std::ostream &o)
 
void generate_validate_transformed_params (const std::vector< var_decl > &vs, int indent, std::ostream &o)
 
void generate_validate_var_decl (const var_decl &decl, int indent, std::ostream &o)
 
void generate_validate_var_decls (const std::vector< var_decl > decls, int indent, std::ostream &o)
 
void generate_var_resizing (const std::vector< var_decl > &vs, int indent, std::ostream &o)
 
void generate_version_comment (std::ostream &o)
 
void generate_void_statement (const std::string &name, const size_t indent, std::ostream &o)
 
void generate_write_array_method (const program &prog, const std::string &model_name, std::ostream &o)
 
template<typename D >
bool has_lb (const D &x)
 
template<typename D >
bool has_lub (const D &x)
 
bool has_only_int_args (const function_decl_def &fun)
 
template<typename D >
bool has_ub (const D &x)
 
void generate_statement (const std::vector< statement > &ss, int indent, std::ostream &o)
 
template<typename T >
std::string to_string (const T &x)
 
bool has_prob_suffix (const std::string &s)
 
void replace_suffix (const std::string &old_suffix, const std::string &new_suffix, fun &f)
 
void set_fun_type (fun &fun, std::ostream &error_msgs)
 
int num_dimss (std::vector< std::vector< stan::lang::expression > > &dimss)
 
template<class T >
void validate_integrate_ode_non_control_args (const T &ode_fun, const variable_map &var_map, bool &pass, std::ostream &error_msgs)
 
template<class T >
void validate_algebra_solver_non_control_args (const T &alg_fun, const variable_map &var_map, bool &pass, std::ostream &error_msgs)
 
void qualify_builtins (fun &f)
 
bool has_rng_lp_suffix (const std::string &s)
 
bool deprecate_fun (const std::string &old_name, const std::string &new_name, fun &f, std::ostream &msgs)
 
bool deprecate_suffix (const std::string &deprecated_suffix, const std::string &replacement, fun &f, std::ostream &msgs)
 
bool is_double_return (const std::string &function_name, const std::vector< expr_type > &arg_types, std::ostream &error_msgs)
 
bool is_univariate (const expr_type &et)
 
bool can_assign_to_lhs_var (const std::string &lhs_var_name, const scope &var_scope, const variable_map &vm, std::ostream &error_msgs)
 
expr_type infer_var_dims_type (const base_var_decl &var_type, const variable_dims &var_dims)
 
bool has_same_shape (const expr_type &lhs_type, const expression &rhs_expr, const std::string &name, const std::string &stmt_type, std::ostream &error_msgs)
 
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)
 
void dump_program_line (size_t idx_errline, int offset, const std::string &origin_file, size_t origin_line, const io::program_reader &reader, const std::vector< std::string > &program_lines, std::stringstream &error_msgs)
 
bool parse (std::ostream *out, std::istream &in, const std::string &name, const io::program_reader &reader, program &prog, const bool allow_undefined=false)
 
template<typename E >
bool is_type (const std::exception &e)
 
void rethrow_located (const std::exception &e, int line, const io::program_reader &reader=stan::io::program_reader())
 

Variables

const int model_name_origin = 0
 
const int data_origin = 1
 
const int transformed_data_origin = 2
 
const int parameter_origin = 3
 
const int transformed_parameter_origin = 4
 
const int derived_origin = 5
 
const int function_argument_origin = 6
 
const int function_argument_origin_lp = 7
 
const int function_argument_origin_rng = 8
 
const int void_function_argument_origin = 9
 
const int void_function_argument_origin_lp = 10
 
const int void_function_argument_origin_rng = 11
 
const int loop_identifier_origin = 12
 
boost::phoenix::function< assign_lhsassign_lhs_f
 
boost::phoenix::function< validate_expr_type3validate_expr_type3_f
 
boost::phoenix::function< is_prob_funis_prob_fun_f
 
boost::phoenix::function< addition_expr3addition3_f
 
boost::phoenix::function< subtraction_expr3subtraction3_f
 
boost::phoenix::function< increment_size_tincrement_size_t_f
 
boost::phoenix::function< validate_conditional_opvalidate_conditional_op_f
 
boost::phoenix::function< binary_op_exprbinary_op_f
 
boost::phoenix::function< validate_non_void_arg_functionvalidate_non_void_arg_f
 
boost::phoenix::function< set_void_functionset_void_function_f
 
boost::phoenix::function< set_allows_sampling_originset_allows_sampling_origin_f
 
boost::phoenix::function< validate_declarationsvalidate_declarations_f
 
boost::phoenix::function< add_function_signatureadd_function_signature_f
 
boost::phoenix::function< validate_return_typevalidate_return_type_f
 
boost::phoenix::function< validate_pmf_pdf_variatevalidate_pmf_pdf_variate_f
 
boost::phoenix::function< validate_prob_funvalidate_prob_fun_f
 
boost::phoenix::function< set_fun_params_scopeset_fun_params_scope_f
 
boost::phoenix::function< unscope_variablesunscope_variables_f
 
boost::phoenix::function< add_fun_varadd_fun_var_f
 
boost::phoenix::function< set_omni_idxset_omni_idx_f
 
boost::phoenix::function< validate_int_expr_silentvalidate_int_expr_silent_f
 
boost::phoenix::function< validate_int_expression_warnvalidate_int_expression_warn_f
 
boost::phoenix::function< validate_ints_expressionvalidate_ints_expression_f
 
boost::phoenix::function< add_params_varadd_params_var_f
 
boost::phoenix::function< remove_params_varremove_params_var_f
 
boost::phoenix::function< program_errorprogram_error_f
 
boost::phoenix::function< add_conditional_conditionadd_conditional_condition_f
 
boost::phoenix::function< add_conditional_bodyadd_conditional_body_f
 
boost::phoenix::function< deprecate_old_assignment_opdeprecate_old_assignment_op_f
 
boost::phoenix::function< non_void_return_msgnon_void_return_msg_f
 
boost::phoenix::function< validate_return_allowedvalidate_return_allowed_f
 
boost::phoenix::function< validate_void_return_allowedvalidate_void_return_allowed_f
 
boost::phoenix::function< set_lhs_var_assgnset_lhs_var_assgn_f
 
boost::phoenix::function< validate_lhs_var_assgnvalidate_lhs_var_assgn_f
 
boost::phoenix::function< validate_assgnvalidate_assgn_f
 
boost::phoenix::function< validate_samplevalidate_sample_f
 
boost::phoenix::function< expression_as_statementexpression_as_statement_f
 
boost::phoenix::function< unscope_localsunscope_locals_f
 
boost::phoenix::function< add_while_conditionadd_while_condition_f
 
boost::phoenix::function< add_while_bodyadd_while_body_f
 
boost::phoenix::function< add_loop_identifieradd_loop_identifier_f
 
boost::phoenix::function< add_array_loop_identifieradd_array_loop_identifier_f
 
boost::phoenix::function< add_matrix_loop_identifieradd_matrix_loop_identifier_f
 
boost::phoenix::function< store_loop_identifierstore_loop_identifier_f
 
boost::phoenix::function< remove_loop_identifierremove_loop_identifier_f
 
boost::phoenix::function< deprecate_increment_log_probdeprecate_increment_log_prob_f
 
boost::phoenix::function< validate_allow_samplevalidate_allow_sample_f
 
boost::phoenix::function< validate_non_void_expressionvalidate_non_void_expression_f
 
boost::phoenix::function< set_void_returnset_void_return_f
 
boost::phoenix::function< set_no_opset_no_op_f
 
boost::phoenix::function< deprecated_integrate_odedeprecated_integrate_ode_f
 
boost::phoenix::function< validate_integrate_odevalidate_integrate_ode_f
 
boost::phoenix::function< validate_integrate_ode_controlvalidate_integrate_ode_control_f
 
boost::phoenix::function< validate_algebra_solvervalidate_algebra_solver_f
 
boost::phoenix::function< validate_algebra_solver_controlvalidate_algebra_solver_control_f
 
boost::phoenix::function< validate_map_rectvalidate_map_rect_f
 
boost::phoenix::function< set_fun_type_namedset_fun_type_named_f
 
boost::phoenix::function< infer_array_expr_typeinfer_array_expr_type_f
 
boost::phoenix::function< infer_vec_or_matrix_expr_typeinfer_vec_or_matrix_expr_type_f
 
boost::phoenix::function< exponentiation_exprexponentiation_f
 
boost::phoenix::function< multiplication_exprmultiplication_f
 
boost::phoenix::function< division_exprdivision_f
 
boost::phoenix::function< modulus_exprmodulus_f
 
boost::phoenix::function< left_division_exprleft_division_f
 
boost::phoenix::function< elt_multiplication_exprelt_multiplication_f
 
boost::phoenix::function< elt_division_exprelt_division_f
 
boost::phoenix::function< negate_exprnegate_expr_f
 
boost::phoenix::function< logical_negate_exprlogical_negate_expr_f
 
boost::phoenix::function< transpose_exprtranspose_f
 
boost::phoenix::function< add_idxsadd_idxs_f
 
boost::phoenix::function< add_expression_dimssadd_expression_dimss_f
 
boost::phoenix::function< set_var_typeset_var_type_f
 
boost::phoenix::function< require_vbarrequire_vbar_f
 
boost::phoenix::function< add_line_numberadd_line_number_f
 
boost::phoenix::function< validate_decl_constraintsvalidate_decl_constraints_f
 
boost::phoenix::function< validate_definitionvalidate_definition_f
 
boost::phoenix::function< validate_identifiervalidate_identifier_f
 
boost::phoenix::function< copy_square_cholesky_dimension_if_necessarycopy_square_cholesky_dimension_if_necessary_f
 
boost::phoenix::function< empty_rangeempty_range_f
 
boost::phoenix::function< validate_int_exprvalidate_int_expr_f
 
boost::phoenix::function< validate_int_expr_no_error_msgsvalidate_int_expr_no_error_msgs_f
 
boost::phoenix::function< set_int_range_lowerset_int_range_lower_f
 
boost::phoenix::function< set_int_range_upperset_int_range_upper_f
 
boost::phoenix::function< validate_int_data_exprvalidate_int_data_expr_f
 
boost::phoenix::function< validate_double_exprvalidate_double_expr_f
 
boost::phoenix::function< set_double_range_lowerset_double_range_lower_f
 
boost::phoenix::function< set_double_range_upperset_double_range_upper_f
 
boost::phoenix::function< add_varadd_var_f
 
boost::phoenix::function< validate_in_loopvalidate_in_loop_f
 
boost::phoenix::function< non_void_expressionnon_void_expression_f
 
boost::phoenix::function< set_var_scopeset_var_scope_f
 
boost::phoenix::function< set_data_originset_data_origin_f
 
boost::phoenix::function< set_var_scope_localset_var_scope_local_f
 
boost::phoenix::function< reset_var_scopereset_var_scope_f
 
boost::phoenix::function< tracetrace_f
 
boost::phoenix::function< deprecate_pound_commentdeprecate_pound_comment_f
 

Typedef Documentation

The type of a function signature, mapping a vector of argument expression types to a result expression type.

Definition at line 17 of file function_signature_t.hpp.

typedef std::string::const_iterator stan::lang::input_iterator_t

Definition at line 10 of file iterator_typedefs.hpp.

The type of a variable indicating where a variable was declared. This is a typedef rather than an enum to get around forward declaration issues with enums in header files.

Definition at line 11 of file origin_block.hpp.

typedef boost::spirit::line_pos_iterator<input_iterator_t> stan::lang::pos_iterator_t

Definition at line 11 of file iterator_typedefs.hpp.

Function Documentation

bool stan::lang::can_assign_to_lhs_var ( const std::string &  lhs_var_name,
const scope var_scope,
const variable_map vm,
std::ostream &  error_msgs 
)

Definition at line 148 of file semantic_actions_def.cpp.

References allTimeWatchdog::endl, stan::lang::variable_map::exists(), stan::lang::scope::fun(), stan::lang::variable_map::get_scope(), stan::lang::scope::is_local(), loop_identifier_origin, print_scope(), and stan::lang::scope::program_block().

Referenced by stan::lang::validate_lhs_var_assgn::operator()().

151  {
152  if (lhs_var_name == std::string("lp__")) {
153  error_msgs << std::endl
154  << "Error (fatal): Use of lp__ is no longer supported."
155  << std::endl
156  << " Use target += ... statement to increment log density."
157  << std::endl;
158  return false;
159  }
160  if (!vm.exists(lhs_var_name)) {
161  error_msgs << "Unknown variable in assignment"
162  << "; lhs variable=" << lhs_var_name
163  << std::endl;
164  return false;
165  }
166  scope lhs_origin = vm.get_scope(lhs_var_name);
167  // enforce constancy of loop variables
168  if (lhs_origin.program_block() == loop_identifier_origin) {
169  error_msgs << "Loop variable " << lhs_var_name
170  << " cannot be used on left side of assignment statement."
171  << std::endl;
172  return false;
173  }
174  // enforce constancy of function args
175  if (!lhs_origin.is_local() && lhs_origin.fun()) {
176  error_msgs << "Cannot assign to function argument variables."
177  << std::endl
178  << "Use local variables instead."
179  << std::endl;
180  return false;
181  }
182  if (lhs_origin.program_block() != var_scope.program_block()) {
183  error_msgs << "Cannot assign to variable outside of declaration block"
184  << "; left-hand-side variable origin=";
185  print_scope(error_msgs, lhs_origin);
186  error_msgs << std::endl;
187  return false;
188  }
189  return true;
190  }
const int loop_identifier_origin
void print_scope(std::ostream &o, const scope &var_scope)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool stan::lang::compile ( std::ostream *  msgs,
std::istream &  in,
std::ostream &  out,
const std::string &  name,
const bool  allow_undefined = false,
const std::string &  filename = "unknown file name",
const std::vector< std::string > &  include_paths = std::vector<std::string>() 
)

Read a Stan model specification from the specified input, parse it, and write the C++ code for it to the specified output, allowing undefined function declarations if the flag is set to true and searching the specified include path for included files.

Parameters
msgsOutput stream for warning messages
inStan model specification
outC++ code output stream
nameName of model class
allow_undefinedtrue if permits undefined functions
filenamename of file or other source from which input stream was derived
include_pathsarray of paths to search for included files
Returns
false if code could not be generated due to syntax error in the Stan model; true otherwise.

Definition at line 35 of file compiler.hpp.

References shutoffs::filename, generate_cpp(), stan::io::program_reader::history(), confusionMatrixTree::out, parse(), cacheDefinitionData::prog, stan::io::program_reader::program(), and ss.

Referenced by expect_match(), stanc_helper(), and TEST().

39  {
40  io::program_reader reader(in, filename, include_paths);
41  std::string s = reader.program();
42  std::stringstream ss(s);
43  program prog;
44  bool parse_succeeded = parse(msgs, ss, name, reader, prog,
45  allow_undefined);
46  if (!parse_succeeded)
47  return false;
48  generate_cpp(prog, name, reader.history(), out);
49  return true;
50  }
const XML_Char * name
Definition: expat.h:151
Float_t ss
Definition: plot.C:24
string filename
Definition: shutoffs.py:106
const XML_Char * s
Definition: expat.h:262
void generate_cpp(const program &prog, const std::string &model_name, const std::vector< io::preproc_event > &history, std::ostream &o)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
ifstream in
Definition: comparison.C:7
bool parse(const std::string &hexString, int32_t &decimalValue)
Definition: HexUtils.cpp:96
bool stan::lang::compile_functions ( std::ostream *  msgs,
std::istream &  stan_funcs_in,
std::ostream &  cpp_out,
const std::vector< std::string > &  namespaces,
const bool  allow_undefined = false,
const std::string &  filename = "unknown file name",
const std::vector< std::string > &  include_paths = std::vector<std::string>() 
)

Read a Stan file with only the functions block from the specified input, parse it, and write the C++ code for it to the specified output.

Parameters
[in]msgsOutput stream for warning messages
[in]stan_funcs_inStan model specification
[in]cpp_outC++ code output stream
[in]namespacesVector of namespace to generate the functions in
[in]allow_undefinedPermit undefined functions?
filenamename of file or other source from which input stream was derived
include_pathsarray of paths to search for included files
Returns
false if code could not be generated due to syntax error in the functions file; true otherwise.

Definition at line 31 of file compile_functions.hpp.

References shutoffs::filename, generate_standalone_functions(), stan::io::program_reader::history(), parse(), cacheDefinitionData::prog, stan::io::program_reader::program(), and ss.

Referenced by stanc_helper().

38  {
39  io::program_reader reader(stan_funcs_in, filename, include_paths);
40  std::string s = reader.program();
41  std::stringstream ss(s);
42  program prog;
43 
44  std::string name("functions_only_model");
45 
46  bool parsed_ok = parse(msgs, ss, name, reader, prog, allow_undefined);
47  if (!parsed_ok)
48  return false; // syntax error in program
49 
50  generate_standalone_functions(prog, namespaces,
51  reader.history(), cpp_out);
52  return true;
53  }
const XML_Char * name
Definition: expat.h:151
Float_t ss
Definition: plot.C:24
string filename
Definition: shutoffs.py:106
const XML_Char * s
Definition: expat.h:262
void generate_standalone_functions(const program &prog, const std::vector< std::string > &namespaces, const std::vector< io::preproc_event > &history, std::ostream &o)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool parse(const std::string &hexString, int32_t &decimalValue)
Definition: HexUtils.cpp:96
bool stan::lang::deprecate_fun ( const std::string &  old_name,
const std::string &  new_name,
fun f,
std::ostream &  msgs 
)

Definition at line 97 of file semantic_actions_def.cpp.

References allTimeWatchdog::endl, stan::lang::fun::name_, and stan::lang::fun::original_name_.

Referenced by stan::lang::set_fun_type_named::operator()().

98  {
99  if (f.name_ != old_name) return false;
100  f.original_name_ = f.name_;
101  f.name_ = new_name;
102  msgs << "Warning: Function name '" << old_name << "' is deprecated"
103  << " and will be removed in a later release; please replace"
104  << " with '" << new_name << "'" << std::endl;
105  return true;
106  }
bool stan::lang::deprecate_suffix ( const std::string &  deprecated_suffix,
const std::string &  replacement,
fun f,
std::ostream &  msgs 
)

Definition at line 108 of file semantic_actions_def.cpp.

References allTimeWatchdog::endl, ends_with(), and stan::lang::fun::name_.

Referenced by stan::lang::set_fun_type_named::operator()().

110  {
111  if (!ends_with(deprecated_suffix, f.name_)) return false;
112  msgs << "Warning: Deprecated function '" << f.name_ << "';"
113  << " please replace suffix '" << deprecated_suffix
114  << "' with " << replacement << std::endl;
115  return true;
116  }
bool ends_with(const std::string &suffix, const std::string &s)
void stan::lang::dump_program_line ( size_t  idx_errline,
int  offset,
const std::string &  origin_file,
size_t  origin_line,
const io::program_reader reader,
const std::vector< std::string > &  program_lines,
std::stringstream &  error_msgs 
)

Definition at line 844 of file semantic_actions_def.cpp.

References allTimeWatchdog::endl, novadaq::HexUtils::format(), runNovaSAM::str, and stan::io::program_reader::trace().

Referenced by stan::lang::program_error::operator()().

849  {
850  boost::format fmt_lineno("%6d: ");
851  if (idx_errline + offset > 0
852  && idx_errline + offset < program_lines.size()) {
853  io::program_reader::trace_t trace = reader.trace(idx_errline + offset);
854  if (trace[trace.size() - 1].first == origin_file) {
855  std::string lineno = str(fmt_lineno % (origin_line + offset));
856  error_msgs << lineno << program_lines[idx_errline + offset - 1]
857  << std::endl;
858  }
859  }
860  }
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T trace(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &m)
Definition: trace.hpp:19
const std::vector<expression> stan::lang::EMPTY_EXP_VECTOR ( )
bool stan::lang::ends_with ( const std::string &  suffix,
const std::string &  s 
)

Returns true if the specified suffix appears at the end of the specified string.

Parameters
suffixsuffix to test
sstring in which to search
Returns
true if the string ends with the suffix

Definition at line 10 of file ends_with_def.hpp.

Referenced by deprecate_suffix(), Expression::fetch(), generate_function(), generate_function_functor(), generate_function_instantiation(), stan::lang::function_signatures::get_result_type(), has_ccdf_suffix(), has_cdf_suffix(), has_prob_fun_suffix(), has_prob_suffix(), has_rng_lp_suffix(), stan::lang::set_allows_sampling_origin::operator()(), stan::lang::add_function_signature::operator()(), stan::lang::validate_return_type::operator()(), stan::lang::validate_pmf_pdf_variate::operator()(), stan::lang::validate_sample::operator()(), replace_suffix(), strip_ccdf_suffix(), strip_cdf_suffix(), and strip_prob_fun_suffix().

10  {
11  size_t idx = s.rfind(suffix);
12  return idx != std::string::npos && idx == (s.size() - suffix.size());
13  }
const XML_Char * s
Definition: expat.h:262
const std::string stan::lang::EOL ( "\n"  )

End-of-line marker.

Referenced by stan::lang::validate_var_decl_visgen::basic_validate(), stan::lang::member_var_decl_visgen::declare_array(), stan::lang::local_var_decl_visgen::declare_array(), stan::lang::init_vars_visgen::fill_real(), stan::lang::validate_var_decl_visgen::generate_begin_for_dims(), stan::lang::init_visgen::generate_buffer_loop(), generate_catch_throw_located(), stan::lang::init_visgen::generate_check_double(), stan::lang::init_visgen::generate_check_int(), generate_class_decl(), generate_comment(), generate_constrained_param_names_method(), generate_constructor(), generate_destructor(), stan::lang::write_dims_visgen::generate_dims_array(), stan::lang::init_visgen::generate_dims_loop_fwd(), generate_dims_method(), stan::lang::validate_var_decl_visgen::generate_end_for_dims(), generate_function(), generate_function_arguments(), generate_function_body(), generate_function_functor(), generate_function_inline_return_type(), generate_function_instantiation(), generate_function_instantiation_body(), generate_function_template_parameters(), generate_include(), generate_includes(), stan::lang::set_param_ranges_visgen::generate_increment(), stan::lang::set_param_ranges_visgen::generate_increment_i(), stan::lang::local_var_init_nan_visgen::generate_init(), generate_init_method(), stan::lang::write_array_visgen::generate_initialize_array(), stan::lang::init_local_var_visgen::generate_initialize_array(), generate_initializer(), generate_line_number(), generate_local_var_decls(), generate_log_prob(), generate_member_var_inits(), generate_model_name_method(), stan::lang::write_param_names_visgen::generate_param_names(), stan::lang::constrained_param_names_visgen::generate_param_names_array(), stan::lang::unconstrained_param_names_visgen::generate_param_names_array(), generate_param_names_method(), generate_private_decl(), generate_propto_default_function_body(), generate_public_decl(), generate_set_param_ranges(), generate_standalone_functions(), generate_statement(), generate_try(), generate_typedef(), generate_typedefs(), generate_unconstrained_param_names_method(), generate_using(), generate_using_namespace(), generate_usings(), generate_usings_standalone_functions(), generate_validate_context_size(), generate_validate_positive(), generate_validate_transformed_params(), generate_validate_var_decls(), generate_var_resizing(), generate_void_statement(), generate_write_array_method(), stan::lang::init_visgen::generate_write_loop(), stan::lang::validate_var_decl_visgen::nonbasic_validate(), stan::lang::init_vars_visgen::operator()(), stan::lang::dump_member_var_visgen::operator()(), stan::lang::set_param_ranges_visgen::operator()(), stan::lang::statement_visgen::operator()(), stan::lang::validate_transformed_params_visgen::validate_array(), and stan::lang::write_array_vars_visgen::write_array().

const std::string stan::lang::EOL2 ( "\n\n"  )
bool stan::lang::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 
)

Definition at line 511 of file semantic_actions_def.cpp.

References it.

Referenced by stan::lang::add_function_signature::operator()().

515  {
516  for (std::set<std::pair<std::string,
517  function_signature_t> >::const_iterator it
518  = existing.begin();
519  it != existing.end();
520  ++it) {
521  if (name_sig.first == (*it).first
522  && (name_only
523  || name_sig.second.second == (*it).second.second))
524  return true; // name and arg sequences match
525  }
526  return false;
527  }
set< int >::iterator it
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::pair< expr_type, std::vector< function_arg_type > > function_signature_t
bool stan::lang::fun_name_exists ( const std::string &  name)

Return true if the function name has been declared as a built-in or by the user.

Parameters
namename of function
Returns
true if it has been declared

Definition at line 10 of file fun_name_exists_def.hpp.

References stan::lang::function_signatures::has_key(), and stan::lang::function_signatures::instance().

Referenced by stan::lang::validate_prob_fun::operator()().

10  {
11  return function_signatures::instance().has_key(name);
12  }
const XML_Char * name
Definition: expat.h:151
std::string stan::lang::fun_name_to_operator ( const std::string &  name)

Definition at line 321 of file function_signatures_def.hpp.

Referenced by stan::lang::function_signatures::get_result_type(), and TEST().

321  {
322  // binary infix (pow handled by parser)
323  if (name == "add") return "+";
324  if (name == "subtract") return "-";
325  if (name == "multiply") return "*";
326  if (name == "divide") return "/";
327  if (name == "modulus") return "%";
328  if (name == "mdivide_left") return "\\";
329  if (name == "mdivide_right") return "/";
330  if (name == "elt_multiply") return ".*";
331  if (name == "elt_divide") return "./";
332 
333  // unary prefix (+ handled by parser)
334  if (name == "minus") return "-";
335  if (name == "logical_negation") return "!";
336 
337  // unary suffix
338  if (name == "transpose") return "'";
339 
340  // none of the above
341  return "ERROR";
342  }
const XML_Char * name
Definition: expat.h:151
std::string stan::lang::fun_scalar_type ( const function_decl_def fun,
bool  is_lp 
)

Return the string representing the scalar type to use in the body of the specified function declaration, with a flag indicating if the function is a log probability function.

Parameters
[in]funfunction declaration
[in]is_lptrue if the function is a log probability function
Returns
string representing scalar type to use within the function body

Definition at line 24 of file fun_scalar_type.hpp.

References stan::lang::function_decl_def::arg_decls_, has_only_int_args(), MECModelEnuComparisons::i, and ss.

Referenced by generate_function(), and generate_function_functor().

24  {
25  size_t num_args = fun.arg_decls_.size();
26  // nullary, non-lp
27  if (has_only_int_args(fun) && !is_lp)
28  return "double";
29 
30  // need template metaprogram to construct return
31  std::stringstream ss;
32  ss << "typename boost::math::tools::promote_args<";
33  int num_open_brackets = 1;
34  int num_generated_params = 0;
35  for (size_t i = 0; i < num_args; ++i) {
36  if (!fun.arg_decls_[i].arg_type_.base_type_.is_int_type()) {
37  if (num_generated_params > 0)
38  ss << ", ";
39  // break into blocks of 4 and apply promotion recursively
40  // setting at 4 leaves room for an extra parameter at the end
41  if (num_generated_params == 4) {
42  ss << "typename boost::math::tools::promote_args<";
43  num_generated_params = 0;
44  ++num_open_brackets;
45  }
46  ss << "T" << i << "__";
47  ++num_generated_params;
48  }
49  }
50  if (is_lp) {
51  if (num_generated_params > 0)
52  ss << ", ";
53  ss << "T_lp__";
54  }
55  for (int i = 0; i < num_open_brackets; ++i)
56  ss << ">::type";
57  return ss.str();
58  }
Float_t ss
Definition: plot.C:24
bool has_only_int_args(const function_decl_def &fun)
void stan::lang::generate_arg_decl ( bool  gen_const,
bool  gen_ref,
const arg_decl decl,
const std::string &  scalar_t_name,
std::ostream &  o 
)

Generate the argument declaration for a function with flags indicating whether to generate a const qualifer and whether to make the variable a reference, for the specified declaration and scalar type name from context, writing to the specified stream.

Parameters
[in]gen_consttrue if declaration is for const
[in]gen_reftrue if declaration is for reference
[in]declargument declaration
[in]scalar_t_namestring representing context scalar type
[in,out]ostream for writing

Definition at line 26 of file generate_arg_decl.hpp.

References stan::lang::arg_decl::arg_type_, generate_bare_type(), and stan::lang::arg_decl::name_.

Referenced by generate_function_arguments().

27  {
28  if (gen_const) o << "const ";
29  generate_bare_type(decl.arg_type_, scalar_t_name, o);
30  if (gen_ref) o << "&";
31  o << " " << decl.name_;
32  }
void generate_bare_type(const expr_type &t, const std::string &scalar_t_name, std::ostream &o)
void stan::lang::generate_array_builder_adds ( const std::vector< expression > &  elements,
bool  user_facing,
std::ostream &  o 
)

Recursive helper function for array, matrix, and row_vector expressions which generates chain of calls to math lib array_builder add function for each of the contained elements.

Parameters
[in]elementsvector of expression elements to generate
[in]user_facingtrue if expression might be reported to user
[in,out]ostream for generating

Definition at line 20 of file generate_array_builder_adds.hpp.

References generate_expression(), and MECModelEnuComparisons::i.

Referenced by stan::lang::expression_visgen::operator()(), and TEST().

22  {
23  for (size_t i = 0; i < elements.size(); ++i) {
24  o << ".add(";
25  generate_expression(elements[i], user_facing, o);
26  o << ")";
27  }
28  }
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_array_var_type ( const base_expr_type base_type,
const std::string &  real_var_type,
std::ostream &  o 
)

Generate C++ type for array expressions according to context in which expression appears.

Parameters
[in]base_typeexpression base type
[in]real_var_typecontext-dependent real type
[in,out]ogenerated typename

Definition at line 19 of file generate_array_var_type.hpp.

References stan::lang::base_expr_type::is_double_type(), stan::lang::base_expr_type::is_int_type(), stan::lang::base_expr_type::is_matrix_type(), stan::lang::base_expr_type::is_row_vector_type(), and stan::lang::base_expr_type::is_vector_type().

Referenced by stan::lang::expression_visgen::operator()(), and TEST().

21  {
22  if (base_type.is_int_type())
23  o << "int";
24  else if (base_type.is_double_type())
25  o << real_var_type;
26  else if (base_type.is_vector_type())
27  o << "Eigen::Matrix<" << real_var_type << ",Eigen::Dynamic,1> ";
28  else if (base_type.is_row_vector_type())
29  o << "Eigen::Matrix<" << real_var_type << ",1,Eigen::Dynamic> ";
30  else if (base_type.is_matrix_type())
31  o << "Eigen::Matrix<" << real_var_type
32  << ",Eigen::Dynamic,Eigen::Dynamic> ";
33  }
void stan::lang::generate_bare_type ( const expr_type t,
const std::string &  scalar_t_name,
std::ostream &  o 
)

Generate the basic type for the specified expression type without dimensions, using the specified scalar type string, writing to the specified stream.

Parameters
[in]texpression type
[in]scalar_t_namename of scalar type for double values and containers
[in]ostream for generating

Definition at line 22 of file generate_bare_type.hpp.

References stan::lang::expr_type::base_type_, d, stan::lang::base_expr_type::is_double_type(), stan::lang::base_expr_type::is_int_type(), stan::lang::base_expr_type::is_matrix_type(), stan::lang::base_expr_type::is_row_vector_type(), stan::lang::base_expr_type::is_vector_type(), stan::lang::base_expr_type::is_void_type(), and stan::lang::expr_type::num_dims_.

Referenced by generate_arg_decl(), and generate_function_inline_return_type().

24  {
25  for (size_t d = 0; d < t.num_dims_; ++d)
26  o << "std::vector<";
27  bool is_template_type = false;
28  if (t.base_type_.is_int_type()) {
29  o << "int";
30  is_template_type = false;
31  } else if (t.base_type_.is_double_type()) {
32  o << scalar_t_name;
33  is_template_type = false;
34  } else if (t.base_type_.is_vector_type()) {
35  o << "Eigen::Matrix<"
36  << scalar_t_name
37  << ", Eigen::Dynamic,1>";
38  is_template_type = true;
39  } else if (t.base_type_.is_row_vector_type()) {
40  o << "Eigen::Matrix<"
41  << scalar_t_name
42  << ", 1,Eigen::Dynamic>";
43  is_template_type = true;
44  } else if (t.base_type_.is_matrix_type()) {
45  o << "Eigen::Matrix<"
46  << scalar_t_name
47  << ", Eigen::Dynamic,Eigen::Dynamic>";
48  is_template_type = true;
49  } else if (t.base_type_.is_void_type()) {
50  o << "void";
51  } else {
52  o << "UNKNOWN TYPE";
53  }
54  for (size_t d = 0; d < t.num_dims_; ++d) {
55  if (d > 0 || is_template_type)
56  o << " ";
57  o << ">";
58  }
59  }
Float_t d
Definition: plot.C:236
void stan::lang::generate_catch_throw_located ( int  indent,
std::ostream &  o 
)

Generate code to catch and rethrow an exception that includes location information read out of the generated context.

Parameters
[in]indentindentation level
[in,out]ostream for generating.

Definition at line 20 of file generate_catch_throw_located.hpp.

References EOL(), generate_comment(), and generate_indent().

Referenced by generate_constructor(), generate_function_body(), generate_log_prob(), and generate_write_array_method().

20  {
22  o << "} catch (const std::exception& e) {" << EOL;
23  generate_indent(indent + 1, o);
24  o << "stan::lang::rethrow_located(e, current_statement_begin__"
25  << ", prog_reader__());"
26  << EOL;
27  generate_comment("Next line prevents compiler griping about no return",
28  indent + 1, o);
29  generate_indent(indent + 1, o);
30  o << "throw std::runtime_error"
31  << "(\"*** IF YOU SEE THIS, PLEASE REPORT A BUG ***\");" << EOL;
33  o << "}" << EOL;
34  }
void generate_comment(const std::string &msg, int indent, std::ostream &o)
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_class_decl ( const std::string &  model_name,
std::ostream &  o 
)

Generate the specified name for the model class to the specified stream.

Parameters
[in]model_namename of class
[in,out]ostream for generating

Definition at line 19 of file generate_class_decl.hpp.

References EOL().

Referenced by generate_cpp().

20  {
21  o << "class " << model_name << " : public prob_grad {" << EOL;
22  }
const std::string EOL("\n")
void stan::lang::generate_class_decl_end ( std::ostream &  o)

Definition at line 11 of file generate_class_decl_end.hpp.

References EOL2().

Referenced by generate_cpp().

11  {
12  o << "}; // model" << EOL2;
13  }
const std::string EOL2("\n\n")
void stan::lang::generate_comment ( const std::string &  msg,
int  indent,
std::ostream &  o 
)

Generate the specified message as a comment with the specified indentation and an end-of-line.

Parameters
[in]msgtext of comment
[in]indentindentation level
[in,out]ostream for generating

Definition at line 19 of file generate_comment.hpp.

References EOL(), and generate_indent().

Referenced by generate_catch_throw_located(), generate_constructor(), generate_log_prob(), generate_validate_transformed_params(), and generate_write_array_method().

20  {
22  o << "// " << msg << EOL;
23  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_constrained_param_names_method ( const program prog,
std::ostream &  o 
)

Generate the constrained_param_names method for the specified program on the specified stream.

Parameters
[in]progprogram from which to generate
[in,out]ostream for generating

Definition at line 20 of file generate_constrained_param_names_method.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), stan::lang::program::generated_decl_, MECModelEnuComparisons::i, INDENT(), INDENT2(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

21  {
22  o << EOL << INDENT
23  << "void constrained_param_names("
24  << "std::vector<std::string>& param_names__,"
25  << EOL << INDENT
26  << " bool include_tparams__ = true,"
27  << EOL << INDENT
28  << " bool include_gqs__ = true) const {"
29  << EOL << INDENT2
30  << "std::stringstream param_name_stream__;" << EOL;
31  constrained_param_names_visgen vis1(1, o);
32  constrained_param_names_visgen vis2(2, o);
33  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
34  boost::apply_visitor(vis1, prog.parameter_decl_[i].decl_);
35  o << EOL << INDENT2
36  << "if (!include_gqs__ && !include_tparams__) return;" << EOL;
37  o << EOL << INDENT2 << "if (include_tparams__) {" << EOL;
38  for (size_t i = 0; i < prog.derived_decl_.first.size(); ++i)
39  boost::apply_visitor(vis2, prog.derived_decl_.first[i].decl_);
40  o << INDENT2 << "}" << EOL2;
41  o << EOL << INDENT2 << "if (!include_gqs__) return;" << EOL;
42  for (size_t i = 0; i < prog.generated_decl_.first.size(); ++i)
43  boost::apply_visitor(vis1, prog.generated_decl_.first[i].decl_);
44  o << INDENT << "}" << EOL2;
45  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_constructor ( const program prog,
const std::string &  model_name,
std::ostream &  o 
)

Generate the constructors for the specified program with the specified model name to the specified stream.

Parameters
[in]progprogram from which to generate
[in]model_namename of model for class name
[in,out]ostream for generating

Definition at line 31 of file generate_constructor.hpp.

References stan::lang::program::data_decl_, stan::lang::program::derived_data_decl_, EOL(), EOL2(), generate_catch_throw_located(), generate_comment(), generate_member_var_inits(), generate_set_param_ranges(), generate_statements(), generate_try(), generate_validate_var_decls(), generate_var_resizing(), generate_void_statement(), INDENT(), INDENT2(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

32  {
33  // constructor without seed or template parameter
34  o << INDENT << model_name << "(stan::io::var_context& context__," << EOL;
35  o << INDENT << " std::ostream* pstream__ = 0)" << EOL;
36  o << INDENT2 << ": prob_grad(0) {" << EOL;
37  o << INDENT2 << "ctor_body(context__, 0, pstream__);" << EOL;
38  o << INDENT << "}" << EOL2;
39  // constructor with specified seed
40  o << INDENT << model_name << "(stan::io::var_context& context__," << EOL;
41  o << INDENT << " unsigned int random_seed__," << EOL;
42  o << INDENT << " std::ostream* pstream__ = 0)" << EOL;
43  o << INDENT2 << ": prob_grad(0) {" << EOL;
44  o << INDENT2 << "ctor_body(context__, random_seed__, pstream__);" << EOL;
45  o << INDENT << "}" << EOL2;
46  // body of constructor now in function
47  o << INDENT << "void ctor_body(stan::io::var_context& context__," << EOL;
48  o << INDENT << " unsigned int random_seed__," << EOL;
49  o << INDENT << " std::ostream* pstream__) {" << EOL;
50  o << INDENT2 << "typedef double local_scalar_t__;" << EOL2;
51 
52  o << INDENT2 << "boost::ecuyer1988 base_rng__ =" << EOL;
53  o << INDENT2 << " stan::services::util::create_rng(random_seed__, 0);"
54  << EOL;
55  o << INDENT2 << "(void) base_rng__; // suppress unused var warning"
56  << EOL2;
57  o << INDENT2 << "current_statement_begin__ = -1;" << EOL2;
58 
59  o << INDENT2 << "static const char* function__ = \""
60  << model_name << "_namespace::" << model_name << "\";" << EOL;
61  generate_void_statement("function__", 2, o);
62  o << INDENT2 << "size_t pos__;" << EOL;
63  generate_void_statement("pos__", 2, o);
64  o << INDENT2 << "std::vector<int> vals_i__;" << EOL;
65  o << INDENT2 << "std::vector<double> vals_r__;" << EOL;
66  o << INDENT2
67  << "local_scalar_t__ DUMMY_VAR__"
68  << "(std::numeric_limits<double>::quiet_NaN());"
69  << EOL;
70  o << INDENT2 << "(void) DUMMY_VAR__; // suppress unused var warning"
71  << EOL2;
72  o << INDENT2 << "// initialize member variables" << EOL;
73  generate_try(2, o);
74  generate_member_var_inits(prog.data_decl_, 3, o);
75  o << EOL;
76  generate_comment("validate, data variables", 3, o);
77  generate_validate_var_decls(prog.data_decl_, 3, o);
78  generate_comment("initialize data variables", 3, o);
79  generate_var_resizing(prog.derived_data_decl_.first, 3, o);
80  o << EOL;
81  generate_statements(prog.derived_data_decl_.second, 3, o);
82  o << EOL;
83  generate_comment("validate transformed data", 3, o);
84  generate_validate_var_decls(prog.derived_data_decl_.first, 3, o);
85  o << EOL;
86  generate_comment("validate, set parameter ranges", 3, o);
87  generate_set_param_ranges(prog.parameter_decl_, 3, o);
89  o << INDENT << "}" << EOL;
90  }
const std::string EOL2("\n\n")
void generate_comment(const std::string &msg, int indent, std::ostream &o)
void generate_member_var_inits(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void generate_void_statement(const std::string &name, const size_t indent, std::ostream &o)
void generate_statements(const std::vector< statement > statements, int indent, std::ostream &o)
void generate_var_resizing(const std::vector< var_decl > &vs, int indent, std::ostream &o)
const std::string INDENT(" ")
void generate_validate_var_decls(const std::vector< var_decl > decls, int indent, std::ostream &o)
void generate_try(int indent, std::ostream &o)
const std::string EOL("\n")
void generate_set_param_ranges(const std::vector< var_decl > &var_decls, int indent, std::ostream &o)
void generate_catch_throw_located(int indent, std::ostream &o)
const std::string INDENT2(" ")
void stan::lang::generate_cpp ( const program prog,
const std::string &  model_name,
const std::vector< io::preproc_event > &  history,
std::ostream &  o 
)

Generae the C++ code for the specified program, generating it in a class and namespace derived from the specified model name, writing to the specified stream.

Parameters
[in]progprogram from which to generate
[in]model_namename of model for generating namespace and class name
[in]historyI/O include history for text underlying program
[in,out]ostream for generating

Definition at line 51 of file generate_cpp.hpp.

References stan::lang::program::function_decl_defs_, generate_class_decl(), generate_class_decl_end(), generate_constrained_param_names_method(), generate_constructor(), generate_destructor(), generate_dims_method(), generate_functions(), generate_globals(), generate_includes(), generate_init_method(), generate_log_prob(), generate_member_var_decls_all(), generate_model_name_method(), generate_model_typedef(), generate_namespace_end(), generate_namespace_start(), generate_param_names_method(), generate_private_decl(), generate_program_reader_fun(), generate_public_decl(), generate_register_mpi(), generate_unconstrained_param_names_method(), generate_usings(), generate_version_comment(), generate_write_array_method(), and stan::lang::program::parameter_decl_.

Referenced by compile(), model_to_cpp(), and TEST().

53  {
56  generate_namespace_start(model_name, o);
58  // generate_typedefs(o);
61  generate_functions(prog.function_decl_defs_, o);
62  generate_class_decl(model_name, o);
66  generate_constructor(prog, model_name, o);
67  generate_destructor(model_name, o);
68  // put back if ever need integer params
69  // generate_set_param_ranges(prog.parameter_decl_, o);
70  generate_init_method(prog.parameter_decl_, o);
74  generate_write_array_method(prog, model_name, o);
75  generate_model_name_method(model_name, o);
80  generate_model_typedef(model_name, o);
81  generate_register_mpi(model_name, o);
82  }
void generate_model_typedef(const std::string &model_name, std::ostream &o)
def history()
Definition: g4zmq.py:84
void generate_private_decl(std::ostream &o)
void generate_namespace_end(std::ostream &o)
void generate_class_decl_end(std::ostream &o)
void generate_register_mpi(const std::string &model_name, std::ostream &o)
void generate_unconstrained_param_names_method(const program &prog, std::ostream &o)
void generate_program_reader_fun(const std::vector< io::preproc_event > &history, std::ostream &o)
void generate_model_name_method(const std::string &model_name, std::ostream &o)
void generate_functions(const std::vector< function_decl_def > &funs, std::ostream &o)
void generate_dims_method(const program &prog, std::ostream &o)
void generate_param_names_method(const program &prog, std::ostream &o)
void generate_usings(std::ostream &o)
void generate_log_prob(const program &p, std::ostream &o)
void generate_write_array_method(const program &prog, const std::string &model_name, std::ostream &o)
void generate_constrained_param_names_method(const program &prog, std::ostream &o)
void generate_namespace_start(const std::string &name, std::ostream &o)
void generate_version_comment(std::ostream &o)
void generate_constructor(const program &prog, const std::string &model_name, std::ostream &o)
void generate_init_method(const std::vector< var_decl > &vs, std::ostream &o)
void generate_includes(std::ostream &o)
void generate_globals(std::ostream &o)
void generate_destructor(const std::string &model_name, std::ostream &o)
void generate_public_decl(std::ostream &o)
void generate_member_var_decls_all(const program &prog, std::ostream &o)
void generate_class_decl(const std::string &model_name, std::ostream &o)
void stan::lang::generate_destructor ( const std::string &  model_name,
std::ostream &  o 
)

Generate the destructor for the class with name specified by the model name to the specified stream.

Parameters
[in]model_namename of model to use as class name
[in,out]ostream for generating.

Definition at line 19 of file generate_destructor.hpp.

References EOL(), EOL2(), and INDENT().

Referenced by generate_cpp().

19  {
20  o << EOL << INDENT << "~" << model_name << "() { }" << EOL2;
21  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
void stan::lang::generate_dims_method ( const program prog,
std::ostream &  o 
)

Generate the get_dims method for the parameters, transformed parameters, and generated quantities, using the specified program and generating to the specified stream.

Parameters
[in]progprogram from which to generate
[in,out]ostream for generating

Definition at line 21 of file generate_dims_method.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), stan::lang::program::generated_decl_, MECModelEnuComparisons::i, INDENT(), INDENT2(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

21  {
22  write_dims_visgen vis(o);
23  o << EOL << INDENT
24  << "void get_dims(std::vector<std::vector<size_t> >& dimss__) const {"
25  << EOL;
26  o << INDENT2 << "dimss__.resize(0);" << EOL;
27  o << INDENT2 << "std::vector<size_t> dims__;" << EOL;
28  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
29  boost::apply_visitor(vis, prog.parameter_decl_[i].decl_);
30  for (size_t i = 0; i < prog.derived_decl_.first.size(); ++i)
31  boost::apply_visitor(vis, prog.derived_decl_.first[i].decl_);
32  for (size_t i = 0; i < prog.generated_decl_.first.size(); ++i)
33  boost::apply_visitor(vis, prog.generated_decl_.first[i].decl_);
34  o << INDENT << "}" << EOL2;
35  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_eigen_index_expression ( const expression e,
std::ostream &  o 
)

Generate the specified expression cast to an Eigen index to disambiguate from pointer.

Parameters
[in]eexpression for size
[in,out]ostream for generating

Definition at line 19 of file generate_eigen_index_expression.hpp.

References stan::lang::expression::expr_, generate_expression(), and NOT_USER_FACING().

Referenced by stan::lang::local_var_decl_visgen::generate_init_args(), and generate_initializer().

19  {
20  o << "static_cast<Eigen::VectorXd::Index>(";
22  o << ")";
23  }
const bool NOT_USER_FACING(false)
Float_t e
Definition: plot.C:35
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_expression ( const expression e,
bool  user_facing,
std::ostream &  o 
)

Write the code generated by the specified expression to the specified output stream, putting it in a user-readable format if the user-facing flag is true. This is just the header for a forward declaration defined in the generator.

Parameters
[in]eexpression to write
[in]user_facingtrue if expression should be written so that a user can understand it
[in,out]ostream to which expression is written

Generate the specified expression to the specified stream with user-facing/C++ format and parameter/data format controlled by the flags.

Parameters
[in]eexpression to generate
[in]user_facingtrue if expression might be reported to user
[in,out]ostream for generating

Definition at line 21 of file generate_expression.hpp.

References stan::lang::expression::expr_.

Referenced by stan::lang::validate_var_decl_visgen::basic_validate(), stan::lang::init_visgen::function_args(), generate_array_builder_adds(), stan::lang::validate_var_decl_visgen::generate_begin_for_dims(), stan::lang::init_visgen::generate_buffer_loop(), stan::lang::write_dims_visgen::generate_dims_array(), stan::lang::init_visgen::generate_dims_loop_fwd(), generate_eigen_index_expression(), stan::lang::set_param_ranges_visgen::generate_increment(), stan::lang::set_param_ranges_visgen::generate_increment_i(), generate_indexed_expr(), generate_indexed_expr_user(), stan::lang::local_var_decl_visgen::generate_init_args(), stan::lang::write_array_visgen::generate_initialize_array(), stan::lang::init_local_var_visgen::generate_initialize_array(), generate_initializer(), generate_local_var_decls(), stan::lang::constrained_param_names_visgen::generate_param_names_array(), stan::lang::unconstrained_param_names_visgen::generate_param_names_array(), generate_quoted_expression(), stan::lang::statement_visgen::generate_truncation(), generate_validate_context_size(), generate_validate_positive(), generate_var_resizing(), stan::lang::idx_visgen::operator()(), stan::lang::idx_user_visgen::operator()(), stan::lang::printable_visgen::operator()(), stan::lang::dump_member_var_visgen::operator()(), stan::lang::expression_visgen::operator()(), stan::lang::set_param_ranges_visgen::operator()(), stan::lang::statement_visgen::operator()(), stan::lang::validate_sample::operator()(), stan::lang::expression_as_statement::operator()(), stan::lang::division_expr::operator()(), stan::lang::validate_transformed_params_visgen::validate_array(), and stan::lang::write_array_vars_visgen::write_array().

22  {
23  expression_visgen vis(o, user_facing);
24  boost::apply_visitor(vis, e.expr_);
25  }
Float_t e
Definition: plot.C:35
void stan::lang::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 _log.

Exact behavior differs for unmarked functions, and functions ending in one of "_rng", "_lp", or "_log".

Parameters
[in]funfunction AST object
[in,out]outoutput stream to which function definition is written

Definition at line 30 of file generate_function.hpp.

References stan::lang::function_decl_def::body_, ends_with(), EOL(), fun_scalar_type(), generate_function_arguments(), generate_function_body(), generate_function_inline_return_type(), generate_function_name(), generate_function_template_parameters(), generate_propto_default_function(), stan::lang::statement::is_no_op_statement(), and stan::lang::function_decl_def::name_.

Referenced by generate_functions().

31  {
32  bool is_rng = ends_with("_rng", fun.name_);
33  bool is_lp = ends_with("_lp", fun.name_);
34  bool is_pf = ends_with("_log", fun.name_)
35  || ends_with("_lpdf", fun.name_) || ends_with("_lpmf", fun.name_);
36  std::string scalar_t_name = fun_scalar_type(fun, is_lp);
37 
38  generate_function_template_parameters(fun, is_rng, is_lp, is_pf, out);
39  generate_function_inline_return_type(fun, scalar_t_name, 0, out);
41  generate_function_arguments(fun, is_rng, is_lp, is_pf, out);
42  generate_function_body(fun, scalar_t_name, out);
43 
44  // need a second function def for default propto=false for _log
45  // funs; but don't want duplicate def, so don't do it for
46  // forward decl when body is no-op
47  if (is_pf && !fun.body_.is_no_op_statement())
48  generate_propto_default_function(fun, scalar_t_name, out);
49  out << EOL;
50  }
void generate_function_name(const function_decl_def &fun, std::ostream &o)
std::string fun_scalar_type(const function_decl_def &fun, bool is_lp)
bool ends_with(const std::string &suffix, const std::string &s)
void generate_function_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o, bool double_only=false, std::string rng_type="RNG", bool parameter_defaults=false)
void generate_function_body(const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &o)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const std::string EOL("\n")
void generate_propto_default_function(const function_decl_def &fun, const std::string &scalar_t_name, std::ostream &o)
void generate_function_inline_return_type(const function_decl_def &fun, const std::string &scalar_t_name, int indent, std::ostream &out)
void generate_function_template_parameters(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
void stan::lang::generate_function_arguments ( const function_decl_def fun,
bool  is_rng,
bool  is_lp,
bool  is_log,
std::ostream &  o,
bool  double_only = false,
std::string  rng_type = "RNG",
bool  parameter_defaults = false 
)

Generate the arguments for the specified function, with precalculated flags for whether it is an RNG, uses the log density accumulator or is a probability function, to the specified stream.

Parameters
[in]funfunction declaration
[in]is_rngtrue if function is an RNG
[in]is_lptrue if function accesses log density accumulator
[in]is_logtrue if function is log probability function
[in,out]ostream for generating
[in]double_onlydo not do any templating and make all arguments based on the standard double type
[in]rng_typeset a type of the rng argument in _rng functions
[in]parameter_defaultsif true, default values for the standard parameters (now only pstream__) will be generated

Definition at line 33 of file generate_function_arguments.hpp.

References stan::lang::function_decl_def::arg_decls_, EOL(), generate_arg_decl(), MECModelEnuComparisons::i, INDENT(), and stan::lang::function_decl_def::name_.

Referenced by generate_function(), generate_function_functor(), generate_function_instantiation(), and generate_propto_default_function().

37  {
38  o << "(";
39  for (size_t i = 0; i < fun.arg_decls_.size(); ++i) {
40  std::string template_type_i;
41  if (double_only) {
42  template_type_i = "double";
43  } else {
44  template_type_i = "T" + boost::lexical_cast<std::string>(i) + "__";
45  }
46  generate_arg_decl(true, true, fun.arg_decls_[i], template_type_i, o);
47  if (i + 1 < fun.arg_decls_.size()) {
48  o << "," << EOL << INDENT;
49  for (size_t i = 0; i <= fun.name_.size(); ++i)
50  o << " ";
51  }
52  }
53  if ((is_rng || is_lp) && fun.arg_decls_.size() > 0)
54  o << ", ";
55  if (is_rng) {
56  o << rng_type << "& base_rng__";
57  } else if (is_lp) {
58  if (double_only) {
59  o << "double& lp__, stan::math::accumulator<double>& lp_accum__";
60  } else {
61  o << "T_lp__& lp__, T_lp_accum__& lp_accum__";
62  }
63  }
64  if (is_rng || is_lp || fun.arg_decls_.size() > 0)
65  o << ", ";
66 
67  o << "std::ostream* pstream__";
68  if (parameter_defaults) {
69  o << " = nullptr";
70  }
71 
72  o << ")";
73  }
const std::string INDENT(" ")
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const std::string EOL("\n")
void generate_arg_decl(bool gen_const, bool gen_ref, const arg_decl &decl, const std::string &scalar_t_name, std::ostream &o)
void stan::lang::generate_function_body ( const function_decl_def fun,
const std::string &  scalar_t_name,
std::ostream &  o 
)

Generate the body of the specified function, with the specified local scalar type, writing to the specified stream.

Parameters
[in]funfunction declaration
[in]scalar_t_namename of type to use for scalars in the function body
[in,out]ostream for generating

Definition at line 24 of file generate_function_body.hpp.

References stan::lang::expr_type::base_type_, stan::lang::function_decl_def::body_, EOL(), EOL2(), generate_catch_throw_located(), generate_statement(), generate_try(), INDENT(), INDENT2(), stan::lang::base_expr_type::is_int_type(), stan::lang::statement::is_no_op_statement(), and stan::lang::function_decl_def::return_type_.

Referenced by generate_function().

26  {
27  if (fun.body_.is_no_op_statement()) {
28  o << ";" << EOL;
29  return;
30  }
31  o << " {" << EOL;
32  o << INDENT << "typedef " << scalar_t_name << " local_scalar_t__;" << EOL;
33  o << INDENT << "typedef "
34  << (fun.return_type_.base_type_.is_int_type()
35  ? "int" : "local_scalar_t__")
36  << " fun_return_scalar_t__;" << EOL;
37  o << INDENT
38  << "const static bool propto__ = true;" << EOL
39  << INDENT << "(void) propto__;" << EOL;
40  // use this dummy for inits
41  o << INDENT2 << "local_scalar_t__ "
42  << "DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" << EOL;
43  o << INDENT2 << "(void) DUMMY_VAR__; // suppress unused var warning"
44  << EOL2;
45 
46  o << INDENT << "int current_statement_begin__ = -1;" << EOL;
47  generate_try(1, o);
48  generate_statement(fun.body_, 2, o);
50  o << "}" << EOL;
51  }
const std::string EOL2("\n\n")
void generate_statement(const statement &s, int indent, std::ostream &o)
const std::string INDENT(" ")
void generate_try(int indent, std::ostream &o)
const std::string EOL("\n")
void generate_catch_throw_located(int indent, std::ostream &o)
const std::string INDENT2(" ")
void stan::lang::generate_function_functor ( const function_decl_def fun,
std::ostream &  o 
)

Generate the functor to accompnay a function with the specified declaration, writing to the specified stream.

Parameters
[in]funfunction declaration
[in,out]ostream for generating

Definition at line 25 of file generate_function_functor.hpp.

References stan::lang::function_decl_def::body_, ends_with(), EOL(), EOL2(), fun_scalar_type(), generate_function_arguments(), generate_function_inline_return_type(), generate_function_name(), generate_function_template_parameters(), generate_functor_arguments(), INDENT(), INDENT2(), stan::lang::statement::is_no_op_statement(), and stan::lang::function_decl_def::name_.

Referenced by generate_functions().

26  {
27  if (fun.body_.is_no_op_statement())
28  return; // forward declaration, so no functor needed
29 
30  bool is_rng = ends_with("_rng", fun.name_);
31  bool is_lp = ends_with("_lp", fun.name_);
32  bool is_pf = ends_with("_log", fun.name_)
33  || ends_with("_lpdf", fun.name_) || ends_with("_lpmf", fun.name_);
34  std::string scalar_t_name = fun_scalar_type(fun, is_lp);
35 
36  o << EOL << "struct ";
38  o << "_functor__ {" << EOL;
39 
40  o << INDENT;
41  generate_function_template_parameters(fun, is_rng, is_lp, is_pf, o);
42 
43  o << INDENT;
44  generate_function_inline_return_type(fun, scalar_t_name, 1, o);
45 
46  o << INDENT << "operator()";
47  generate_function_arguments(fun, is_rng, is_lp, is_pf, o);
48  o << " const {" << EOL;
49 
50  o << INDENT2 << "return ";
52  generate_functor_arguments(fun, is_rng, is_lp, is_pf, o);
53  o << ";" << EOL;
54  o << INDENT << "}" << EOL;
55  o << "};" << EOL2;
56  }
const std::string EOL2("\n\n")
void generate_function_name(const function_decl_def &fun, std::ostream &o)
std::string fun_scalar_type(const function_decl_def &fun, bool is_lp)
const std::string INDENT(" ")
void generate_functor_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o)
bool ends_with(const std::string &suffix, const std::string &s)
void generate_function_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o, bool double_only=false, std::string rng_type="RNG", bool parameter_defaults=false)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const std::string EOL("\n")
void generate_function_inline_return_type(const function_decl_def &fun, const std::string &scalar_t_name, int indent, std::ostream &out)
const std::string INDENT2(" ")
void generate_function_template_parameters(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
void stan::lang::generate_function_inline_return_type ( const function_decl_def fun,
const std::string &  scalar_t_name,
int  indent,
std::ostream &  out 
)

Generate the return type for the specified function declaration in the context of the specified scalar type at the specified indentation level on the specified stream.

Parameters
[in]funfunction declaration
[in]scalar_t_namestring version of scalar type in context
[in]indentindentation level
[in,out]outstream for generating

Definition at line 25 of file generate_function_inline_return_type.hpp.

References EOL(), generate_bare_type(), generate_indent(), and stan::lang::function_decl_def::return_type_.

Referenced by generate_function(), generate_function_functor(), generate_function_instantiation(), and generate_propto_default_function().

28  {
30  generate_bare_type(fun.return_type_, scalar_t_name, out);
31  out << EOL;
32  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
void generate_bare_type(const expr_type &t, const std::string &scalar_t_name, std::ostream &o)
const std::string EOL("\n")
void stan::lang::generate_function_instantiation ( const function_decl_def fun,
const std::vector< std::string > &  namespaces,
std::ostream &  out 
)

Generate a non-variable (double only) instantiation of specified function and optionally its default for propto=false for functions ending in _log.

Exact behavior differs for unmarked functions, and functions ending in one of "_rng", "_lp", or "_log".

Parameters
[in]funfunction AST object
[in]namespacesvector of strings used to generate the namespaces generated code is nested in.
[in,out]outoutput stream to which function definition is written

Definition at line 31 of file generate_function_instantiation.hpp.

References stan::lang::function_decl_def::body_, ends_with(), EOL(), generate_function_arguments(), generate_function_inline_return_type(), generate_function_instantiation_body(), generate_function_instantiation_name(), stan::lang::statement::is_no_op_statement(), and stan::lang::function_decl_def::name_.

Referenced by generate_function_instantiations().

33  {
34  // Do not generate anything for forward decalrations
35  if (fun.body_.is_no_op_statement()) {
36  return;
37  }
38 
39  bool is_rng = ends_with("_rng", fun.name_);
40  bool is_lp = ends_with("_lp", fun.name_);
41  bool is_pf = ends_with("_log", fun.name_)
42  || ends_with("_lpdf", fun.name_) || ends_with("_lpmf", fun.name_);
43 
44  // scalar type is always double for instantiations
45  std::string scalar_t_name = "double";
46  std::string rng_class = "boost::ecuyer1988";
47 
48  out << "// [[stan::function]]" << EOL;
49  generate_function_inline_return_type(fun, scalar_t_name, 0, out);
52  fun, is_rng, is_lp, is_pf, out, true /*no templates*/, rng_class,
53  true /*parameter_defaults*/);
54 
56  fun, namespaces, is_rng, is_lp, is_pf, rng_class, out);
57 
58  out << EOL;
59  }
void generate_function_instantiation_name(const function_decl_def &fun, std::ostream &out)
bool ends_with(const std::string &suffix, const std::string &s)
void generate_function_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o, bool double_only=false, std::string rng_type="RNG", bool parameter_defaults=false)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void generate_function_instantiation_body(const function_decl_def &fun, const std::vector< std::string > &namespaces, bool is_rng, bool is_lp, bool is_log, const std::string &rng_class, std::ostream &o)
const std::string EOL("\n")
void generate_function_inline_return_type(const function_decl_def &fun, const std::string &scalar_t_name, int indent, std::ostream &out)
void stan::lang::generate_function_instantiation_body ( const function_decl_def fun,
const std::vector< std::string > &  namespaces,
bool  is_rng,
bool  is_lp,
bool  is_log,
const std::string &  rng_class,
std::ostream &  o 
)

Generate the body for a function instantiation (e.g., the call to the templated function with all templated arguments based on double). Requires precalculated flags for whether it is an RNG, uses the log density accumulator or is a probability function, to the specified stream.

Parameters
[in]funfunction declaration
[in]namespacesvector of strings used to generate the namespaces generated code is nested in.
[in]is_rngtrue if function is an RNG
[in]is_lptrue if function accesses log density accumulator
[in]is_logtrue if function is log probability function
[in]rng_classclass of the RNG being used (required by xxx_rng functions)
[in,out]ostream for generating

Definition at line 33 of file generate_function_instantiation_body.hpp.

References stan::lang::function_decl_def::arg_decls_, EOL(), generate_function_instantiation_template_parameters(), generate_function_name(), stan::lang::expr_type::is_void(), and stan::lang::function_decl_def::return_type_.

Referenced by generate_function_instantiation().

37  {
38  o << "{" << EOL;
39  o << " ";
40  if (!fun.return_type_.is_void()) {
41  o << "return ";
42  }
43  o << EOL;
44  for (const std::string& namespace_i : namespaces) {
45  o << namespace_i << "::";
46  }
49  fun, is_rng, is_lp, is_log, rng_class, o);
50 
51  o << "(";
52  for (size_t arg_i = 0; arg_i < fun.arg_decls_.size(); ++arg_i) {
53  o << fun.arg_decls_[arg_i].name_;
54  if (arg_i + 1 < fun.arg_decls_.size()) {
55  o << ", ";
56  }
57  }
58  if ((is_rng || is_lp) && fun.arg_decls_.size() > 0)
59  o << ", ";
60  if (is_rng)
61  o << "base_rng__";
62  else if (is_lp)
63  o << "lp__, lp_accum__";
64  if (is_rng || is_lp || fun.arg_decls_.size() > 0)
65  o << ", ";
66  o << "pstream__";
67  o << ");" << EOL;
68  o << "}" << EOL;
69  }
void generate_function_name(const function_decl_def &fun, std::ostream &o)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void generate_function_instantiation_template_parameters(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, const std::string &rng_class, std::ostream &out)
const std::string EOL("\n")
void stan::lang::generate_function_instantiation_name ( const function_decl_def fun,
std::ostream &  out 
)

Generate a name for a non-variable (double only) instantiation of specified function

Parameters
[in]funfunction AST object
[in,out]outoutput stream to which function definition is written

Definition at line 19 of file generate_function_instantiation_name.hpp.

References stan::lang::function_decl_def::name_.

Referenced by generate_function_instantiation().

20  {
21  out << fun.name_;
22  }
void stan::lang::generate_function_instantiation_template_parameters ( const function_decl_def fun,
bool  is_rng,
bool  is_lp,
bool  is_log,
const std::string &  rng_class,
std::ostream &  out 
)

Generate the concrete template parameters for function instantiation.

Parameters
[in]funfunction declaration
[in]is_rngtrue if function is a random number generator
[in]is_lptrue if function accesses log density accumulator
[in]is_logtrue if function is a probability function
[in]rng_classclass of the RNG being used (required by xxx_rng functions)
[in]outstream for generating

Definition at line 27 of file generate_fun_inst_templ_params.hpp.

References stan::lang::function_decl_def::arg_decls_, and MECModelEnuComparisons::i.

Referenced by generate_function_instantiation_body().

32  {
33  std::vector<std::string> type_params;
34  type_params.reserve(fun.arg_decls_.size());
35 
36  if (is_log) {
37  std::string propto_value = "false";
38  type_params.push_back(propto_value);
39  }
40 
41  for (size_t i = 0; i < fun.arg_decls_.size(); ++i) {
42  // no template parameter for int-based args
43  if (!fun.arg_decls_[i].arg_type_.base_type_.is_int_type()) {
44  type_params.push_back("double");
45  }
46  }
47  if (is_rng) {
48  type_params.push_back(rng_class);
49  } else if (is_lp) {
50  type_params.push_back("double");
51  // the trailing space after '>' is necessary to compile
52  type_params.push_back("stan::math::accumulator<double> ");
53  }
54 
55  if (!type_params.empty()) {
56  out << "<";
57  for (size_t param_i = 0; param_i < type_params.size(); ++param_i) {
58  if (param_i > 0)
59  out << ", ";
60  out << type_params[param_i];
61  }
62  out << ">";
63  }
64  }
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void stan::lang::generate_function_instantiations ( const std::vector< function_decl_def > &  funs,
const std::vector< std::string > &  namespaces,
std::ostream &  o 
)

Generate instantiations of templated functions with non-variable parametersfor standalone generation of functions.

Parameters
[in]funssequence of function declarations and definitions
[in]namespacesvector of strings used to generate the namespaces generated code is nested in.
[in,out]ostream for generating

Definition at line 23 of file generate_function_instantiations.hpp.

References generate_function_instantiation(), and MECModelEnuComparisons::i.

Referenced by generate_standalone_functions().

26  {
27  for (size_t i = 0; i < funs.size(); ++i) {
28  generate_function_instantiation(funs[i], namespaces, o);
29  }
30  }
void generate_function_instantiation(const function_decl_def &fun, const std::vector< std::string > &namespaces, std::ostream &out)
void stan::lang::generate_function_name ( const function_decl_def fun,
std::ostream &  o 
)

Generate the function name from the specified declaration on the specified stream.

Parameters
[in]funfunction declaration
[in,out]ostream for generating

Definition at line 17 of file generate_function_name.hpp.

References stan::lang::function_decl_def::name_.

Referenced by generate_function(), generate_function_functor(), generate_function_instantiation_body(), and generate_propto_default_function().

18  {
19  o << fun.name_;
20  }
void stan::lang::generate_function_template_parameters ( const function_decl_def fun,
bool  is_rng,
bool  is_lp,
bool  is_log,
std::ostream &  out 
)

Generate the template declaration for functions.

Parameters
[in]funfunction declaration
[in]is_rngtrue if function is a random number generator
[in]is_lptrue if function accesses log density accumulator
[in]is_logtrue if function is a probability function
[in]outstream for generating

Definition at line 22 of file generate_function_template_parameters.hpp.

References stan::lang::function_decl_def::arg_decls_, EOL(), has_only_int_args(), and MECModelEnuComparisons::i.

Referenced by generate_function(), generate_function_functor(), and generate_propto_default_function().

24  {
25  if (!has_only_int_args(fun)) { // other cases handled below
26  out << "template <";
27  bool continuing_tps = false;
28  if (is_log) {
29  out << "bool propto";
30  continuing_tps = true;
31  }
32  for (size_t i = 0; i < fun.arg_decls_.size(); ++i) {
33  // no template parameter for int-based args
34  if (!fun.arg_decls_[i].arg_type_.base_type_.is_int_type()) {
35  if (continuing_tps)
36  out << ", ";
37  out << "typename T" << i << "__";
38  continuing_tps = true;
39  }
40  }
41  if (is_rng) {
42  if (continuing_tps)
43  out << ", ";
44  out << "class RNG";
45  continuing_tps = true;
46  } else if (is_lp) {
47  if (continuing_tps)
48  out << ", ";
49  out << "typename T_lp__, typename T_lp_accum__";
50  continuing_tps = true;
51  }
52  out << ">" << EOL;
53  } else { // no-arg function
54  if (is_rng) {
55  // nullary RNG case
56  out << "template <class RNG>" << EOL;
57  } else if (is_lp) {
58  out << "template <typename T_lp__, typename T_lp_accum__>"
59  << EOL;
60  } else if (is_log) {
61  out << "template <bool propto>"
62  << EOL;
63  }
64  }
65  }
bool has_only_int_args(const function_decl_def &fun)
const std::string EOL("\n")
void stan::lang::generate_functions ( const std::vector< function_decl_def > &  funs,
std::ostream &  o 
)

Generate function forward declarations, definitions, and functors for the the specified sequence of function declarations and definitions, writing to the specified stream.

Parameters
[in]funssequence of function declarations and definitions
[in,out]ostream for generating are generated (for non-templated functions only)

Definition at line 23 of file generate_functions.hpp.

References generate_function(), generate_function_functor(), and MECModelEnuComparisons::i.

Referenced by generate_cpp(), and generate_standalone_functions().

24  {
25  for (size_t i = 0; i < funs.size(); ++i) {
26  generate_function(funs[i], o);
28  }
29  }
void generate_function(const function_decl_def &fun, std::ostream &out)
void generate_function_functor(const function_decl_def &fun, std::ostream &o)
void stan::lang::generate_functor_arguments ( const function_decl_def fun,
bool  is_rng,
bool  is_lp,
bool  is_log,
std::ostream &  o 
)

Generate the arguments for the functor for the specified function declaration, with flags indicating whether it is a random number generator, accesses the log density accumulator, or is a probability function, writing to the specified stream.

Parameters
[in]funfunction declaration
[in]is_rngtrue if function is a random number generator
[in]is_lptrue if function acceses log density accumulator
[in]is_logtrue if function is log probability function
[in,out]ostream for generating

Definition at line 23 of file generate_functor_arguments.hpp.

References stan::lang::function_decl_def::arg_decls_, and MECModelEnuComparisons::i.

Referenced by generate_function_functor().

24  {
25  o << "(";
26  for (size_t i = 0; i < fun.arg_decls_.size(); ++i) {
27  if (i > 0)
28  o << ", ";
29  o << fun.arg_decls_[i].name_;
30  }
31  if ((is_rng || is_lp) && fun.arg_decls_.size() > 0)
32  o << ", ";
33  if (is_rng)
34  o << "base_rng__";
35  else if (is_lp)
36  o << "lp__, lp_accum__";
37  if (is_rng || is_lp || fun.arg_decls_.size() > 0)
38  o << ", ";
39  o << "pstream__";
40  o << ")";
41  }
void stan::lang::generate_globals ( std::ostream &  o)

Generate the global variables to the specified stream.

Parameters
[in]ostream for generating

Definition at line 15 of file generate_globals.hpp.

References EOL2().

Referenced by generate_cpp().

15  {
16  o << "static int current_statement_begin__;" << EOL2;
17  }
const std::string EOL2("\n\n")
void stan::lang::generate_idx ( const idx i,
std::ostream &  o 
)

Generate the specified multiple index on the specified stream.

Parameters
[in]imultiple index to generate
[in,out]ostream for generating

Definition at line 18 of file generate_idx.hpp.

References stan::lang::idx::idx_.

Referenced by generate_idxs().

18  {
19  idx_visgen vis(o);
20  boost::apply_visitor(vis, i.idx_);
21  }
void stan::lang::generate_idx_user ( const idx i,
std::ostream &  o 
)

Generate the specified multiple index for users to the specified stream.

Parameters
[in]imultiple index
[in,out]ostream for writing

Generate specified multiple index for user on specified stream.

Parameters
[in]imultiple index
[in,out]ostream for generating

Definition at line 19 of file geneate_idx_user.hpp.

References stan::lang::idx::idx_.

Referenced by generate_idxs_user().

19  {
20  idx_user_visgen vis(o);
21  boost::apply_visitor(vis, i.idx_);
22  }
void stan::lang::generate_idxs ( size_t  pos,
const std::vector< idx > &  idxs,
std::ostream &  o 
)

Recursive helper function tracking position to generate specified multiple indexes on the specified stream in order to terminate with a nil index properly.

Parameters
[in]posposition in list to generate next
[in]idxsmultiple indexes to generate
[in,out]ostream for generating

Definition at line 21 of file generate_idxs.hpp.

References generate_idx(), and generate_idxs().

22  {
23  if (pos == idxs.size()) {
24  o << "stan::model::nil_index_list()";
25  } else {
26  o << "stan::model::cons_list(";
27  generate_idx(idxs[pos], o);
28  o << ", ";
29  generate_idxs(pos + 1, idxs, o);
30  o << ")";
31  }
32  }
void generate_idxs(size_t pos, const std::vector< idx > &idxs, std::ostream &o)
void generate_idx(const idx &i, std::ostream &o)
void stan::lang::generate_idxs ( const std::vector< idx > &  idxs,
std::ostream &  o 
)

Generate the specified multiple indexes on the specified stream.

Parameters
[in]idxsmultiple indexes to generate
[in,out]ostream for generating

Definition at line 40 of file generate_idxs.hpp.

Referenced by generate_idxs(), stan::lang::expression_visgen::operator()(), stan::lang::statement_visgen::operator()(), and TEST().

40  {
41  generate_idxs(0, idxs, o);
42  }
void generate_idxs(size_t pos, const std::vector< idx > &idxs, std::ostream &o)
void stan::lang::generate_idxs_user ( const std::vector< idx > &  idxs,
std::ostream &  o 
)

Generate the specified multiple indexes for users to the specified stream.

Parameters
[in]idxsmultiple indexes
[in,out]ostream for writing

Definition at line 20 of file generate_idxs_user.hpp.

References generate_idx_user(), and MECModelEnuComparisons::i.

Referenced by stan::lang::expression_visgen::operator()().

20  {
21  if (idxs.size() == 0)
22  return;
23  o << "[";
24  for (size_t i = 0; i < idxs.size(); ++i) {
25  if (i > 0)
26  o << ", ";
27  generate_idx_user(idxs[i], o);
28  }
29  o << "]";
30  }
void generate_idx_user(const idx &i, std::ostream &o)
void stan::lang::generate_include ( const std::string &  lib_name,
std::ostream &  o 
)

Generate an include statement for the specified library path.

Parameters
lib_namepath to library
ostream for generating

Definition at line 18 of file generate_include.hpp.

References EOL().

Referenced by generate_includes(), and generate_standalone_functions().

18  {
19  o << "#include" << " " << "<" << lib_name << ">" << EOL;
20  }
const std::string EOL("\n")
void stan::lang::generate_includes ( std::ostream &  o)

Generate include statements for a Stan model class to the specified stream.

Parameters
ostream for generating

Definition at line 18 of file generate_includes.hpp.

References EOL(), and generate_include().

Referenced by generate_cpp().

18  {
19  generate_include("stan/model/model_header.hpp", o);
20  o << EOL;
21  }
const std::string EOL("\n")
void generate_include(const std::string &lib_name, std::ostream &o)
void stan::lang::generate_indent ( size_t  indent,
std::ostream &  o 
)

Write the specified number of indentations to the specified output stream.

Parameters
indentnumber of indentations
[in,out]ostream to which indentations are written

Definition at line 17 of file generate_indent.hpp.

References art::detail::indent(), and INDENT().

Referenced by stan::lang::validate_var_decl_visgen::basic_validate(), stan::lang::local_var_decl_visgen::declare_array(), stan::lang::init_vars_visgen::fill_real(), stan::lang::validate_var_decl_visgen::generate_begin_for_dims(), stan::lang::init_visgen::generate_buffer_loop(), generate_catch_throw_located(), stan::lang::init_visgen::generate_check_double(), stan::lang::init_visgen::generate_check_int(), generate_comment(), stan::lang::init_visgen::generate_declaration(), stan::lang::init_visgen::generate_dims_loop_fwd(), stan::lang::validate_var_decl_visgen::generate_end_for_dims(), generate_function_inline_return_type(), stan::lang::set_param_ranges_visgen::generate_increment(), stan::lang::set_param_ranges_visgen::generate_increment_i(), stan::lang::init_visgen::generate_indent_num_dims(), stan::lang::local_var_init_nan_visgen::generate_init(), generate_initialization(), stan::lang::write_array_visgen::generate_initialize_array(), stan::lang::init_local_var_visgen::generate_initialize_array(), generate_local_var_decls(), generate_local_var_inits(), generate_member_var_inits(), stan::lang::constrained_param_names_visgen::generate_param_names_array(), stan::lang::unconstrained_param_names_visgen::generate_param_names_array(), generate_set_param_ranges(), generate_statement(), stan::lang::statement_visgen::generate_truncation(), generate_try(), generate_validate_context_size(), generate_validate_positive(), generate_validate_var_decls(), generate_var_resizing(), generate_void_statement(), stan::lang::init_visgen::generate_write_loop(), stan::lang::validate_var_decl_visgen::nonbasic_validate(), stan::lang::init_vars_visgen::operator()(), stan::lang::dump_member_var_visgen::operator()(), stan::lang::set_param_ranges_visgen::operator()(), stan::lang::statement_visgen::operator()(), stan::lang::validate_transformed_params_visgen::validate_array(), and stan::lang::write_array_vars_visgen::write_array().

17  {
18  for (size_t k = 0; k < indent; ++k)
19  o << INDENT;
20  }
const std::string INDENT(" ")
std::string indent(std::size_t const i)
template<bool isLHS>
void stan::lang::generate_indexed_expr ( const std::string &  expr,
const std::vector< expression > &  indexes,
base_expr_type  base_type,
size_t  e_num_dims,
bool  user_facing,
std::ostream &  o 
)

Generate the specified expression indexed with the specified indices with the specified base type of expression being indexed, number of dimensions, and a flag indicating whether the generation is for user output or C++ compilation. Depending on the base type, two layers of parens may be written in the underlying code.

Template Parameters
isLHStrue if indexed expression appears on left-hand side of an assignment
Parameters
[in]exprstring for expression
[in]indexesindexes for expression
[in]base_typebase type of expression
[in]e_num_dimsnumber of array dimensions in expression
[in]user_facingtrue if expression might be reported to user
[in,out]ostream for generating

Definition at line 32 of file generate_indexed_expr.hpp.

References generate_expression(), generate_indexed_expr_user(), generate_quoted_string(), stan::lang::base_expr_type::is_matrix_type(), and getGoodRuns4SAM::n.

35  {
36  if (user_facing) {
37  generate_indexed_expr_user(expr, indexes, o);
38  return;
39  }
40  size_t ai_size = indexes.size();
41  if (ai_size == 0) {
42  o << expr;
43  return;
44  }
45  if (ai_size <= (e_num_dims + 1) || !base_type.is_matrix_type()) {
46  for (size_t n = 0; n < ai_size; ++n)
47  o << (isLHS ? "get_base1_lhs(" : "get_base1(");
48  o << expr;
49  for (size_t n = 0; n < ai_size; ++n) {
50  o << ',';
51  generate_expression(indexes[n], user_facing, o);
52  o << ',';
54  o << ',' << (n + 1) << ')';
55  }
56  } else {
57  for (size_t n = 0; n < ai_size - 1; ++n)
58  o << (isLHS ? "get_base1_lhs(" : "get_base1(");
59  o << expr;
60  for (size_t n = 0; n < ai_size - 2; ++n) {
61  o << ',';
62  generate_expression(indexes[n], user_facing, o);
63  o << ',';
65  o << ',' << (n+1) << ')';
66  }
67  o << ',';
68  generate_expression(indexes[ai_size - 2U], user_facing, o);
69  o << ',';
70  generate_expression(indexes[ai_size - 1U], user_facing, o);
71  o << ',';
72  generate_quoted_string(expr, o);
73  o << ',' << (ai_size - 1U) << ')';
74  }
75  }
void generate_indexed_expr_user(const std::string &expr, const std::vector< expression > indexes, std::ostream &o)
void generate_quoted_string(const std::string &s, std::ostream &o)
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_indexed_expr_user ( const std::string &  expr,
const std::vector< expression indexes,
std::ostream &  o 
)

Generate an expression with indices, writing brackets around indices and commas in between as necessary. If no indices are presents, no brackets will be written.

Parameters
[in]exprexpression for indexing
[in]indexessequence of indexes
[in,out]ostream for writing

Definition at line 24 of file generate_indexed_expr_user.hpp.

References generate_expression(), and MECModelEnuComparisons::i.

Referenced by generate_indexed_expr().

26  {
27  static const bool user_facing = true;
28  o << expr;
29  if (indexes.size() == 0) return;
30  o << '[';
31  for (size_t i = 0; i < indexes.size(); ++i) {
32  if (i > 0) o << ", ";
33  generate_expression(indexes[i], user_facing, o);
34  }
35  o << ']';
36  }
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_init_method ( const std::vector< var_decl > &  vs,
std::ostream &  o 
)

Generate the transform_inits method for the specified variable declarations to the specified stream.

Parameters
[in]vsvariable declarations
[in,out]ostream for generating

Definition at line 22 of file generate_init_method.hpp.

References EOL(), EOL2(), MECModelEnuComparisons::i, INDENT(), and INDENT2().

Referenced by generate_cpp().

23  {
24  o << EOL;
25  o << INDENT
26  << "void transform_inits(const stan::io::var_context& context__,"
27  << EOL;
28  o << INDENT << " std::vector<int>& params_i__,"
29  << EOL;
30  o << INDENT << " std::vector<double>& params_r__,"
31  << EOL;
32  o << INDENT << " std::ostream* pstream__) const {"
33  << EOL;
34  o << INDENT2 << "stan::io::writer<double> "
35  << "writer__(params_r__,params_i__);"
36  << EOL;
37  o << INDENT2 << "size_t pos__;" << EOL;
38  o << INDENT2 << "(void) pos__; // dummy call to supress warning" << EOL;
39  o << INDENT2 << "std::vector<double> vals_r__;" << EOL;
40  o << INDENT2 << "std::vector<int> vals_i__;"
41  << EOL;
42  init_visgen vis(2, o);
43  for (size_t i = 0; i < vs.size(); ++i)
44  boost::apply_visitor(vis, vs[i].decl_);
45 
46  o << EOL
47  << INDENT2 << "params_r__ = writer__.data_r();" << EOL;
48  o << INDENT2 << "params_i__ = writer__.data_i();" << EOL;
49  o << INDENT << "}" << EOL2;
50 
51  o << INDENT
52  << "void transform_inits(const stan::io::var_context& context," << EOL;
53  o << INDENT
54  << " "
55  << "Eigen::Matrix<double,Eigen::Dynamic,1>& params_r," << EOL;
56  o << INDENT
57  << " std::ostream* pstream__) const {" << EOL;
58  o << INDENT << " std::vector<double> params_r_vec;" << EOL;
59  o << INDENT << " std::vector<int> params_i_vec;" << EOL;
60  o << INDENT
61  << " transform_inits(context, params_i_vec, params_r_vec, pstream__);"
62  << EOL;
63  o << INDENT << " params_r.resize(params_r_vec.size());" << EOL;
64  o << INDENT << " for (int i = 0; i < params_r.size(); ++i)" << EOL;
65  o << INDENT << " params_r(i) = params_r_vec[i];" << EOL;
66  o << INDENT << "}" << EOL2;
67  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_initialization ( std::ostream &  o,
size_t  indent,
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() 
)

Generate varaible initialization, checking dimension sizes are all positive, gnerating to the specified stream for a variable with the specified name, type, dimension sizes, and optional matrix/vector size declarations.

Parameters
[in,out]ostream for generating
[in]indentindentation level
[in]var_namename of variable being initialized
[in]base_typebase type of variable
[in]dimsdimension sizes
[in]type_arg1optional vector/row-vector size or matrix rows
[in]type_arg2optional size of matrix columns

Definition at line 31 of file generate_initialization.hpp.

References generate_indent(), generate_initializer(), generate_type(), generate_validate_positive(), MECModelEnuComparisons::i, is_nil(), and msf_helper::o.

Referenced by stan::lang::var_resizing_visgen::operator()().

36  {
37  // check array dimensions
38  for (size_t i = 0; i < dims.size(); ++i)
40  // check vector, row_vector, and matrix rows
41  if (!is_nil(type_arg1))
42  generate_validate_positive(var_name, type_arg1, indent, o);
43  // check matrix cols
44  if (!is_nil(type_arg2))
45  generate_validate_positive(var_name, type_arg2, indent, o);
46 
47  // initialize variable
49  o << var_name << " = ";
50  generate_type(base_type, dims, dims.size(), o);
51  generate_initializer(o, base_type, dims, type_arg1, type_arg2);
52  }
void generate_validate_positive(const std::string &var_name, const expression &expr, int indents, std::ostream &o)
bool is_nil(boost::any const &val)
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
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_type(const std::string &base_type, const std::vector< expression > &, size_t end, std::ostream &o)
void stan::lang::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() 
)

Generate an initializer for a variable of the specified base type with the specified dimension sizes with an additional size for vectors and row vectors and two additional sizes for matrices.

Parameters
ostream for generating
base_typebase type of variable
dimssizes of dimensions for variable
type_arg1size of vector or row vector or size of rows for matrix, not used otherwise
type_arg2size of columns for matrix, not used otherwise

Definition at line 28 of file generate_initializer.hpp.

References EOL(), generate_eigen_index_expression(), generate_expression(), generate_type(), MECModelEnuComparisons::i, is_nil(), NOT_USER_FACING(), and msf_helper::o.

Referenced by stan::lang::init_visgen::generate_declaration(), and generate_initialization().

32  {
33  for (size_t i = 0; i < dims.size(); ++i) {
34  o << '(';
36  o << ',';
37  generate_type(base_type, dims, dims.size() - i - 1, o);
38  }
39 
40  o << '(';
41  if (!is_nil(type_arg1)) {
42  generate_eigen_index_expression(type_arg1, o);
43  if (!is_nil(type_arg2)) {
44  o << ',';
45  generate_eigen_index_expression(type_arg2, o);
46  }
47  } else if (!is_nil(type_arg2.expr_)) {
48  generate_eigen_index_expression(type_arg2, o);
49  } else {
50  o << '0';
51  }
52  o << ')';
53 
54  for (size_t i = 0; i < dims.size(); ++i)
55  o << ')';
56  o << ';' << EOL;
57  }
bool is_nil(boost::any const &val)
const bool NOT_USER_FACING(false)
const std::string EOL("\n")
void generate_eigen_index_expression(const expression &e, std::ostream &o)
void generate_type(const std::string &base_type, const std::vector< expression > &, size_t end, std::ostream &o)
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
template<typename T >
void stan::lang::generate_line_number ( const T line,
int  indent,
std::ostream &  o 
)

Definition at line 20 of file generate_line_number.hpp.

References EOL(), art::detail::indent(), and msf_helper::o.

21  {
22  o << "current_statement_begin__ = " << line.begin_line_ << ";" << EOL;
23  }
const std::string EOL("\n")
template void stan::lang::generate_line_number ( const var_decl ,
int  indent,
std::ostream &  o 
)
template void stan::lang::generate_line_number ( const statement ,
int  indent,
std::ostream &  o 
)
void stan::lang::generate_local_var_decls ( const std::vector< var_decl > &  vs,
int  indent,
std::ostream &  o 
)

Generate local variable declarations, including initializations, for the specified declarations, indentation level, writing to the specified stream. Generated code is preceeded by stmt updating global variable current_statement_begin__ to src file line number where variable is declared.

Parameters
[in]vsvariable declarations
[in]indentindentation level
[in,out]ostream for generating

Definition at line 29 of file generate_local_var_decls.hpp.

References EOL(), generate_expression(), generate_indent(), MECModelEnuComparisons::i, and NOT_USER_FACING().

Referenced by generate_log_prob(), generate_write_array_method(), and stan::lang::statement_visgen::operator()().

30  {
31  local_var_decl_visgen vis_decl(indent, o);
32  local_var_init_nan_visgen vis_init(indent, o);
33  init_vars_visgen vis_filler(indent, o);
34  for (size_t i = 0; i < vs.size(); ++i) {
36  o << "current_statement_begin__ = " << vs[i].begin_line_ << ";"
37  << EOL;
38  boost::apply_visitor(vis_decl, vs[i].decl_);
39  boost::apply_visitor(vis_init, vs[i].decl_);
40  boost::apply_visitor(vis_filler, vs[i].decl_);
41  if (vs[i].has_def()) {
43  o << "stan::math::assign("
44  << vs[i].name()
45  << ",";
47  o << ");" << EOL;
48  }
49  }
50  o << EOL;
51  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const bool NOT_USER_FACING(false)
const std::string EOL("\n")
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_local_var_inits ( std::vector< var_decl vs,
bool  declare_vars,
int  indent,
std::ostream &  o 
)

Generate initializations for the specified local variables, with flags indicating whether the generation is in a variable context and whether variables need to be declared, writing to the specified stream.

Parameters
[in]vsvariable declarations
[in]declare_varstrue if variables should be declared
[in]indentindentation level
[in,out]ostream for generating

Definition at line 26 of file generate_local_var_inits.hpp.

References EOL2(), generate_indent(), and MECModelEnuComparisons::i.

Referenced by generate_log_prob().

27  {
29  o << "stan::io::reader<local_scalar_t__> in__(params_r__,params_i__);"
30  << EOL2;
31  init_local_var_visgen vis_init(declare_vars, indent, o);
32  for (size_t i = 0; i < vs.size(); ++i)
33  boost::apply_visitor(vis_init, vs[i].decl_);
34  }
const std::string EOL2("\n\n")
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
void stan::lang::generate_log_prob ( const program p,
std::ostream &  o 
)

Generate the log_prob method for the model class for the specified program on the specified stream.

Parameters
pprogram
ostream for generating

Definition at line 27 of file generate_log_prob.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), generate_catch_throw_located(), generate_comment(), generate_local_var_decls(), generate_local_var_inits(), generate_statement(), generate_statements(), generate_try(), generate_validate_transformed_params(), generate_validate_var_decls(), INDENT(), INDENT2(), INDENT3(), stan::lang::program::parameter_decl_, and stan::lang::program::statement_.

Referenced by generate_cpp().

27  {
28  o << EOL;
29  o << INDENT << "template <bool propto__, bool jacobian__, typename T__>"
30  << EOL;
31  o << INDENT << "T__ log_prob(vector<T__>& params_r__,"
32  << EOL;
33  o << INDENT << " vector<int>& params_i__,"
34  << EOL;
35  o << INDENT << " std::ostream* pstream__ = 0) const {"
36  << EOL2;
37  o << INDENT2 << "typedef T__ local_scalar_t__;" << EOL2;
38 
39  // use this dummy for inits
40  o << INDENT2
41  << "local_scalar_t__ DUMMY_VAR__"
42  << "(std::numeric_limits<double>::quiet_NaN());"
43  << EOL;
44  o << INDENT2 << "(void) DUMMY_VAR__; // suppress unused var warning"
45  << EOL2;
46 
47  o << INDENT2 << "T__ lp__(0.0);"
48  << EOL;
49  o << INDENT2 << "stan::math::accumulator<T__> lp_accum__;"
50  << EOL2;
51 
52  bool gen_local_vars = true;
53 
54  generate_try(2, o);
55 
56  generate_comment("model parameters", 3, o);
57  generate_local_var_inits(p.parameter_decl_, gen_local_vars, 3, o);
58  o << EOL;
59 
60  generate_comment("transformed parameters", 3, o);
61  generate_local_var_decls(p.derived_decl_.first, 3, o);
62  o << EOL;
63 
64  generate_statements(p.derived_decl_.second, 3, o);
65  o << EOL;
66 
67  generate_validate_transformed_params(p.derived_decl_.first, 3, o);
68  o << INDENT3
69  << "const char* function__ = \"validate transformed params\";"
70  << EOL;
71  o << INDENT3
72  << "(void) function__; // dummy to suppress unused var warning"
73  << EOL;
74 
75  generate_validate_var_decls(p.derived_decl_.first, 3, o);
76 
77  o << EOL;
78  generate_comment("model body", 3, o);
79 
80  generate_statement(p.statement_, 3, o);
81  o << EOL;
83 
84  o << EOL;
85  o << INDENT2 << "lp_accum__.add(lp__);" << EOL;
86  o << INDENT2 << "return lp_accum__.sum();" << EOL2;
87  o << INDENT << "} // log_prob()" << EOL2;
88 
89  o << INDENT
90  << "template <bool propto, bool jacobian, typename T_>" << EOL;
91  o << INDENT
92  << "T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r," << EOL;
93  o << INDENT << " std::ostream* pstream = 0) const {" << EOL;
94  o << INDENT << " std::vector<T_> vec_params_r;" << EOL;
95  o << INDENT << " vec_params_r.reserve(params_r.size());" << EOL;
96  o << INDENT << " for (int i = 0; i < params_r.size(); ++i)" << EOL;
97  o << INDENT << " vec_params_r.push_back(params_r(i));" << EOL;
98  o << INDENT << " std::vector<int> vec_params_i;" << EOL;
99  o << INDENT
100  << " return log_prob<propto,jacobian,T_>(vec_params_r, "
101  << "vec_params_i, pstream);" << EOL;
102  o << INDENT << "}" << EOL2;
103  }
const std::string EOL2("\n\n")
void generate_comment(const std::string &msg, int indent, std::ostream &o)
void generate_statement(const statement &s, int indent, std::ostream &o)
const char * p
Definition: xmltok.h:285
void generate_statements(const std::vector< statement > statements, int indent, std::ostream &o)
void generate_local_var_decls(const std::vector< var_decl > &vs, int indent, std::ostream &o)
const std::string INDENT3(" ")
const std::string INDENT(" ")
void generate_validate_var_decls(const std::vector< var_decl > decls, int indent, std::ostream &o)
void generate_validate_transformed_params(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void generate_local_var_inits(std::vector< var_decl > vs, bool declare_vars, int indent, std::ostream &o)
void generate_try(int indent, std::ostream &o)
const std::string EOL("\n")
void generate_catch_throw_located(int indent, std::ostream &o)
const std::string INDENT2(" ")
void stan::lang::generate_member_var_decls ( const std::vector< var_decl > &  vs,
int  indent,
std::ostream &  o 
)

Generate member variable declarations for the specified variable declarations at the specified indentation level to the specified stream.

Parameters
[in]vsvariable declarations
[in]indentindentation level
[in]ostream for writing

Definition at line 22 of file generate_member_var_decls.hpp.

References MECModelEnuComparisons::i.

Referenced by generate_member_var_decls_all().

23  {
24  member_var_decl_visgen vis(indent, o);
25  for (size_t i = 0; i < vs.size(); ++i)
26  boost::apply_visitor(vis, vs[i].decl_);
27  }
std::string indent(std::size_t const i)
void stan::lang::generate_member_var_decls_all ( const program prog,
std::ostream &  o 
)

Generate member variable declarations for the data and transformed data blocks for the specified program, writing to the specified stream.

Parameters
[in]progprogram from which to generate
[in,out]ostream for generating

Definition at line 19 of file generate_member_var_decls_all.hpp.

References stan::lang::program::data_decl_, stan::lang::program::derived_data_decl_, and generate_member_var_decls().

Referenced by generate_cpp().

20  {
21  generate_member_var_decls(prog.data_decl_, 1, o);
22  generate_member_var_decls(prog.derived_data_decl_.first, 1, o);
23  }
void generate_member_var_decls(const std::vector< var_decl > &vs, int indent, std::ostream &o)
void stan::lang::generate_member_var_inits ( const std::vector< var_decl > &  vs,
int  indent,
std::ostream &  o 
)

Generate initializations for member variables by reading from constructor variable context. Generated initializations are preceeded by stmt updating global variable current_statement_begin__ to src file line number where variable is declared.

Parameters
[in]vsmember variable declarations
[in]indentindentation level
[in,out]ostream for generating

Definition at line 26 of file generate_member_var_inits.hpp.

References EOL(), generate_indent(), and MECModelEnuComparisons::i.

Referenced by generate_constructor().

27  {
28  dump_member_var_visgen vis(indent, o);
29  for (size_t i = 0; i < vs.size(); ++i) {
31  o << "current_statement_begin__ = " << vs[i].begin_line_ << ";"
32  << EOL;
33  boost::apply_visitor(vis, vs[i].decl_);
34  }
35  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_model_name_method ( const std::string &  model_name,
std::ostream &  o 
)

Generate the model_name method for the specified name on the specified stream.

Parameters
[in]model_namename of model
[in,out]ostream for generating

Definition at line 19 of file generate_model_name_method.hpp.

References EOL(), EOL2(), INDENT(), and INDENT2().

Referenced by generate_cpp().

20  {
21  o << INDENT << "static std::string model_name() {" << EOL
22  << INDENT2 << "return \"" << model_name << "\";" << EOL
23  << INDENT << "}" << EOL2;
24  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_model_typedef ( const std::string &  model_name,
std::ostream &  o 
)

Generate reusable typedef of stan_model for specified model name writing to the specified stream.

Parameters
model_namename of model
ostream for generating

Definition at line 19 of file generate_model_typedef.hpp.

References EOL2().

Referenced by generate_cpp(), and TEST().

20  {
21  o << "typedef " << model_name << "_namespace::" << model_name
22  << " stan_model;" << EOL2;
23  }
const std::string EOL2("\n\n")
void stan::lang::generate_namespace_end ( std::ostream &  o)

Generate the end of a namespace to the specified stream.

Parameters
[in,out]ostream for generating

Definition at line 15 of file generate_namespace_end.hpp.

References EOL2().

Referenced by generate_cpp().

15  {
16  o << "}" << EOL2;
17  }
const std::string EOL2("\n\n")
void stan::lang::generate_namespace_start ( const std::string &  name,
std::ostream &  o 
)

Generate the opening name and brace for a namespace, with two end of lines.

Parameters
[in]namename of namespace
[in,out]ostream for generating

Definition at line 18 of file generate_namespace_start.hpp.

References EOL2().

Referenced by generate_cpp().

18  {
19  o << "namespace " << name << "_namespace {" << EOL2;
20  }
const XML_Char * name
Definition: expat.h:151
const std::string EOL2("\n\n")
void stan::lang::generate_param_names_method ( const program prog,
std::ostream &  o 
)

Generate the method to get_param_names, which retrieves the parameter names for the specified program on the specified stream.

Parameters
[in]progprogram from which to generate
[in,out]ostream for generating

Definition at line 21 of file generate_param_names_method.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), stan::lang::program::generated_decl_, MECModelEnuComparisons::i, INDENT(), INDENT2(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

21  {
22  write_param_names_visgen vis(o);
23  o << EOL << INDENT
24  << "void get_param_names(std::vector<std::string>& names__) const {"
25  << EOL;
26  o << INDENT2 << "names__.resize(0);" << EOL;
27  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
28  boost::apply_visitor(vis, prog.parameter_decl_[i].decl_);
29  for (size_t i = 0; i < prog.derived_decl_.first.size(); ++i)
30  boost::apply_visitor(vis, prog.derived_decl_.first[i].decl_);
31  for (size_t i = 0; i < prog.generated_decl_.first.size(); ++i)
32  boost::apply_visitor(vis, prog.generated_decl_.first[i].decl_);
33  o << INDENT << "}" << EOL2;
34  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_printable ( const printable p,
std::ostream &  o 
)

Generate the specified printable object to the specified stream.

Parameters
pobject to print
ostream for printing

Definition at line 18 of file generate_printable.hpp.

References stan::lang::printable::printable_.

Referenced by stan::lang::statement_visgen::operator()().

18  {
19  printable_visgen vis(o);
20  boost::apply_visitor(vis, p.printable_);
21  }
const char * p
Definition: xmltok.h:285
void stan::lang::generate_private_decl ( std::ostream &  o)

Generate the private declaration scope for a class to the specified stream.

Parameters
[in,out]ostream for generating

Definition at line 17 of file generate_private_decl.hpp.

References EOL().

Referenced by generate_cpp().

17  {
18  o << "private:" << EOL;
19  }
const std::string EOL("\n")
void stan::lang::generate_program_reader_fun ( const std::vector< io::preproc_event > &  history,
std::ostream &  o 
)

Generate a top-level function that returns the program reader for the specified history.

Implementation note: Because this is only called when there is an error to report, reconstructing on each call has acceptable performance.

Parameters
[in]historyrecord of I/O path for lines in compound program
[in,out]ostream to which generated code is written

Definition at line 24 of file generate_program_reader_fun.hpp.

References allTimeWatchdog::endl, MECModelEnuComparisons::i, and INDENT().

Referenced by generate_cpp(), and generate_standalone_functions().

25  {
26  o << "stan::io::program_reader prog_reader__() {" << std::endl;
27  o << INDENT << "stan::io::program_reader reader;" << std::endl;
28  for (size_t i = 0; i < history.size(); ++i)
29  o << INDENT << "reader.add_event("
30  << history[i].concat_line_num_
31  << ", " << history[i]. line_num_
32  << ", \"" << history[i].action_ << "\""
33  << ", \"" << history[i].path_ << "\");" << std::endl;
34  o << INDENT << "return reader;" << std::endl;
35  o << "}" << std::endl << std::endl;
36  }
def history()
Definition: g4zmq.py:84
const std::string INDENT(" ")
void stan::lang::generate_propto_default_function ( const function_decl_def fun,
const std::string &  scalar_t_name,
std::ostream &  o 
)

Generate a version of the specified function with propto set to false, with the specified local scalar type, writing to the specified stream.

Parameters
[in]funfunction declaration
[in]scalar_t_namestring representation of scalar type for local scalar variables
[in,out]ostream for generating

Definition at line 26 of file generate_propto_default_function.hpp.

References generate_function_arguments(), generate_function_inline_return_type(), generate_function_name(), generate_function_template_parameters(), and generate_propto_default_function_body().

Referenced by generate_function().

28  {
29  generate_function_template_parameters(fun, false, false, false, o);
30  generate_function_inline_return_type(fun, scalar_t_name, 0, o);
32  generate_function_arguments(fun, false, false, false, o);
34  }
void generate_function_name(const function_decl_def &fun, std::ostream &o)
void generate_function_arguments(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &o, bool double_only=false, std::string rng_type="RNG", bool parameter_defaults=false)
void generate_function_inline_return_type(const function_decl_def &fun, const std::string &scalar_t_name, int indent, std::ostream &out)
void generate_propto_default_function_body(const function_decl_def &fun, std::ostream &o)
void generate_function_template_parameters(const function_decl_def &fun, bool is_rng, bool is_lp, bool is_log, std::ostream &out)
void stan::lang::generate_propto_default_function_body ( const function_decl_def fun,
std::ostream &  o 
)

Generate the body of the specified function with propto set to false, writing to the specified stream.

Parameters
[in]funfunction declaration
[in,out]ostream for generating

Definition at line 19 of file generate_propto_default_function_body.hpp.

References stan::lang::function_decl_def::arg_decls_, EOL(), MECModelEnuComparisons::i, INDENT(), and stan::lang::function_decl_def::name_.

Referenced by generate_propto_default_function().

20  {
21  o << " {" << EOL;
22  o << INDENT << "return ";
23  o << fun.name_ << "<false>(";
24  for (size_t i = 0; i < fun.arg_decls_.size(); ++i) {
25  if (i > 0)
26  o << ",";
27  o << fun.arg_decls_[i].name_;
28  }
29  if (fun.arg_decls_.size() > 0)
30  o << ", ";
31  o << "pstream__";
32  o << ");" << EOL;
33  o << "}" << EOL;
34  }
const std::string INDENT(" ")
const std::string EOL("\n")
void stan::lang::generate_public_decl ( std::ostream &  o)

Generate the public declaration scope for a class to the specified stream.

Parameters
[in,out]ostream for generating

Definition at line 17 of file generate_public_decl.hpp.

References EOL().

Referenced by generate_cpp().

17  {
18  o << "public:" << EOL;
19  }
const std::string EOL("\n")
void stan::lang::generate_quoted_expression ( const expression e,
std::ostream &  o 
)

Definition at line 16 of file generate_quoted_expression.hpp.

References generate_expression(), generate_quoted_string(), NOT_USER_FACING(), msf_helper::o, and ss.

Referenced by generate_validate_positive(), and test_generate_quoted_expression().

16  {
17  std::stringstream ss;
19  generate_quoted_string(ss.str(), o);
20  }
Float_t ss
Definition: plot.C:24
void generate_quoted_string(const std::string &s, std::ostream &o)
const bool NOT_USER_FACING(false)
Float_t e
Definition: plot.C:35
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_quoted_string ( const std::string &  s,
std::ostream &  o 
)

Print the specified string to the specified output stream, wrapping in double quotes (") and inserting a backslash to escape double quotes, single quotes, and backslashes.

Parameters
[in]sString to output
[in,out]oOutput stream

Definition at line 18 of file generate_quoted_string.hpp.

References MECModelEnuComparisons::i.

Referenced by generate_indexed_expr(), generate_quoted_expression(), stan::lang::printable_visgen::operator()(), test_generate_quoted_string(), and test_generate_quoted_string_quote().

18  {
19  o << '"';
20  for (size_t i = 0; i < s.size(); ++i) {
21  if (s[i] == '"' || s[i] == '\\' || s[i] == '\'' )
22  o << '\\';
23  o << s[i];
24  }
25  o << '"';
26  }
const XML_Char * s
Definition: expat.h:262
void stan::lang::generate_real_var_type ( const scope var_scope,
bool  has_var,
std::ostream &  o 
)

Generate correct C++ type for expressions which contain a Stan real variable according to scope in which expression is used and expression contents.

Parameters
[in]var_scopeexpression origin block
[in]has_vardoes expression contains a variable?
[in,out]ogenerated typename

Definition at line 19 of file generate_real_var_type.hpp.

References stan::lang::scope::fun(), and has_var().

Referenced by stan::lang::expression_visgen::operator()(), and TEST().

21  {
22  if (var_scope.fun() || has_var)
23  o << "local_scalar_t__";
24  else
25  o << "double";
26  }
bool has_var(const expression &e, const variable_map &var_map)
Definition: has_var_def.hpp:10
void stan::lang::generate_register_mpi ( const std::string &  model_name,
std::ostream &  o 
)

Definition at line 13 of file generate_register_mpi.hpp.

References a, allTimeWatchdog::endl, and stan::lang::map_rect::registered_calls().

Referenced by generate_cpp().

14  {
15  for (auto a : map_rect::registered_calls()) {
16  int id = a.first;
17  std::string fun_name = a.second;
18  o << "STAN_REGISTER_MAP_RECT(" << id << ", " << model_name << "_namespace::"
19  << fun_name << "_functor__"
20  << ")" << std::endl;
21  }
22 }
const double a
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void stan::lang::generate_set_param_ranges ( const std::vector< var_decl > &  var_decls,
int  indent,
std::ostream &  o 
)

Definition at line 28 of file generate_set_param_ranges.hpp.

References EOL(), generate_indent(), and MECModelEnuComparisons::i.

Referenced by generate_constructor().

29  {
31  o << "num_params_r__ = 0U;" << EOL;
33  o << "param_ranges_i__.clear();" << EOL;
34  set_param_ranges_visgen vis(indent, o);
35  for (size_t i = 0; i < var_decls.size(); ++i) {
37  o << "current_statement_begin__ = " << var_decls[i].begin_line_ << ";"
38  << EOL;
39  boost::apply_visitor(vis, var_decls[i].decl_);
40  }
41  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_standalone_functions ( const program prog,
const std::vector< std::string > &  namespaces,
const std::vector< io::preproc_event > &  history,
std::ostream &  o 
)

Generate the C++ code for standalone functions, generating it in the namespace provided, writing to the specified stream.

Parameters
[in]progprogram from which to generate
[in]namespacesnamespace to generate the functions in
[in]historyI/O include history for text underlying program
[in,out]ostream for generating

Definition at line 31 of file generate_standalone_functions.hpp.

References EOL(), stan::lang::program::function_decl_defs_, generate_function_instantiations(), generate_functions(), generate_include(), generate_program_reader_fun(), generate_typedefs(), generate_usings_standalone_functions(), and generate_version_comment().

Referenced by compile_functions().

35  {
37 
38  generate_include("stan/model/standalone_functions_header.hpp", o);
39  o << EOL;
40 
41  // generate namespace starts
42  for (size_t namespace_i = 0;
43  namespace_i < namespaces.size(); ++namespace_i) {
44  o << "namespace " << namespaces[namespace_i] << " { ";
45  }
46  o << EOL;
47 
51  generate_functions(prog.function_decl_defs_, o);
52 
53  // generate namespace ends
54  for (size_t namespace_i = 0;
55  namespace_i < namespaces.size(); ++namespace_i) {
56  o << " } ";
57  }
58  o << EOL;
59 
60  generate_function_instantiations(prog.function_decl_defs_, namespaces, o);
61  }
def history()
Definition: g4zmq.py:84
void generate_program_reader_fun(const std::vector< io::preproc_event > &history, std::ostream &o)
void generate_functions(const std::vector< function_decl_def > &funs, std::ostream &o)
void generate_typedefs(std::ostream &o)
void generate_version_comment(std::ostream &o)
void generate_function_instantiations(const std::vector< function_decl_def > &funs, const std::vector< std::string > &namespaces, std::ostream &o)
void generate_usings_standalone_functions(std::ostream &o)
const std::string EOL("\n")
void generate_include(const std::string &lib_name, std::ostream &o)
void stan::lang::generate_statement ( const statement s,
int  indent,
std::ostream &  o 
)

Generate the specified statement with the specified indentation level on the specified output stream. Generated statement is preceeded by stmt updating global variable current_statement_begin__ to src file line number where stmt begins.

Parameters
[in]sstatement to generate
[in]indentindentation level
[in,out]ostream for generating

Definition at line 25 of file generate_statement.hpp.

References stan::lang::statement::begin_line_, EOL(), generate_indent(), and stan::lang::statement::statement_.

Referenced by generate_function_body(), generate_log_prob(), generate_statements(), stan::lang::statement_visgen::operator()(), and TEST().

25  {
26  is_numbered_statement_vis vis_is_numbered;
27  if (boost::apply_visitor(vis_is_numbered, s.statement_)) {
29  o << "current_statement_begin__ = " << s.begin_line_ << ";" << EOL;
30  }
31  statement_visgen vis(indent, o);
32  boost::apply_visitor(vis, s.statement_);
33  }
void generate_indent(size_t indent, std::ostream &o)
const XML_Char * s
Definition: expat.h:262
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_statement ( const std::vector< statement > &  ss,
int  indent,
std::ostream &  o 
)
void stan::lang::generate_statements ( const std::vector< statement statements,
int  indent,
std::ostream &  o 
)

Generate the set of statements in a program block with the specified indentation level on the specified stream.

Parameters
[in]statementsvector of statements
[in]indentindentation level
[in,out]ostream for generating

Definition at line 20 of file generate_statements.hpp.

References generate_statement(), and MECModelEnuComparisons::i.

Referenced by generate_constructor(), generate_log_prob(), and generate_write_array_method().

21  {
22  for (size_t i = 0; i < statements.size(); ++i)
23  generate_statement(statements[i], indent, o);
24  }
void generate_statement(const statement &s, int indent, std::ostream &o)
std::string indent(std::size_t const i)
void stan::lang::generate_try ( int  indent,
std::ostream &  o 
)

Generate the opening for a try statement at the specified indentation level on the specified stream.

Parameters
[in]indentindentation level
[in,out]ostream for generating

Definition at line 19 of file generate_try.hpp.

References EOL(), and generate_indent().

Referenced by generate_constructor(), generate_function_body(), generate_log_prob(), and generate_write_array_method().

19  {
21  o << "try {" << EOL;
22  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_type ( const std::string &  base_type,
const std::vector< expression > &  ,
size_t  end,
std::ostream &  o 
)

Generate the base type for multi-dimensional arrays.

Parameters
[in]base_typestring representing bae type
[in]endnumber of standard vector embeddings
[in,out]ostream for generating

Definition at line 19 of file generate_type.hpp.

References febshutoff_auto::end, and MECModelEnuComparisons::i.

Referenced by stan::lang::init_visgen::generate_declaration(), generate_initialization(), generate_initializer(), and stan::lang::expression_visgen::operator()().

21  {
22  for (size_t i = 0; i < end; ++i)
23  o << "std::vector<";
24  o << base_type;
25  for (size_t i = 0; i < end; ++i) {
26  if (i > 0) o << ' ';
27  o << '>';
28  }
29  }
void stan::lang::generate_typedef ( const std::string &  type,
const std::string &  abbrev,
std::ostream &  o 
)

Generate a typedef statement for the specified type and abbreviation to the specified stream.

Parameters
[in]typetype for definition
[in]abbrevabbreviation defined for type
[in,out]ostream for writing

Definition at line 20 of file generate_typedef.hpp.

References EOL().

Referenced by generate_typedefs().

21  {
22  o << "typedef" << " " << type << " " << abbrev << ";" << EOL;
23  }
::xsd::cxx::tree::type type
Definition: Database.h:110
const std::string EOL("\n")
void stan::lang::generate_typedefs ( std::ostream &  o)

Generate the typedefs required for the Stan model class to the specified stream.

Parameters
[in,out]ostream for generating

Definition at line 17 of file generate_typedefs.hpp.

References EOL(), and generate_typedef().

Referenced by generate_standalone_functions().

17  {
18  generate_typedef("Eigen::Matrix<double,Eigen::Dynamic,1>", "vector_d", o);
19  generate_typedef("Eigen::Matrix<double,1,Eigen::Dynamic>",
20  "row_vector_d", o);
21  generate_typedef("Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>",
22  "matrix_d", o);
23  o << EOL;
24  }
void generate_typedef(const std::string &type, const std::string &abbrev, std::ostream &o)
const std::string EOL("\n")
void stan::lang::generate_unconstrained_param_names_method ( const program prog,
std::ostream &  o 
)

Generate the method unconstrained_param_names for the specified program on the specified stream.

Parameters
[in]progprogam from which to generate
[in,out]ostream for generating

Definition at line 20 of file generate_unconstrained_param_names_method.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), stan::lang::program::generated_decl_, MECModelEnuComparisons::i, INDENT(), INDENT2(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

21  {
22  o << EOL << INDENT
23  << "void unconstrained_param_names("
24  << "std::vector<std::string>& param_names__,"
25  << EOL << INDENT
26  << " bool include_tparams__ = true,"
27  << EOL << INDENT
28  << " bool include_gqs__ = true) const {"
29  << EOL << INDENT2
30  << "std::stringstream param_name_stream__;" << EOL;
31  unconstrained_param_names_visgen vis1(1, o);
32  unconstrained_param_names_visgen vis2(2, o);
33  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
34  boost::apply_visitor(vis1, prog.parameter_decl_[i].decl_);
35  o << EOL << INDENT2
36  << "if (!include_gqs__ && !include_tparams__) return;" << EOL;
37  o << EOL << INDENT2 << "if (include_tparams__) {" << EOL;
38  for (size_t i = 0; i < prog.derived_decl_.first.size(); ++i)
39  boost::apply_visitor(vis2, prog.derived_decl_.first[i].decl_);
40  o << INDENT2 << "}" << EOL2;
41 
42  o << EOL << INDENT2 << "if (!include_gqs__) return;" << EOL;
43  for (size_t i = 0; i < prog.generated_decl_.first.size(); ++i)
44  boost::apply_visitor(vis1, prog.generated_decl_.first[i].decl_);
45  o << INDENT << "}" << EOL2;
46  }
const std::string EOL2("\n\n")
const std::string INDENT(" ")
const std::string EOL("\n")
const std::string INDENT2(" ")
void stan::lang::generate_using ( const std::string &  type,
std::ostream &  o 
)

Generate a using statement for the specified type to the specified stream.

Parameters
[in]typetype for which using statement is geneated
[in,out]ostream for generation

Definition at line 19 of file generate_using.hpp.

References EOL().

Referenced by generate_usings(), and generate_usings_standalone_functions().

19  {
20  o << "using " << type << ";" << EOL;
21  }
::xsd::cxx::tree::type type
Definition: Database.h:110
const std::string EOL("\n")
void stan::lang::generate_using_namespace ( const std::string &  ns,
std::ostream &  o 
)

Generate using statement for the specified namespace to the specfied stream.

Parameters
[in]nsnamespace for which using statement is generated
[in,out]ostream for generating

Definition at line 19 of file generate_using_namespace.hpp.

References EOL().

Referenced by generate_usings(), and generate_usings_standalone_functions().

19  {
20  o << "using namespace " << ns << ";" << EOL;
21  }
static const double ns
Module that plots metrics from reconstructed cosmic ray data.
const std::string EOL("\n")
void stan::lang::generate_usings ( std::ostream &  o)

Generate the using statements for a Stan model.

Parameters
[in,out]ostream for generating

Definition at line 18 of file generate_usings.hpp.

References EOL(), generate_using(), and generate_using_namespace().

Referenced by generate_cpp().

18  {
19  generate_using("std::istream", o);
20  generate_using("std::string", o);
21  generate_using("std::stringstream", o);
22  generate_using("std::vector", o);
23  generate_using("stan::io::dump", o);
24  generate_using("stan::math::lgamma", o);
25  generate_using("stan::model::prob_grad", o);
26  generate_using_namespace("stan::math", o);
27  o << EOL;
28  }
void generate_using_namespace(const std::string &ns, std::ostream &o)
void generate_using(const std::string &type, std::ostream &o)
const std::string EOL("\n")
void stan::lang::generate_usings_standalone_functions ( std::ostream &  o)

Generate the using statements for a Stan standalone functions file.

Parameters
[in,out]ostream for generating

Definition at line 18 of file generate_usings_standalone_functions.hpp.

References EOL(), generate_using(), and generate_using_namespace().

Referenced by generate_standalone_functions().

18  {
19  generate_using("std::istream", o);
20  generate_using("std::string", o);
21  generate_using("std::stringstream", o);
22  generate_using("std::vector", o);
23  generate_using_namespace("stan::math", o);
24  o << EOL;
25  }
void generate_using_namespace(const std::string &ns, std::ostream &o)
void generate_using(const std::string &type, std::ostream &o)
const std::string EOL("\n")
void stan::lang::generate_validate_context_size ( size_t  indent,
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() 
)

Definition at line 30 of file generate_validate_context_size.hpp.

References EOL(), generate_expression(), generate_indent(), generate_validate_positive(), MECModelEnuComparisons::i, is_nil(), and NOT_USER_FACING().

Referenced by stan::lang::var_size_validating_visgen::operator()().

39  {
40  // check array dimensions
41  for (size_t i = 0; i < dims.size(); ++i)
43  // check vector, row_vector, and matrix rows
44  if (!is_nil(type_arg1))
45  generate_validate_positive(var_name, type_arg1, indent, o);
46  // check matrix cols
47  if (!is_nil(type_arg2))
48  generate_validate_positive(var_name, type_arg2, indent, o);
49 
50  // calls var_context to make sure dimensions match
52  o << "context__.validate_dims("
53  << '"' << stage << '"' << ", "
54  << '"' << var_name << '"' << ", "
55  << '"' << base_type << '"' << ", "
56  << "context__.to_vec(";
57  for (size_t i = 0; i < dims.size(); ++i) {
58  if (i > 0) o << ",";
60  }
61  if (!is_nil(type_arg1)) {
62  if (dims.size() > 0) o << ",";
63  generate_expression(type_arg1.expr_, NOT_USER_FACING, o);
64  if (!is_nil(type_arg2)) {
65  o << ",";
66  generate_expression(type_arg2.expr_, NOT_USER_FACING, o);
67  }
68  }
69  o << "));" << EOL;
70  }
void generate_validate_positive(const std::string &var_name, const expression &expr, int indents, std::ostream &o)
bool is_nil(boost::any const &val)
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const bool NOT_USER_FACING(false)
const std::string EOL("\n")
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_validate_positive ( const std::string &  var_name,
const expression expr,
int  indents,
std::ostream &  o 
)

Generate call to stan_math lib function validate_non_negative_index which will throw an informative error if dim size is < 0

This check should precede the variable declaration in order to avoid bad alloc runtime error. Called by
generate_validate_context_size - data variables
generate_initialization - transformed data declarations
generate_var_resiszing - initializes transformed data variables
generate_local_var_decls - local variables, transformed parameters write array, generated quantities
generate_set_param_ranges - parameter variables

Parameters
[in]var_namevariable name
[in]exprdeclared dim size expression
[in]indentsindentation level
[in,out]ooutput stream for generated code

Definition at line 33 of file generate_validate_positive.hpp.

References EOL(), generate_expression(), generate_indent(), generate_quoted_expression(), and NOT_USER_FACING().

Referenced by stan::lang::local_var_decl_visgen::declare_array(), generate_initialization(), generate_validate_context_size(), stan::lang::set_param_ranges_visgen::operator()(), and stan::lang::local_var_decl_visgen::operator()().

35  {
36  generate_indent(indents, o);
37  o << "validate_non_negative_index(\"" << var_name << "\", ";
39  o << ", ";
41  o << ");" << EOL;
42  }
void generate_indent(size_t indent, std::ostream &o)
const bool NOT_USER_FACING(false)
const std::string EOL("\n")
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void generate_quoted_expression(const expression &e, std::ostream &o)
void stan::lang::generate_validate_transformed_params ( const std::vector< var_decl > &  vs,
int  indent,
std::ostream &  o 
)

Generate code to validate the specified transformed parameters, generating at the specified indentation level to the specified stream.

Parameters
[in]vsvariable declarations
[in]indentindentation level
[in,out]ostream for generating

Definition at line 24 of file generate_validate_transformed_params.hpp.

References EOL(), generate_comment(), and MECModelEnuComparisons::i.

Referenced by generate_log_prob().

25  {
26  generate_comment("validate transformed parameters", indent, o);
27  validate_transformed_params_visgen vis(indent, o);
28  for (size_t i = 0; i < vs.size(); ++i)
29  boost::apply_visitor(vis, vs[i].decl_);
30  o << EOL;
31  }
void generate_comment(const std::string &msg, int indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_validate_var_decl ( const var_decl decl,
int  indent,
std::ostream &  o 
)

Generate code to validate the specified variable declaration at the specified indentation level to the specified stream.

Parameters
[in]declvariable declaration
[in]indentindentation level
[in,out]ostream for generating

Definition at line 20 of file generate_validate_var_decl.hpp.

References stan::lang::var_decl::decl_.

Referenced by generate_validate_var_decls().

21  {
22  validate_var_decl_visgen vis(indent, o);
23  boost::apply_visitor(vis, decl.decl_);
24  }
std::string indent(std::size_t const i)
void stan::lang::generate_validate_var_decls ( const std::vector< var_decl decls,
int  indent,
std::ostream &  o 
)

Generate code to validate the specified variable declarations at the specified indentation level to the specified stream. Generated code is preceeded by stmt updating global variable current_statement_begin__ to src file line number where variable is declared.

Parameters
[in]declsvariable declarations
[in]indentindentation level
[in,out]ostream for generating

Definition at line 24 of file generate_validate_var_decls.hpp.

References EOL(), generate_indent(), generate_validate_var_decl(), and MECModelEnuComparisons::i.

Referenced by generate_constructor(), generate_log_prob(), and generate_write_array_method().

25  {
26  for (size_t i = 0; i < decls.size(); ++i) {
28  o << "current_statement_begin__ = " << decls[i].begin_line_ << ";"
29  << EOL;
30 
32  }
33  }
void generate_indent(size_t indent, std::ostream &o)
void generate_validate_var_decl(const var_decl &decl, int indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_var_resizing ( const std::vector< var_decl > &  vs,
int  indent,
std::ostream &  o 
)

Generate code to to the specified stream to resize the variables in the specified declarations and fill them with dummy values. Generated code is preceeded by stmt updating global variable current_statement_begin__ to src file line number where variable is declared.

Parameters
[in]vsvariable declarations
[in]indentindentation level
[in,out]ostream for generating

Definition at line 28 of file generate_var_resizing.hpp.

References EOL(), generate_expression(), generate_indent(), MECModelEnuComparisons::i, and NOT_USER_FACING().

Referenced by generate_constructor().

29  {
30  var_resizing_visgen vis_resizer(indent, o);
31  init_vars_visgen vis_filler(indent, o);
32  for (size_t i = 0; i < vs.size(); ++i) {
34  o << "current_statement_begin__ = " << vs[i].begin_line_ << ";"
35  << EOL;
36  boost::apply_visitor(vis_resizer, vs[i].decl_);
37  boost::apply_visitor(vis_filler, vs[i].decl_);
38  if (vs[i].has_def()) {
40  o << "stan::math::assign(" << vs[i].name() << ",";
42  o << ");" << EOL;
43  }
44  }
45  }
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const bool NOT_USER_FACING(false)
const std::string EOL("\n")
void generate_expression(const expression &e, bool user_facing, std::ostream &o)
void stan::lang::generate_version_comment ( std::ostream &  o)

Generate a comment indicating which version of Stan generated the model code to the specified stream.

Parameters
[in,out]ostream for generating

Definition at line 18 of file generate_version_comment.hpp.

References EOL2(), stan::MAJOR_VERSION, stan::MINOR_VERSION, and stan::PATCH_VERSION.

Referenced by generate_cpp(), and generate_standalone_functions().

18  {
19  o << "// Code generated by Stan version " << stan::MAJOR_VERSION
20  << "." << stan::MINOR_VERSION
21  << "." << stan::PATCH_VERSION
22  << EOL2;
23  }
const std::string EOL2("\n\n")
const std::string MINOR_VERSION
Definition: version.hpp:24
const std::string PATCH_VERSION
Definition: version.hpp:27
const std::string MAJOR_VERSION
Definition: version.hpp:21
void stan::lang::generate_void_statement ( const std::string &  name,
const size_t  indent,
std::ostream &  o 
)

Generate a dummy void-cast statement for a variable of the specified name at the specified indentation level to the specified output stream.

Parameters
[in]namevariable name
[in]indentindentation level
[in,out]ostream for genering

Definition at line 20 of file generate_void_statement.hpp.

References EOL(), and generate_indent().

Referenced by stan::lang::local_var_decl_visgen::declare_array(), generate_constructor(), stan::lang::init_local_var_visgen::generate_initialize_array(), generate_write_array_method(), and stan::lang::statement_visgen::operator()().

22  {
24  o << "(void) " << name << ";"
25  << " // dummy to suppress unused var warning"
26  << EOL;
27  }
const XML_Char * name
Definition: expat.h:151
void generate_indent(size_t indent, std::ostream &o)
std::string indent(std::size_t const i)
const std::string EOL("\n")
void stan::lang::generate_write_array_method ( const program prog,
const std::string &  model_name,
std::ostream &  o 
)

Generate the write_array method for the specified program, with specified model name to the specified stream.

Parameters
[in]progprogram from which to generate
[in]model_namename of model
[in,out]ostream for generating

Definition at line 30 of file generate_write_array_method.hpp.

References stan::lang::program::derived_decl_, EOL(), EOL2(), generate_catch_throw_located(), generate_comment(), generate_local_var_decls(), generate_statements(), generate_try(), generate_validate_var_decls(), generate_void_statement(), stan::lang::program::generated_decl_, MECModelEnuComparisons::i, INDENT(), INDENT2(), INDENT3(), and stan::lang::program::parameter_decl_.

Referenced by generate_cpp().

32  {
33  o << INDENT << "template <typename RNG>" << EOL;
34  o << INDENT << "void write_array(RNG& base_rng__," << EOL;
35  o << INDENT << " std::vector<double>& params_r__," << EOL;
36  o << INDENT << " std::vector<int>& params_i__," << EOL;
37  o << INDENT << " std::vector<double>& vars__," << EOL;
38  o << INDENT << " bool include_tparams__ = true," << EOL;
39  o << INDENT << " bool include_gqs__ = true," << EOL;
40  o << INDENT
41  << " std::ostream* pstream__ = 0) const {" << EOL;
42  o << INDENT2 << "typedef double local_scalar_t__;" << EOL2;
43 
44  o << INDENT2 << "vars__.resize(0);" << EOL;
45  o << INDENT2
46  << "stan::io::reader<local_scalar_t__> in__(params_r__,params_i__);"
47  << EOL;
48  o << INDENT2 << "static const char* function__ = \""
49  << model_name << "_namespace::write_array\";" << EOL;
50  generate_void_statement("function__", 2, o);
51 
52  // declares, reads, and sets parameters
53  generate_comment("read-transform, write parameters", 2, o);
54  write_array_visgen vis(o);
55  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
56  boost::apply_visitor(vis, prog.parameter_decl_[i].decl_);
57 
58 
59  // writes parameters
60  write_array_vars_visgen vis_writer(2, o);
61  for (size_t i = 0; i < prog.parameter_decl_.size(); ++i)
62  boost::apply_visitor(vis_writer, prog.parameter_decl_[i].decl_);
63  o << EOL;
64 
65  generate_comment("declare and define transformed parameters", 2, o);
66  o << INDENT2 << "double lp__ = 0.0;" << EOL;
67  generate_void_statement("lp__", 2, o);
68  o << INDENT2 << "stan::math::accumulator<double> lp_accum__;" << EOL2;
69 
70  o << INDENT2
71  << "local_scalar_t__ DUMMY_VAR__"
72  << "(std::numeric_limits<double>::quiet_NaN());"
73  << EOL;
74  o << INDENT2 << "(void) DUMMY_VAR__; // suppress unused var warning"
75  << EOL2;
76 
77  generate_try(2, o);
78  generate_local_var_decls(prog.derived_decl_.first, 3, o);
79  o << EOL;
80  generate_statements(prog.derived_decl_.second, 3, o);
81  o << EOL;
82 
83  generate_comment("validate transformed parameters", 3, o);
84  generate_validate_var_decls(prog.derived_decl_.first, 3, o);
85  o << EOL;
86 
87  generate_comment("write transformed parameters", 3, o);
88  o << INDENT3 << "if (include_tparams__) {" << EOL;
89  for (size_t i = 0; i < prog.derived_decl_.first.size(); ++i)
90  boost::apply_visitor(vis_writer, prog.derived_decl_.first[i].decl_);
91  o << INDENT3 << "}" << EOL;
92 
93  o << INDENT3 << "if (!include_gqs__) return;"
94  << EOL;
95  generate_comment("declare and define generated quantities", 3, o);
96  generate_local_var_decls(prog.generated_decl_.first, 3, o);
97 
98  o << EOL;
99  generate_statements(prog.generated_decl_.second, 3, o);
100  o << EOL;
101 
102  generate_comment("validate generated quantities", 3, o);
103  generate_validate_var_decls(prog.generated_decl_.first, 3, o);
104  o << EOL;
105 
106  generate_comment("write generated quantities", 3, o);
107  for (size_t i = 0; i < prog.generated_decl_.first.size(); ++i)
108  boost::apply_visitor(vis_writer, prog.generated_decl_.first[i].decl_);
109  if (prog.generated_decl_.first.size() > 0)
110  o << EOL;
112 
113  o << INDENT << "}" << EOL2;
114 
115  o << INDENT << "template <typename RNG>" << EOL;
116  o << INDENT << "void write_array(RNG& base_rng," << EOL;
117  o << INDENT
118  << " Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,"
119  << EOL;
120  o << INDENT
121  << " Eigen::Matrix<double,Eigen::Dynamic,1>& vars,"
122  << EOL;
123  o << INDENT << " bool include_tparams = true," << EOL;
124  o << INDENT << " bool include_gqs = true," << EOL;
125  o << INDENT
126  << " std::ostream* pstream = 0) const {" << EOL;
127