Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
12
13namespace stan {
14namespace math {
15
28template <typename Ta, typename Tb, typename Tz,
29 typename FvarT = return_type_t<Ta, Tb, Tz>,
30 bool grad_a = !is_constant<Ta>::value,
31 bool grad_b = !is_constant<Tb>::value,
32 bool grad_z = !is_constant<Tz>::value,
33 require_all_vector_t<Ta, Tb>* = nullptr,
34 require_fvar_t<FvarT>* = nullptr>
35inline FvarT hypergeometric_pFq(Ta&& a, Tb&& b, Tz&& z) {
36 auto&& a_ref = to_ref(as_column_vector_or_scalar(a));
37 auto&& b_ref = to_ref(as_column_vector_or_scalar(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
42 partials_type_t<FvarT> pfq_val = hypergeometric_pFq(a_val, b_val, z_val);
43 auto grad_tuple
44 = grad_pFq<grad_a, grad_b, grad_z>(pfq_val, a_val, b_val, z_val);
45
46 FvarT rtn = FvarT(pfq_val, 0.0);
47
48 if constexpr (grad_a) {
49 rtn.d_ += dot_product(a_ref.d(), std::get<0>(grad_tuple));
50 }
51 if constexpr (grad_b) {
52 rtn.d_ += dot_product(b_ref.d(), std::get<1>(grad_tuple));
53 }
54 if constexpr (grad_z) {
55 rtn.d_ += z.d_ * std::get<2>(grad_tuple);
56 }
57
58 return rtn;
59}
60
61} // namespace math
62} // namespace stan
63#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
typename partials_type< T >::type partials_type_t
Helper alias for accessing the partial type.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
FvarT hypergeometric_pFq(Ta &&a, Tb &&b, 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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...