Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
operator_unary_decrement.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_DECREMENT_HPP
2 #define STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_DECREMENT_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 decrement_vari : public op_v_vari {
13  public:
14  decrement_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 
39  inline var& operator--(var& a) {
40  a.vi_ = new decrement_vari(a.vi_);
41  return a;
42  }
43 
55  inline var operator--(var& a, int /*dummy*/) {
56  var temp(a);
57  a.vi_ = new decrement_vari(a.vi_);
58  return temp;
59  }
60 
61  }
62 }
63 #endif
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
var & operator--(var &a)
Prefix decrement operator for variables (C++).
#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.