Automatic Differentiation
 
Loading...
Searching...
No Matches
Phi.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_PHI_HPP
2#define STAN_MATH_REV_FUN_PHI_HPP
3
7#include <cmath>
8
9namespace stan {
10namespace math {
11
53inline var Phi(const var& a) {
54 return make_callback_var(Phi(a.val()), [a](auto& vi) mutable {
55 a.adj() += vi.adj() * INV_SQRT_TWO_PI * std::exp(-0.5 * a.val() * a.val());
56 });
57}
58
66template <typename T, require_var_matrix_t<T>* = nullptr>
67inline auto Phi(const T& a) {
68 return make_callback_var(Phi(a.val()), [a](auto& vi) mutable {
69 a.adj().array() += vi.adj().array() * INV_SQRT_TWO_PI
70 * (-0.5 * a.val().array().square()).exp();
71 });
72}
73
74} // namespace math
75} // namespace stan
76#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 > Phi(const fvar< T > &x)
Definition Phi.hpp:14
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...