Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
operator_unary_increment.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_INCREMENT_HPP
2 #define STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_INCREMENT_HPP
3 
4 #include <stan/agrad/rev/var.hpp>
6 #include <boost/math/special_functions/fpclassify.hpp>
7 
8 namespace stan {
9  namespace agrad {
10 
11  namespace {
12  class increment_vari : public op_v_vari {
13  public:
14  increment_vari(vari* avi) :
15  op_v_vari(avi->val_ + 1.0, avi) {
16  }
17  void chain() {
18  if (unlikely(boost::math::isnan(avi_->val_)))
19  avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
20  else
21  avi_->adj_ += adj_;
22  }
23  };
24  }
25 
35  inline var& operator++(var& a) {
36  a.vi_ = new increment_vari(a.vi_);
37  return a;
38  }
39 
51  inline var operator++(var& a, int /*dummy*/) {
52  var temp(a);
53  a.vi_ = new increment_vari(a.vi_);
54  return temp;
55  }
56 
57  }
58 }
59 #endif
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
var & operator++(var &a)
Prefix increment operator for variables (C++).
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
#define unlikely(x)
Definition: likely.hpp:9
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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