Automatic Differentiation
 
Loading...
Searching...
No Matches
lmgamma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_LMGAMMA_HPP
2#define STAN_MATH_REV_FUN_LMGAMMA_HPP
3
8
9namespace stan {
10namespace math {
11
12namespace internal {
14 public:
15 lmgamma_dv_vari(int a, vari* bvi)
16 : op_dv_vari(lmgamma(a, bvi->val_), a, bvi) {}
17 void chain() {
18 double deriv = 0;
19 for (int i = 1; i < ad_ + 1; i++) {
20 deriv += digamma(bvi_->val_ + (1.0 - i) / 2.0);
21 }
22 bvi_->adj_ += adj_ * deriv;
23 }
24};
25} // namespace internal
26
27inline var lmgamma(int a, const var& b) {
28 return var(new internal::lmgamma_dv_vari(a, b.vi_));
29}
30
31} // namespace math
32} // namespace stan
33#endif
fvar< return_type_t< T, int > > lmgamma(int x1, const fvar< T > &x2)
Definition lmgamma.hpp:14
var_value< double > var
Definition var.hpp:1187
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...