1 #ifndef STAN_MATH_FWD_SCAL_FUN_LMGAMMA_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_LMGAMMA_HPP
3 
4 #include <stan/math/fwd/core.hpp>
5 #include <stan/math/prim/scal/meta/return_type.hpp>
6 #include <stan/math/prim/scal/fun/digamma.hpp>
7 #include <stan/math/prim/scal/fun/lmgamma.hpp>
8 
9 namespace stan {
10 namespace math {
11 
12 template <typename T>
lmgamma(int x1,const fvar<T> & x2)13 inline fvar<typename stan::return_type<T, int>::type> lmgamma(
14     int x1, const fvar<T>& x2) {
15   using std::log;
16   T deriv = 0;
17   for (int count = 1; count < x1 + 1; count++)
18     deriv += x2.d_ * digamma(x2.val_ + (1.0 - count) / 2.0);
19   return fvar<typename stan::return_type<T, int>::type>(lmgamma(x1, x2.val_),
20                                                         deriv);
21 }
22 }  // namespace math
23 }  // namespace stan
24 #endif
25