Automatic Differentiation
 
Loading...
Searching...
No Matches
inv_Phi.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_INV_PHI_HPP
2#define STAN_MATH_REV_FUN_INV_PHI_HPP
3
8#include <cmath>
9
10namespace stan {
11namespace math {
12
21inline var inv_Phi(const var& p) {
22 return make_callback_var(inv_Phi(p.val()), [p](auto& vi) mutable {
23 p.adj() += vi.adj() * SQRT_TWO_PI / std::exp(-0.5 * vi.val() * vi.val());
24 });
25}
26
34template <typename T, require_var_matrix_t<T>* = nullptr>
35inline auto inv_Phi(const T& p) {
36 return make_callback_var(inv_Phi(p.val()), [p](auto& vi) mutable {
37 p.adj().array() += vi.adj().array() * SQRT_TWO_PI
38 / (-0.5 * vi.val().array().square()).exp();
39 });
40}
41
42} // namespace math
43} // namespace stan
44#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 > inv_Phi(const fvar< T > &p)
Definition inv_Phi.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...