Automatic Differentiation
 
Loading...
Searching...
No Matches
lgamma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_LGAMMA_HPP
2#define STAN_MATH_REV_FUN_LGAMMA_HPP
3
8
9namespace stan {
10namespace math {
11
23template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr>
24inline auto lgamma(const var_value<T>& a) {
25 return make_callback_var(lgamma(a.val()), [a](auto& vi) mutable {
26 as_array_or_scalar(a.adj())
27 += as_array_or_scalar(vi.adj()) * as_array_or_scalar(digamma(a.val()));
28 });
29}
30
31} // namespace math
32} // namespace stan
33#endif
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
Definition lgamma.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...