Stan Math Library  2.11.0
reverse mode automatic differentiation
lgamma.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_LGAMMA_HPP
2 #define STAN_MATH_REV_SCAL_FUN_LGAMMA_HPP
3 
4 #include <stan/math/rev/core.hpp>
6 #include <boost/math/special_functions/digamma.hpp>
7 #include <boost/math/special_functions/gamma.hpp>
8 #include <valarray>
9 
10 namespace stan {
11  namespace math {
12 
13  namespace {
14  class lgamma_vari : public op_v_vari {
15  public:
16  lgamma_vari(double value, vari* avi) :
17  op_v_vari(value, avi) {
18  }
19  void chain() {
20  avi_->adj_ += adj_ * boost::math::digamma(avi_->val_);
21  }
22  };
23  }
24 
35  inline var lgamma(const stan::math::var& a) {
36  double lgamma_a = boost::math::lgamma(a.val());
37  return var(new lgamma_vari(lgamma_a, a.vi_));
38  }
39 
40  }
41 }
42 #endif
fvar< T > lgamma(const fvar< T > &x)
Definition: lgamma.hpp:15
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
var lgamma(const stan::math::var &a)
The log gamma function for variables (C99).
Definition: lgamma.hpp:35
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
double val() const
Return the value of this variable.
Definition: var.hpp:233
fvar< T > digamma(const fvar< T > &x)
Definition: digamma.hpp:16

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