Automatic Differentiation
 
Loading...
Searching...
No Matches
lmgamma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_LMGAMMA_HPP
2#define STAN_MATH_FWD_FUN_LMGAMMA_HPP
3
8#include <cmath>
9
10namespace stan {
11namespace math {
12
13template <typename T>
14inline fvar<return_type_t<T, int>> lmgamma(int x1, const fvar<T>& x2) {
15 T deriv = 0;
16 for (int count = 1; count < x1 + 1; count++) {
17 deriv += x2.d_ * digamma(x2.val_ + (1.0 - count) / 2.0);
18 }
19 return fvar<return_type_t<T, int>>(lmgamma(x1, x2.val_), deriv);
20}
21} // namespace math
22} // namespace stan
23#endif
fvar< return_type_t< T, int > > lmgamma(int x1, const fvar< T > &x2)
Definition lmgamma.hpp:14
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 ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40