Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
ast_def.cpp
Go to the documentation of this file.
1 #ifndef __STAN__GM__AST_DEF_HPP__
2 #define __STAN__GM__AST_DEF_HPP__
3 
4 #include <boost/variant/apply_visitor.hpp>
5 #include <boost/variant/recursive_variant.hpp>
6 
7 #include <cstddef>
8 #include <limits>
9 #include <climits>
10 #include <iostream>
11 #include <map>
12 #include <stdexcept>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 #include <stan/gm/ast.hpp>
18 
19 namespace stan {
20 
21  namespace gm {
22 
23  std::ostream& write_base_expr_type(std::ostream& o, base_expr_type type) {
24  switch (type) {
25  case INT_T :
26  o << "int";
27  break;
28  case DOUBLE_T :
29  o << "real";
30  break;
31  case VECTOR_T :
32  o << "vector";
33  break;
34  case ROW_VECTOR_T :
35  o << "row vector";
36  break;
37  case MATRIX_T :
38  o << "matrix";
39  break;
40  case ILL_FORMED_T :
41  o << "ill formed";
42  break;
43  default:
44  o << "UNKNOWN";
45  }
46  return o;
47  }
48 
49  // expr_type ctors and methods
51  : base_type_(ILL_FORMED_T),
52  num_dims_(0) {
53  }
55  : base_type_(base_type),
56  num_dims_(0) {
57  }
59  size_t num_dims)
60  : base_type_(base_type),
61  num_dims_(num_dims) {
62  }
63  bool expr_type::operator==(const expr_type& et) const {
64  return base_type_ == et.base_type_
65  && num_dims_ == et.num_dims_;
66  }
67  bool expr_type::operator!=(const expr_type& et) const {
68  return !(*this == et);
69  }
70  bool expr_type::is_primitive() const {
71  return is_primitive_int()
73  }
75  return base_type_ == INT_T
76  && num_dims_ == 0U;
77  }
79  return base_type_ == DOUBLE_T
80  && num_dims_ == 0U;
81  }
82  bool expr_type::is_ill_formed() const {
83  return base_type_ == ILL_FORMED_T;
84  }
86  return base_type_;
87  }
88  size_t expr_type::num_dims() const {
89  return num_dims_;
90  }
91 
92  std::ostream& operator<<(std::ostream& o, const expr_type& et) {
93  write_base_expr_type(o,et.type());
94  if (et.num_dims() > 0)
95  o << '[' << et.num_dims() << ']';
96  return o;
97  }
98 
100  if (!et.is_primitive())
101  return expr_type();
102  return et;
103  }
104 
106  const expr_type& et2) {
107  if (!et1.is_primitive() || !et2.is_primitive())
108  return expr_type();
109  return et1.type() == DOUBLE_T ? et1 : et2;
110  }
111 
113  // FIXME: for threaded models, requires double-check lock
114  if (!sigs_)
115  sigs_ = new function_signatures;
116  return *sigs_;
117  }
118  void function_signatures::add(const std::string& name,
119  const expr_type& result_type,
120  const std::vector<expr_type>& arg_types) {
121  sigs_map_[name].push_back(function_signature_t(result_type,arg_types));
122 
123  }
124  void function_signatures::add(const std::string& name,
125  const expr_type& result_type) {
126  std::vector<expr_type> arg_types;
127  add(name,result_type,arg_types);
128  }
129  void function_signatures::add(const std::string& name,
130  const expr_type& result_type,
131  const expr_type& arg_type) {
132  std::vector<expr_type> arg_types;
133  arg_types.push_back(arg_type);
134  add(name,result_type,arg_types);
135  }
136  void function_signatures::add(const std::string& name,
137  const expr_type& result_type,
138  const expr_type& arg_type1,
139  const expr_type& arg_type2) {
140  std::vector<expr_type> arg_types;
141  arg_types.push_back(arg_type1);
142  arg_types.push_back(arg_type2);
143  add(name,result_type,arg_types);
144  }
145  void function_signatures::add(const std::string& name,
146  const expr_type& result_type,
147  const expr_type& arg_type1,
148  const expr_type& arg_type2,
149  const expr_type& arg_type3) {
150  std::vector<expr_type> arg_types;
151  arg_types.push_back(arg_type1);
152  arg_types.push_back(arg_type2);
153  arg_types.push_back(arg_type3);
154  add(name,result_type,arg_types);
155  }
156  void function_signatures::add(const std::string& name,
157  const expr_type& result_type,
158  const expr_type& arg_type1,
159  const expr_type& arg_type2,
160  const expr_type& arg_type3,
161  const expr_type& arg_type4) {
162  std::vector<expr_type> arg_types;
163  arg_types.push_back(arg_type1);
164  arg_types.push_back(arg_type2);
165  arg_types.push_back(arg_type3);
166  arg_types.push_back(arg_type4);
167  add(name,result_type,arg_types);
168  }
169  void function_signatures::add(const std::string& name,
170  const expr_type& result_type,
171  const expr_type& arg_type1,
172  const expr_type& arg_type2,
173  const expr_type& arg_type3,
174  const expr_type& arg_type4,
175  const expr_type& arg_type5) {
176  std::vector<expr_type> arg_types;
177  arg_types.push_back(arg_type1);
178  arg_types.push_back(arg_type2);
179  arg_types.push_back(arg_type3);
180  arg_types.push_back(arg_type4);
181  arg_types.push_back(arg_type5);
182  add(name,result_type,arg_types);
183  }
184  void function_signatures::add_nullary(const::std::string& name) {
185  add(name,DOUBLE_T);
186  }
187  void function_signatures::add_unary(const::std::string& name) {
188  add(name,DOUBLE_T,DOUBLE_T);
189  }
190  void function_signatures::add_binary(const::std::string& name) {
192  }
193  void function_signatures::add_ternary(const::std::string& name) {
195  }
196  void function_signatures::add_quaternary(const::std::string& name) {
198  }
200  const std::vector<expr_type>& call_args,
201  const std::vector<expr_type>& sig_args) {
202  if (call_args.size() != sig_args.size()) {
203  return -1; // failure
204  }
205  int num_promotions = 0;
206  for (size_t i = 0; i < call_args.size(); ++i) {
207  if (call_args[i] == sig_args[i]) {
208  continue;
209  } else if (call_args[i].is_primitive_int()
210  && sig_args[i].is_primitive_double()) {
211  ++num_promotions;
212  } else {
213  return -1; // failed match
214  }
215  }
216  return num_promotions;
217  }
219  const std::string& name,
220  const std::vector<expr_type>& args,
221  std::ostream& error_msgs) {
222  std::vector<function_signature_t> signatures = sigs_map_[name];
223  size_t match_index = 0;
224  size_t min_promotions = std::numeric_limits<size_t>::max();
225  size_t num_matches = 0;
226 
227  for (size_t i = 0; i < signatures.size(); ++i) {
228  int promotions = num_promotions(args,signatures[i].second);
229  if (promotions < 0) continue; // no match
230  size_t promotions_ui = static_cast<size_t>(promotions);
231  if (promotions_ui < min_promotions) {
232  min_promotions = promotions_ui;
233  match_index = i;
234  num_matches = 1;
235  } else if (promotions_ui == min_promotions) {
236  ++num_matches;
237  }
238  }
239 
240  if (num_matches == 1) {
241  return signatures[match_index].first;
242  } else if (num_matches == 0) {
243  error_msgs << "no matches for function name=\"" << name << "\""
244  << std::endl;
245  } else {
246  error_msgs << num_matches << " matches with "
247  << min_promotions << " integer promotions "
248  << "for function name=\"" << name << "\"" << std::endl;
249  }
250  for (size_t i = 0; i < args.size(); ++i)
251  error_msgs << " arg " << i << " type=" << args[i] << std::endl;
252 
253  error_msgs << "available function signatures for "
254  << name << ":" << std::endl;
255  for (size_t i = 0; i < signatures.size(); ++i) {
256  error_msgs << i << ". " << name << "(";
257  for (size_t j = 0; j < signatures[i].second.size(); ++j) {
258  if (j > 0) error_msgs << ", ";
259  error_msgs << signatures[i].second[j];
260  }
261  error_msgs << ") : " << signatures[i].first << std::endl;
262  }
263  return expr_type(); // ill-formed dummy
264  }
265  function_signatures::function_signatures() {
267  }
268  function_signatures* function_signatures::sigs_ = 0;
269 
270 
271 
273  statements::statements(const std::vector<var_decl>& local_decl,
274  const std::vector<statement>& stmts)
275  : local_decl_(local_decl),
276  statements_(stmts) {
277  }
278 
280  return expr_type();
281  }
282  // template <typename T>
283  // expr_type expression_type_vis::operator()(const T& e) const {
284  // return e.type_;
285  // }
287  return e.type_;
288  }
290  return e.type_;
291  }
293  return e.type_;
294  }
296  return e.type_;
297  }
299  return e.type_;
300  }
302  return e.type_;
303  }
305  return e.type_;
306  }
308  return e.type_;
309  }
310 
312  : expr_(nil()) {
313  }
315  : expr_(e.expr_) {
316  }
319  return boost::apply_visitor(vis,expr_);
320  }
321  // template <typename Expr>
322  // expression::expression(const Expr& expr) : expr_(expr) { }
323 
324  expression::expression(const expression_t& expr) : expr_(expr) { }
325  expression::expression(const nil& expr) : expr_(expr) { }
326  expression::expression(const int_literal& expr) : expr_(expr) { }
327  expression::expression(const double_literal& expr) : expr_(expr) { }
328  expression::expression(const array_literal& expr) : expr_(expr) { }
329  expression::expression(const variable& expr) : expr_(expr) { }
330  expression::expression(const fun& expr) : expr_(expr) { }
331  expression::expression(const index_op& expr) : expr_(expr) { }
332  expression::expression(const binary_op& expr) : expr_(expr) { }
333  expression::expression(const unary_op& expr) : expr_(expr) { }
334 
335  printable::printable() : printable_("") { }
336  printable::printable(const expression& expr) : printable_(expr) { }
337  printable::printable(const std::string& msg) : printable_(msg) { }
339  : printable_(printable) { }
341  : printable_(printable.printable_) { }
342 
343  // contains_var::contains_var(const variable_map& var_map)
344  // : var_map_(var_map) {
345  // }
346  // bool contains_var::operator()(const nil& e) const {
347  // return false;
348  // }
349  // bool contains_var::operator()(const int_literal& e) const {
350  // return false;
351  // }
352  // bool contains_var::operator()(const double_literal& e) const {
353  // return false;
354  // }
355  // bool contains_var::operator()(const array_literal& e) const {
356  // for (size_t i = 0; i < e.args_.size(); ++i)
357  // if (boost::apply_visitor(*this,e.args_[i]);
358  // return true;
359  // return false;
360  // }
361  // bool contains_var::operator()(const variable& e) const {
362  // var_origin vo = variable_map_.get_origin(e.name_);
363  // return vo == parameter_origin
364  // || vo == transformed_paramter_origin
365  // || vo == local_origin;
366  // }
367  // bool contains_var::operator()(const fun& e) const {
368  // for (size_t i = 0; i < e.args_.size(); ++i)
369  // if (boost::apply_visitor(*this,e.args_[i]))
370  // return true;
371  // return false;
372  // }
373  // bool contains_var::operator()(const index_op& e) const {
374  // if (boost::apply_visitor(*this,e.expr_))
375  // return true;
376  // for (size_t i = 0; i < e.dimss_.size(); ++i)
377  // for (size_t j = 0; j < e.dimss_[i].size(); ++j)
378  // if (boost::apply_visitor(*this,e.dims_[i][j]))
379  // return true;
380  // return false;
381  // }
382  // bool contains_var::operator()(const binary_op& e) const {
383  // return boost::apply_visitor(*this,e.left)
384  // || apply_visitor(*this,e.right);
385  // }
386  // bool contains_var::operator()(const unary_op& e) const {
387  // return boost::apply_visitor(*this,e.subject);
388  // }
389 
390  bool is_nil_op::operator()(const nil& /*x*/) const { return true; }
391  bool is_nil_op::operator()(const int_literal& /*x*/) const { return false; }
392  bool is_nil_op::operator()(const double_literal& /* x */) const { return false; }
393  bool is_nil_op::operator()(const array_literal& /* x */) const { return false; }
394  bool is_nil_op::operator()(const variable& /* x */) const { return false; }
395  bool is_nil_op::operator()(const fun& /* x */) const { return false; }
396  bool is_nil_op::operator()(const index_op& /* x */) const { return false; }
397  bool is_nil_op::operator()(const binary_op& /* x */) const { return false; }
398  bool is_nil_op::operator()(const unary_op& /* x */) const { return false; }
399 
400  // template <typename T>
401  // bool is_nil_op::operator()(const T& /* x */) const { return false; }
402 
403  bool is_nil(const expression& e) {
404  is_nil_op ino;
405  return boost::apply_visitor(ino,e.expr_);
406  }
407 
408  variable_dims::variable_dims() { } // req for FUSION_ADAPT
409  variable_dims::variable_dims(std::string const& name,
410  std::vector<expression> const& dims)
411  : name_(name),
412  dims_(dims) {
413  }
414 
415 
417  : type_(INT_T) {
418  }
420  : val_(val),
421  type_(INT_T) {
422  }
424  : val_(il.val_),
425  type_(il.type_) {
426  }
428  val_ = il.val_;
429  type_ = il.type_;
430  return *this;
431  }
432 
433 
435  : type_(DOUBLE_T,0U) {
436  }
438  : val_(val),
439  type_(DOUBLE_T,0U) {
440  }
442  val_ = dl.val_;
443  type_ = dl.type_;
444  return *this;
445  }
446 
447 
449  : args_(),
450  type_(DOUBLE_T,1U) {
451  }
452  array_literal::array_literal(const std::vector<expression>& args)
453  : args_(args),
454  type_() { // ill-formed w/o help
455  }
457  args_ = al.args_;
458  type_ = al.type_;
459  return *this;
460  }
461 
463  variable::variable(std::string name) : name_(name) { }
464  void variable::set_type(const base_expr_type& base_type,
465  size_t num_dims) {
466  type_ = expr_type(base_type, num_dims);
467  }
468 
469 
470  fun::fun() { }
471  fun::fun(std::string const& name,
472  std::vector<expression> const& args)
473  : name_(name),
474  args_(args) {
475  infer_type();
476  }
478  // FIXME: remove this useless function and any calls to it
479  }
480 
481 
482  size_t total_dims(const std::vector<std::vector<expression> >& dimss) {
483  size_t total = 0U;
484  for (size_t i = 0; i < dimss.size(); ++i)
485  total += dimss[i].size();
486  return total;
487  }
488 
489 
491  size_t num_expr_dims,
492  size_t num_index_dims) {
493  if (num_index_dims <= num_expr_dims)
494  return expr_type(expr_base_type,num_expr_dims - num_index_dims);
495  if (num_index_dims == (num_expr_dims + 1)) {
496  if (expr_base_type == VECTOR_T || expr_base_type == ROW_VECTOR_T)
497  return expr_type(DOUBLE_T,0U);
498  if (expr_base_type == MATRIX_T)
499  return expr_type(ROW_VECTOR_T,0U);
500  }
501  if (num_index_dims == (num_expr_dims + 2))
502  if (expr_base_type == MATRIX_T)
503  return expr_type(DOUBLE_T,0U);
504 
505  // error condition, result expr_type has is_ill_formed() = true
506  return expr_type();
507  }
508 
510  size_t num_index_dims) {
512  expr.expression_type().num_dims(),
513  num_index_dims);
514  }
515 
516 
519  const std::vector<std::vector<expression> >& dimss)
520  : expr_(expr),
521  dimss_(dimss) {
522  infer_type();
523  }
526  }
527 
530  const std::string& op,
531  const expression& right)
532  : op(op),
533  left(left),
534  right(right),
535  type_(promote_primitive(left.expression_type(),
536  right.expression_type())) {
537  }
538 
539 
541  expression const& subject)
542  : op(op),
543  subject(subject),
544  type_(promote_primitive(subject.expression_type())) {
545  }
546 
547 
550  expression const& high)
551  : low_(low),
552  high_(high) {
553  }
554  bool range::has_low() const {
555  return !is_nil(low_.expr_);
556  }
557  bool range::has_high() const {
558  return !is_nil(high_.expr_);
559  }
560 
561  void print_var_origin(std::ostream& o, const var_origin& vo) {
562  if (vo == data_origin)
563  o << "data";
564  else if (vo == transformed_data_origin)
565  o << "transformed data";
566  else if (vo == parameter_origin)
567  o << "parameter";
568  else if (vo == transformed_parameter_origin)
569  o << "transformed parameter";
570  else if (vo == derived_origin)
571  o << "generated quantities";
572  else if (vo == local_origin)
573  o << "local";
574  else
575  o << "UNKNOWN ORIGIN";
576  }
577 
578 
581  : base_type_(base_type) {
582  }
583  base_var_decl::base_var_decl(const std::string& name,
584  const std::vector<expression>& dims,
585  const base_expr_type& base_type)
586  : name_(name),
587  dims_(dims),
588  base_type_(base_type) {
589  }
590 
591  bool variable_map::exists(const std::string& name) const {
592  return map_.find(name) != map_.end();
593  }
594  base_var_decl variable_map::get(const std::string& name) const {
595  if (!exists(name))
596  throw std::invalid_argument("variable does not exist");
597  return map_.find(name)->second.first;
598  }
599  base_expr_type variable_map::get_base_type(const std::string& name) const {
600  return get(name).base_type_;
601  }
602  size_t variable_map::get_num_dims(const std::string& name) const {
603  return get(name).dims_.size();
604  }
605  var_origin variable_map::get_origin(const std::string& name) const {
606  if (!exists(name))
607  throw std::invalid_argument("variable does not exist");
608  return map_.find(name)->second.second;
609  }
610  void variable_map::add(const std::string& name,
611  const base_var_decl& base_decl,
612  const var_origin& vo) {
613  map_[name] = range_t(base_decl,vo);
614  }
615  void variable_map::remove(const std::string& name) {
616  map_.erase(name);
617  }
618 
620  : base_var_decl(INT_T)
621  { }
622 
624  std::string const& name,
625  std::vector<expression> const& dims)
626  : base_var_decl(name,dims,INT_T),
627  range_(range)
628  { }
629 
630 
631 
634  { }
635 
637  std::string const& name,
638  std::vector<expression> const& dims)
639  : base_var_decl(name,dims,DOUBLE_T),
640  range_(range)
641  { }
642 
645  { }
646 
648  std::string const& name,
649  std::vector<expression> const& dims)
650  : base_var_decl(name,dims,VECTOR_T),
651  K_(K)
652  { }
653 
656  { }
657 
659  std::string const& name,
660  std::vector<expression> const& dims)
661  : base_var_decl(name,dims,VECTOR_T),
662  K_(K)
663  { }
664 
667  { }
668 
670  std::string const& name,
671  std::vector<expression> const& dims)
672  : base_var_decl(name,dims,VECTOR_T),
673  K_(K) {
674  }
675 
678  { }
679 
681  std::string const& name,
682  std::vector<expression> const& dims)
683  : base_var_decl(name,dims,VECTOR_T),
684  K_(K) {
685  }
686 
688 
690  expression const& M,
691  std::string const& name,
692  std::vector<expression> const& dims)
693  : base_var_decl(name,dims,VECTOR_T),
694  range_(range),
695  M_(M) {
696  }
697 
700  expression const& N,
701  std::string const& name,
702  std::vector<expression> const& dims)
703  : base_var_decl(name,dims,ROW_VECTOR_T),
704  range_(range),
705  N_(N) {
706  }
707 
710  expression const& M,
711  expression const& N,
712  std::string const& name,
713  std::vector<expression> const& dims)
714  : base_var_decl(name,dims,MATRIX_T),
715  range_(range),
716  M_(M),
717  N_(N) {
718  }
719 
720 
722  }
724  std::string const& name,
725  std::vector<expression> const& dims)
726  : base_var_decl(name,dims,MATRIX_T),
727  K_(K) {
728  }
729 
732  std::string const& name,
733  std::vector<expression> const& dims)
734  : base_var_decl(name,dims,MATRIX_T),
735  K_(K) {
736  }
737 
738 
739 
740 
742  std::string name_vis::operator()(const nil& /* x */) const {
743  return ""; // fail if arises
744  }
745  std::string name_vis::operator()(const int_var_decl& x) const {
746  return x.name_;
747  }
748  std::string name_vis::operator()(const double_var_decl& x) const {
749  return x.name_;
750  }
751  std::string name_vis::operator()(const vector_var_decl& x) const {
752  return x.name_;
753  }
754  std::string name_vis::operator()(const row_vector_var_decl& x) const {
755  return x.name_;
756  }
757  std::string name_vis::operator()(const matrix_var_decl& x) const {
758  return x.name_;
759  }
760  std::string name_vis::operator()(const unit_vector_var_decl& x) const {
761  return x.name_;
762  }
763  std::string name_vis::operator()(const simplex_var_decl& x) const {
764  return x.name_;
765  }
766  std::string name_vis::operator()(const ordered_var_decl& x) const {
767  return x.name_;
768  }
769  std::string name_vis::operator()(const positive_ordered_var_decl& x) const {
770  return x.name_;
771  }
772  std::string name_vis::operator()(const cov_matrix_var_decl& x) const {
773  return x.name_;
774  }
775  std::string name_vis::operator()(const corr_matrix_var_decl& x) const {
776  return x.name_;
777  }
778 
779 
780 
781 
782 
783 
784  var_decl::var_decl(const var_decl_t& decl) : decl_(decl) { }
785  var_decl::var_decl() : decl_(nil()) { }
786  var_decl::var_decl(const nil& decl) : decl_(decl) { }
787  var_decl::var_decl(const int_var_decl& decl) : decl_(decl) { }
788  var_decl::var_decl(const double_var_decl& decl) : decl_(decl) { }
789  var_decl::var_decl(const vector_var_decl& decl) : decl_(decl) { }
790  var_decl::var_decl(const row_vector_var_decl& decl) : decl_(decl) { }
791  var_decl::var_decl(const matrix_var_decl& decl) : decl_(decl) { }
792  var_decl::var_decl(const unit_vector_var_decl& decl) : decl_(decl) { }
793  var_decl::var_decl(const simplex_var_decl& decl) : decl_(decl) { }
794  var_decl::var_decl(const ordered_var_decl& decl) : decl_(decl) { }
795  var_decl::var_decl(const positive_ordered_var_decl& decl) : decl_(decl) { }
796  var_decl::var_decl(const cov_matrix_var_decl& decl) : decl_(decl) { }
797  var_decl::var_decl(const corr_matrix_var_decl& decl) : decl_(decl) { }
798 
799  // template <typename Decl>
800  // var_decl::var_decl(Decl const& decl) : decl_(decl) { }
801 
802 
803 
804  std::string var_decl::name() const {
805  return boost::apply_visitor(name_vis(),decl_);
806  }
807 
808  statement::statement() : statement_(nil()) { }
809 
810  // FIXME: template these out
811  statement::statement(const statement_t& st) : statement_(st) { }
812  statement::statement(const nil& st) : statement_(st) { }
813  statement::statement(const assignment& st) : statement_(st) { }
814  statement::statement(const sample& st) : statement_(st) { }
815  statement::statement(const statements& st) : statement_(st) { }
816  statement::statement(const for_statement& st) : statement_(st) { }
817  statement::statement(const while_statement& st) : statement_(st) { }
818  statement::statement(const conditional_statement& st) : statement_(st) { }
819  statement::statement(const print_statement& st) : statement_(st) { }
820  statement::statement(const no_op_statement& st) : statement_(st) { }
821 
822  // template <typename Statement>
823  // statement::statement(const Statement& statement)
824  // : statement_(statement) {
825  // }
826 
827 
828 
829 
831  }
833  range& range,
834  statement& stmt)
835  : variable_(variable),
836  range_(range),
837  statement_(stmt) {
838  }
839 
841  }
843  const statement& body)
844  : condition_(condition),
845  body_(body) {
846  }
847 
849  }
851  ::conditional_statement(const std::vector<expression>& conditions,
852  const std::vector<statement>& bodies)
853  : conditions_(conditions),
854  bodies_(bodies) {
855  }
856 
858 
859  print_statement::print_statement(const std::vector<printable>& printables)
860  : printables_(printables) {
861  }
862 
864  program::program(const std::vector<var_decl>& data_decl,
865  const std::pair<std::vector<var_decl>,
866  std::vector<statement> >& derived_data_decl,
867  const std::vector<var_decl>& parameter_decl,
868  const std::pair<std::vector<var_decl>,
869  std::vector<statement> >& derived_decl,
870  const statement& st,
871  const std::pair<std::vector<var_decl>,
872  std::vector<statement> >& generated_decl)
873  : data_decl_(data_decl),
874  derived_data_decl_(derived_data_decl),
875  parameter_decl_(parameter_decl),
876  derived_decl_(derived_decl),
877  statement_(st),
878  generated_decl_(generated_decl) {
879  }
880 
882  }
884  distribution& dist)
885  : expr_(e),
886  dist_(dist) {
887  }
888  bool sample::is_ill_formed() const {
890  || ( truncation_.has_low()
891  && expr_.expression_type()
893  || ( truncation_.has_high()
894  && expr_.expression_type()
896  }
897 
899  }
901  expression& expr)
902  : var_dims_(var_dims),
903  expr_(expr) {
904  }
905 
907  expr_ = binary_op(expr_, "+", rhs);
908  return *this;
909  }
910 
912  expr_ = binary_op(expr_, "-", rhs);
913  return *this;
914  }
915 
917  expr_ = binary_op(expr_, "*", rhs);
918  return *this;
919  }
920 
922  expr_ = binary_op(expr_, "/", rhs);
923  return *this;
924  }
925 
926  bool has_rng_suffix(const std::string& s) {
927  int n = s.size();
928  return n > 4
929  && s[n-1] == 'g'
930  && s[n-2] == 'n'
931  && s[n-3] == 'r'
932  && s[n-4] == '_';
933  }
934 
935 
936  }
937 }
938 
939 
940 #endif

     [ Stan Home Page ] © 2011–2013, Stan Development Team.