Automatic Differentiation
 
Loading...
Searching...
No Matches
hypergeometric_pFq.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_HYPERGEOMETRIC_PFQ_HPP
2#define STAN_MATH_FWD_FUN_HYPERGEOMETRIC_PFQ_HPP
3
8
9namespace stan {
10namespace math {
11
24template <typename Ta, typename Tb, typename Tz,
25 typename FvarT = return_type_t<Ta, Tb, Tz>,
26 bool grad_a = !is_constant<Ta>::value,
27 bool grad_b = !is_constant<Tb>::value,
28 bool grad_z = !is_constant<Tz>::value,
29 require_all_vector_t<Ta, Tb>* = nullptr,
30 require_fvar_t<FvarT>* = nullptr>
31inline FvarT hypergeometric_pFq(const Ta& a, const Tb& b, const Tz& z) {
32 using PartialsT = partials_type_t<FvarT>;
33 using ARefT = ref_type_t<Ta>;
34 using BRefT = ref_type_t<Tb>;
35
36 ARefT a_ref = a;
37 BRefT b_ref = b;
38 auto&& a_val = value_of(a_ref);
39 auto&& b_val = value_of(b_ref);
40 auto&& z_val = value_of(z);
41 PartialsT pfq_val = hypergeometric_pFq(a_val, b_val, z_val);
42 auto grad_tuple
43 = grad_pFq<grad_a, grad_b, grad_z>(pfq_val, a_val, b_val, z_val);
44
45 FvarT rtn = FvarT(pfq_val, 0.0);
46
47 if (grad_a) {
49 std::get<0>(grad_tuple));
50 }
51 if (grad_b) {
53 std::get<1>(grad_tuple));
54 }
55 if (grad_z) {
56 rtn.d_ += forward_as<promote_scalar_t<FvarT, Tz>>(z).d_
57 * std::get<2>(grad_tuple);
58 }
59
60 return rtn;
61}
62
63} // namespace math
64} // namespace stan
65#endif
typename partials_type< T >::type partials_type_t
Helper alias for accessing the partial type.
T_actual && forward_as(T_actual &&a)
Assume which type we get.
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
FvarT hypergeometric_pFq(const Ta &a, const Tb &b, const Tz &z)
Returns the generalized hypergeometric (pFq) function applied to the input arguments.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...