1#ifndef STAN_MATH_PRIM_PROB_STD_NORMAL_LOG_QF_HPP
2#define STAN_MATH_PRIM_PROB_STD_NORMAL_LOG_QF_HPP
27 check_not_nan(
"std_normal_log_qf",
"Log probability variable", log_p);
37 static constexpr double log_a[8]
38 = {1.2199838032983212, 4.8914137334471356, 7.5865960847956080,
39 9.5274618535358388, 10.734698580862359, 11.116406781896242,
40 10.417226196842595, 7.8276718012189362};
41 static constexpr double log_b[8] = {0.,
49 static constexpr double log_c[8]
50 = {0.3530744474482423, 1.5326298343683388, 1.7525849400614634,
51 1.2941374937060454, 0.2393776640901312, -1.419724057885092,
52 -3.784340465764968, -7.163234779359426};
53 static constexpr double log_d[8] = {0.,
61 static constexpr double log_e[8]
62 = {1.8958048169567149, 1.6981417567726154, 0.5793212339927351,
63 -1.215503791936417, -3.629396584023968, -6.690500273261249,
64 -10.51540298415323, -15.41979457491781};
65 static constexpr double log_f[8] = {0.,
76 int log_q_sign = log_p <=
LOG_HALF ? -1 : 1;
77 double log_r = log_q_sign == -1 ? log_p :
log1m_exp(log_p);
85 const double* num_ptr;
86 const double* den_ptr;
89 static constexpr double LOG_16 =
LOG_TWO * 4;
90 static constexpr double LOG_425 = 6.0520891689244171729;
91 static constexpr double LOG_425_OVER_1000 = LOG_425 -
LOG_TEN * 3;
93 if (log_q <= LOG_425_OVER_1000) {
94 log_inner_r =
log_diff_exp(LOG_425_OVER_1000 * 2, log_q * 2);
99 double log_temp_r =
log(-log_r) / 2.0;
100 if (log_temp_r <= LOG_FIVE) {
116 Eigen::VectorXd log_r_pow
117 = Eigen::ArrayXd::LinSpaced(8, 0, 7) * log_inner_r -
LOG_TEN;
118 Eigen::Map<const Eigen::VectorXd> num_map(num_ptr, 8);
119 Eigen::Map<const Eigen::VectorXd> den_map(den_ptr, 8);
122 return log_q_sign *
exp(log_pre_mult + log_result);
134 template <
typename T>
135 static inline auto fun(
const T& x) {
require_all_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_not_nonscalar_prim_or_rev_kernel_expression_t
Require none of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
require_not_t< is_var_matrix< std::decay_t< T > > > require_not_var_matrix_t
Require type does not satisfy is_var_matrix.
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not less than high.
static constexpr double LOG_HALF
The natural logarithm of 0.5, .
fvar< T > log1m_exp(const fvar< T > &x)
Return the natural logarithm of one minus the exponentiation of the specified argument.
static constexpr double LOG_TEN
The natural logarithm of 10, .
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
static constexpr double LOG_TWO
The natural logarithm of 2, .
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
fvar< T > std_normal_log_qf(const fvar< T > &p)
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
static constexpr double INFTY
Positive infinity.
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(const T &x)
Structure to wrap std_normal_log_qf() so it can be vectorized.