Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
operator_unary_negative.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_NEGATIVE_HPP
2 #define STAN__AGRAD__REV__OPERATORS__OPERATOR_UNARY_NEGATIVE_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 neg_vari : public op_v_vari {
13  public:
14  neg_vari(vari* avi) :
15  op_v_vari(-(avi->val_), 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 
50  inline var operator-(const var& a) {
51  return var(new neg_vari(a.vi_));
52  }
53 
54  }
55 }
56 #endif
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
fvar< T > operator-(const fvar< T > &x1, const fvar< T > &x2)
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.