Stan Math Library  2.9.0
reverse mode automatic differentiation
lmgamma.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_LMGAMMA_HPP
2 #define STAN_MATH_REV_SCAL_FUN_LMGAMMA_HPP
3 
4 #include <stan/math/rev/core.hpp>
8 #include <valarray>
9 
10 namespace stan {
11  namespace math {
12 
13  namespace {
14  class lmgamma_dv_vari : public op_dv_vari {
15  public:
16  lmgamma_dv_vari(int a, vari* bvi) :
17  op_dv_vari(stan::math::lmgamma(a, bvi->val_), a, bvi) {
18  }
19  void chain() {
20  double deriv = 0;
21  for (int i = 1; i < ad_ + 1; i++)
22  deriv += stan::math::digamma(bvi_->val_ + (1.0 - i) / 2.0);
23  bvi_->adj_ += adj_ * deriv;
24  }
25  };
26  }
27 
28  inline var lmgamma(int a, const stan::math::var& b) {
29  return var(new lmgamma_dv_vari(a, b.vi_));
30  }
31 
32  }
33 }
34 #endif
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
fvar< typename stan::return_type< T, int >::type > lmgamma(int x1, const fvar< T > &x2)
Definition: lmgamma.hpp:16
fvar< T > digamma(const fvar< T > &x)
Definition: digamma.hpp:16

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