Automatic Differentiation
 
Loading...
Searching...
No Matches
std_normal_log_qf.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_PROB_STD_NORMAL_LOG_QF_HPP
2#define STAN_MATH_REV_PROB_STD_NORMAL_LOG_QF_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
20template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr>
21inline auto std_normal_log_qf(const var_value<T>& log_p) {
22 return make_callback_var(
23 std_normal_log_qf(log_p.val()), [log_p](auto& vi) mutable {
24 auto vi_array = as_array_or_scalar(vi.val());
25 auto vi_sign = sign(as_array_or_scalar(vi.adj()));
26
27 const auto& deriv = as_array_or_scalar(log_p).val()
28 + log(as_array_or_scalar(vi.adj()) * vi_sign)
29 - NEG_LOG_SQRT_TWO_PI + 0.5 * square(vi_array);
30 as_array_or_scalar(log_p).adj() += vi_sign * exp(deriv);
31 });
32}
33
34} // namespace math
35} // namespace stan
36#endif
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...
fvar< T > std_normal_log_qf(const fvar< T > &p)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...