Stan  2.14.0
probability, sampling & optimization
expr_type_def.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_AST_EXPR_TYPE_DEF_HPP
2 #define STAN_LANG_AST_EXPR_TYPE_DEF_HPP
3 
7 #include <ostream>
8 
9 namespace stan {
10  namespace lang {
11 
12  expr_type::expr_type() : base_type_(ILL_FORMED_T), num_dims_(0) { }
13 
15  : base_type_(base_type), num_dims_(0) { }
16 
17  expr_type::expr_type(const base_expr_type base_type, size_t num_dims)
18  : base_type_(base_type), num_dims_(num_dims) { }
19 
20  bool expr_type::operator==(const expr_type& et) const {
21  return base_type_ == et.base_type_ && num_dims_ == et.num_dims_;
22  }
23 
24  bool expr_type::operator!=(const expr_type& et) const {
25  return !(*this == et);
26  }
27 
28  bool expr_type::operator<(const expr_type& et) const {
29  return base_type_ < et.base_type_
30  || (base_type_ == et.base_type_ && num_dims_ < et.num_dims_);
31  }
32 
33  bool expr_type::operator<=(const expr_type& et) const {
34  return base_type_ < et.base_type_
35  || (base_type_ == et.base_type_ && num_dims_ <= et.num_dims_);
36  }
37 
38  bool expr_type::operator>(const expr_type& et) const {
39  return base_type_ > et.base_type_
40  || (base_type_ == et.base_type_ && num_dims_ > et.num_dims_);
41  }
42 
43  bool expr_type::operator>=(const expr_type& et) const {
44  return base_type_ > et.base_type_
45  || (base_type_ == et.base_type_ && num_dims_ >= et.num_dims_);
46  }
47 
48  bool expr_type::is_primitive() const {
50  }
51 
53  return base_type_ == INT_T && num_dims_ == 0U;
54  }
55 
57  return base_type_ == DOUBLE_T && num_dims_ == 0U;
58  }
59 
60  bool expr_type::is_ill_formed() const {
61  return base_type_ == ILL_FORMED_T;
62  }
63 
64  bool expr_type::is_void() const {
65  return base_type_ == VOID_T;
66  }
67 
69  return base_type_;
70  }
71 
72  size_t expr_type::num_dims() const {
73  return num_dims_;
74  }
75 
76  std::ostream& operator<<(std::ostream& o, const expr_type& et) {
77  write_base_expr_type(o, et.type());
78  if (et.num_dims() > 0) {
79  o << '[';
80  for (size_t i = 1; i < et.num_dims(); ++i) o << ",";
81  o << ']';
82  }
83  return o;
84  }
85 
86  }
87 }
88 #endif
bool is_primitive_int() const
Return true if this expression type is an integer type with zero dimensions.
bool is_ill_formed() const
Return true if the base type of this type is ill formed.
std::size_t num_dims_
The number of array dimensions.
Definition: expr_type.hpp:23
Probability, optimization and sampling library.
bool operator<=(const expr_type &et) const
Return true if this expression type is less than or equal to the specified expression type...
std::size_t num_dims() const
Return the number of dimensions for this type.
bool operator<(const expr_type &et) const
Return true if this expression type is less than the specified expression type.
const int DOUBLE_T
Real scalar type.
bool is_primitive_double() const
Return true if this expression type is a real type with zero dimensions.
int base_expr_type
The type of a base expression.
Structure of the type of an expression, which consists of a base type and a number of dimensions...
Definition: expr_type.hpp:14
bool operator!=(const expr_type &et) const
Return true if this expression type is not equal to the specified expression type.
bool operator>(const expr_type &et) const
Return true if this expression type is greater than the specified expression type.
base_expr_type type() const
Return the base type of this expression type.
expr_type()
Construct an empty expression type.
const int VOID_T
Void type.
bool operator>=(const expr_type &et) const
Return true if this expression type is greater than or equal to the specified expression type...
std::ostream & operator<<(std::ostream &o, const expr_type &et)
Stream a user-readable version of the expression type to the specified output stream, returning the speicifed argument output stream to allow chaining.
base_expr_type base_type_
The base expression type.
Definition: expr_type.hpp:18
const int INT_T
Integer type.
bool is_primitive() const
Return true if this expression type is an integer or real type with zero dimensions.
std::ostream & write_base_expr_type(std::ostream &o, base_expr_type type)
Write a user-readable version of the specified base expression type to the specified output stream...
bool is_void() const
Return true if this type is void.
bool operator==(const expr_type &et) const
Return true if the specified expression type is equal to this expression type in the sense of having ...
const int ILL_FORMED_T
Type denoting an ill-formed expression.

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