Automatic Differentiation
 
Loading...
Searching...
No Matches
hypergeometric_2F1.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_HYPERGEOMETRIC_2F1_HPP
2#define STAN_MATH_REV_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_var_t<Ta1, Ta2, Tb, Tz>* = nullptr>
32inline return_type_t<Ta1, Ta2, Tb, Tz> hypergeometric_2F1(const Ta1& a1,
33 const Ta2& a2,
34 const Tb& b,
35 const Tz& z) {
36 double a1_dbl = value_of(a1);
37 double a2_dbl = value_of(a2);
38 double b_dbl = value_of(b);
39 double z_dbl = value_of(z);
40
41 return make_callback_var(hypergeometric_2F1(a1_dbl, a2_dbl, b_dbl, z_dbl),
42 [a1, a2, b, z](auto& vi) mutable {
43 auto grad_tuple = grad_2F1(a1, a2, b, z);
44
45 if constexpr (is_autodiff_v<Ta1>) {
46 a1.adj() += vi.adj() * std::get<0>(grad_tuple);
47 }
48 if constexpr (is_autodiff_v<Ta2>) {
49 a2.adj() += vi.adj() * std::get<1>(grad_tuple);
50 }
51 if constexpr (is_autodiff_v<Tb>) {
52 b.adj() += vi.adj() * std::get<2>(grad_tuple);
53 }
54 if constexpr (is_autodiff_v<Tz>) {
55 z.adj() += vi.adj() * std::get<3>(grad_tuple);
56 }
57 });
58}
59} // namespace math
60} // namespace stan
61#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...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
return_type_t< Ta1, Ta2, 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: .
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:273
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...