1 #ifndef STAN_MATH_REV_FUN_LOGIT_HPP 2 #define STAN_MATH_REV_FUN_LOGIT_HPP 3 4 #include <stan/math/rev/core.hpp> 5 #include <stan/math/rev/meta.hpp> 6 #include <stan/math/prim/fun/logit.hpp> 7 #include <stan/math/prim/fun/square.hpp> 8 9 namespace stan { 10 namespace math { 11 12 /** 13 * Return the log odds of the specified argument. 14 * 15 * @tparam T Arithmetic or a type inheriting from `EigenBase`. 16 * @param u The variable. 17 * @return log odds of argument 18 */ 19 template <typename T, require_stan_scalar_or_eigen_t<T>* = nullptr> logit(const var_value<T> & u)20inline auto logit(const var_value<T>& u) { 21 auto denom = to_arena(1.0 / as_array_or_scalar(u.val() - square(u.val()))); 22 return make_callback_var(logit(u.val()), [u, denom](auto& vi) mutable { 23 as_array_or_scalar(u.adj()) += as_array_or_scalar(vi.adj()) * denom; 24 }); 25 } 26 27 } // namespace math 28 } // namespace stan 29 #endif 30