Automatic Differentiation
 
Loading...
Searching...
No Matches
falling_factorial.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_FALLING_FACTORIAL_HPP
2#define STAN_MATH_PRIM_FUN_FALLING_FACTORIAL_HPP
3
8#include <boost/math/special_functions/factorials.hpp>
9
10namespace stan {
11namespace math {
12
63template <typename T, require_arithmetic_t<T>* = nullptr>
64inline return_type_t<T> falling_factorial(const T& x, int n) {
65 constexpr const char* function = "falling_factorial";
66 check_not_nan(function, "first argument", x);
67 check_nonnegative(function, "second argument", n);
68 return boost::math::falling_factorial(x, n, boost_policy_t<>());
69}
70
81template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr,
82 require_all_not_var_matrix_t<T1, T2>* = nullptr>
83inline auto falling_factorial(const T1& a, const T2& b) {
84 return apply_scalar_binary(a, b, [&](const auto& c, const auto& d) {
85 return falling_factorial(c, d);
86 });
87}
88
89} // namespace math
90} // namespace stan
91
92#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
fvar< T > falling_factorial(const fvar< T > &x, int n)
Return autodiff variable with the gradient and result of the falling factorial function applied to th...
boost::math::policies::policy< boost::math::policies::overflow_error< boost::math::policies::errno_on_error >, boost::math::policies::pole_error< boost::math::policies::errno_on_error >, boost::math::policies::promote_double< false >, boost::math::policies::digits2< B > > boost_policy_t
Boost policy that overrides the defaults to match the built-in C++ standard library functions.
auto apply_scalar_binary(const T1 &x, const T2 &y, const F &f)
Base template function for vectorization of binary scalar functions defined by applying a functor to ...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...