Automatic Differentiation
 
Loading...
Searching...
No Matches
hypergeometric_2F1.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_HYPERGEOMETRIC_2F1_HPP
2#define STAN_MATH_FWD_FUN_HYPERGEOMETRIC_2F1_HPP
3
8
9namespace stan {
10namespace math {
11
29template <typename Ta1, typename Ta2, typename Tb, typename Tz,
30 require_all_stan_scalar_t<Ta1, Ta2, Tb, Tz>* = nullptr,
31 require_any_fvar_t<Ta1, Ta2, Tb, Tz>* = nullptr>
33 const Ta2& a2,
34 const Tb& b,
35 const Tz& z) {
37
38 auto a1_val = value_of(a1);
39 auto a2_val = value_of(a2);
40 auto b_val = value_of(b);
41 auto z_val = value_of(z);
42
43 auto grad_tuple = grad_2F1(a1, a2, b, z);
44
45 typename fvar_t::Scalar grad = 0;
46
48 grad += forward_as<fvar_t>(a1).d() * std::get<0>(grad_tuple);
49 }
51 grad += forward_as<fvar_t>(a2).d() * std::get<1>(grad_tuple);
52 }
54 grad += forward_as<fvar_t>(b).d() * std::get<2>(grad_tuple);
55 }
57 grad += forward_as<fvar_t>(z).d() * std::get<3>(grad_tuple);
58 }
59
60 return fvar_t(hypergeometric_2F1(a1_val, a2_val, b_val, z_val), grad);
61}
62
63} // namespace math
64} // namespace stan
65#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
return_type_t< Ta1, Ta1, Tb, Tz > hypergeometric_2F1(const Ta1 &a1, const Ta2 &a2, const Tb &b, const Tz &z)
Returns the Gauss hypergeometric function applied to the input arguments: .
static void grad()
Compute the gradient for all variables starting from the end of the AD tape.
Definition grad.hpp:26
auto grad_2F1(const T1 &a1, const T2 &a2, const T3 &b1, const T_z &z, double precision=1e-14, int max_steps=1e6)
Calculate the gradients of the hypergeometric function (2F1) as the power series stopping when the se...
Definition grad_2F1.hpp:271
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...