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_PRIM_FUN_HYPERGEOMETRIC_PFQ_HPP
2#define STAN_MATH_PRIM_FUN_HYPERGEOMETRIC_PFQ_HPP
3
8#include <boost/math/special_functions/hypergeometric_pFq.hpp>
9
10namespace stan {
11namespace math {
12
25template <typename Ta, typename Tb, typename Tz,
26 require_all_vector_st<std::is_arithmetic, Ta, Tb>* = nullptr,
27 require_arithmetic_t<Tz>* = nullptr>
29 const Tz& z) {
30 plain_type_t<Ta> a_ref = a;
31 plain_type_t<Tb> b_ref = b;
32 check_finite("hypergeometric_pFq", "a", a_ref);
33 check_finite("hypergeometric_pFq", "b", b_ref);
34 check_finite("hypergeometric_pFq", "z", z);
35
36 check_not_nan("hypergeometric_pFq", "a", a_ref);
37 check_not_nan("hypergeometric_pFq", "b", b_ref);
38 check_not_nan("hypergeometric_pFq", "z", z);
39
40 bool condition_1 = (a_ref.size() > (b_ref.size() + 1)) && (z != 0);
41 bool condition_2 = (a_ref.size() == (b_ref.size() + 1)) && (std::fabs(z) > 1);
42
43 if (condition_1 || condition_2) {
44 std::stringstream msg;
45 msg << "hypergeometric function pFq does not meet convergence "
46 << "conditions with given arguments. "
47 << "a: " << to_row_vector(a_ref) << ", "
48 << "b: " << to_row_vector(b_ref) << ", "
49 << "z: " << z;
50 throw std::domain_error(msg.str());
51 }
52
53 return boost::math::hypergeometric_pFq(
54 std::vector<double>(a_ref.data(), a_ref.data() + a_ref.size()),
55 std::vector<double>(b_ref.data(), b_ref.data() + b_ref.size()), z);
56}
57} // namespace math
58} // namespace stan
59#endif
auto to_row_vector(T_x &&x)
Returns input matrix reshaped into a row vector.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
FvarT hypergeometric_pFq(Ta &&a, Tb &&b, Tz &&z)
Returns the generalized hypergeometric (pFq) function applied to the input arguments.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...