Stan  2.14.0
probability, sampling & optimization
expression_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_NODE_EXPRESSION_DEF_HPP
2 #define STAN_LANG_AST_NODE_EXPRESSION_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 
6 
7 namespace stan {
8  namespace lang {
9 
11  : expr_(nil()) {
12  }
13 
15  : expr_(e.expr_) {
16  }
17 
18  expression::expression(const expression_t& expr) : expr_(expr) { }
19 
20  expression::expression(const nil& expr) : expr_(expr) { }
21 
22  expression::expression(const int_literal& expr) : expr_(expr) { }
23 
24  expression::expression(const double_literal& expr) : expr_(expr) { }
25 
26  expression::expression(const array_expr& expr) : expr_(expr) { }
27 
28  expression::expression(const variable& expr) : expr_(expr) { }
29 
30  expression::expression(const integrate_ode& expr) : expr_(expr) { }
31 
33 
34  expression::expression(const fun& expr) : expr_(expr) { }
35 
36  expression::expression(const index_op& expr) : expr_(expr) { }
37 
38  expression::expression(const index_op_sliced& expr) : expr_(expr) { }
39 
40  expression::expression(const conditional_op& expr) : expr_(expr) { }
41 
42  expression::expression(const binary_op& expr) : expr_(expr) { }
43 
44  expression::expression(const unary_op& expr) : expr_(expr) { }
45 
47  expr_ = binary_op(expr_, "+", rhs);
48  return *this;
49  }
50 
52  expr_ = binary_op(expr_, "-", rhs);
53  return *this;
54  }
55 
57  expr_ = binary_op(expr_, "*", rhs);
58  return *this;
59  }
60 
62  expr_ = binary_op(expr_, "/", rhs);
63  return *this;
64  }
65 
68  return boost::apply_visitor(vis, expr_);
69  }
70 
71  int expression::total_dims() const {
72  int sum = expression_type().num_dims_;
73  if (expression_type().type() == VECTOR_T)
74  ++sum;
75  if (expression_type().type() == ROW_VECTOR_T)
76  ++sum;
77  if (expression_type().type() == MATRIX_T)
78  sum += 2;
79  return sum;
80  }
81 
82  }
83 }
84 #endif
const int ROW_VECTOR_T
Row vector type; scalar type is real.
expression & operator-=(const expression &rhs)
std::size_t num_dims_
The number of array dimensions.
Definition: expr_type.hpp:23
Node for holding a double literal.
Probability, optimization and sampling library.
Structure to hold an array expression.
Definition: array_expr.hpp:17
Structure for an indexed expression.
Definition: index_op.hpp:14
Callback functor for calculating expression types from the variant types making up an expression...
Structure for function application.
Definition: fun.hpp:17
Structure of the type of an expression, which consists of a base type and a number of dimensions...
Definition: expr_type.hpp:14
Structure for integrate diff eq statement.
expr_type expression_type() const
expression & operator*=(const expression &rhs)
expression & operator+=(const expression &rhs)
boost::variant< boost::recursive_wrapper< nil >, boost::recursive_wrapper< int_literal >, boost::recursive_wrapper< double_literal >, boost::recursive_wrapper< array_expr >, boost::recursive_wrapper< variable >, boost::recursive_wrapper< integrate_ode >, boost::recursive_wrapper< integrate_ode_control >, boost::recursive_wrapper< fun >, boost::recursive_wrapper< index_op >, boost::recursive_wrapper< index_op_sliced >, boost::recursive_wrapper< conditional_op >, boost::recursive_wrapper< binary_op >, boost::recursive_wrapper< unary_op > > expression_t
Definition: expression.hpp:55
AST structure for holding an expression with a sequence of indexes.
Structure for the conditional operator.
const int VECTOR_T
Column vector type; scalar type is real.
Structure to hold a variable.
Definition: variable.hpp:14
AST structure for unary operations consisting of an operation and argument.
Definition: unary_op.hpp:14
Node for storing binary operations consisting of an operation and left and right arguments.
Definition: binary_op.hpp:15
The nil structure used as a placeholder for undefined or empty values in several structures.
Definition: nil.hpp:11
const int MATRIX_T
Matrix type; scalar type is real.
expression & operator/=(const expression &rhs)
Structure for a diff eq integration statement with control parameters for the integrator.

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