Automatic Differentiation
 
Loading...
Searching...
No Matches
hypergeometric_pFq.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_HYPERGEOMETRIC_PFQ_HPP
2#define STAN_MATH_REV_FUN_HYPERGEOMETRIC_PFQ_HPP
3
9
10namespace stan {
11namespace math {
12
25template <typename Ta, typename Tb, typename Tz,
26 require_all_vector_t<Ta, Tb>* = nullptr,
27 require_return_type_t<is_var, Ta, Tb, Tz>* = nullptr>
28inline var hypergeometric_pFq(Ta&& a, Tb&& b, Tz&& z) {
29 constexpr bool grad_a = is_autodiff_v<Ta>;
30 constexpr bool grad_b = is_autodiff_v<Tb>;
31 constexpr bool grad_z = is_autodiff_v<Tz>;
32 auto arena_a = to_arena(as_column_vector_or_scalar(std::forward<Ta>(a)));
33 auto arena_b = to_arena(as_column_vector_or_scalar(std::forward<Tb>(b)));
34 auto pfq_val
35 = hypergeometric_pFq(value_of(arena_a), value_of(arena_b), value_of(z));
36 return make_callback_var(
37 pfq_val, [arena_a, arena_b, z, pfq_val](auto& vi) mutable {
38 auto grad_tuple = grad_pFq<grad_a, grad_b, grad_z>(
39 pfq_val, arena_a.val(), arena_b.val(), value_of(z));
40 if constexpr (grad_a) {
41 arena_a.adj() += vi.adj() * std::get<0>(grad_tuple);
42 }
43 if constexpr (grad_b) {
44 arena_b.adj() += vi.adj() * std::get<1>(grad_tuple);
45 }
46 if constexpr (grad_z) {
47 z.adj() += vi.adj() * std::get<2>(grad_tuple);
48 }
49 });
50}
51} // namespace math
52} // namespace stan
53#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
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
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
Definition to_arena.hpp:25
FvarT hypergeometric_pFq(Ta &&a, Tb &&b, Tz &&z)
Returns the generalized hypergeometric (pFq) function applied to the input arguments.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...