1#ifndef STAN_MATH_REV_FUN_DOT_SELF_HPP
2#define STAN_MATH_REV_FUN_DOT_SELF_HPP
23template <
typename T, require_eigen_vector_vt<is_var, T>* =
nullptr>
25 const auto& v_ref =
to_ref(v);
28 for (
size_t i = 0; i < arena_v.size(); ++i) {
29 arena_v.coeffRef(i) = v_ref.coeffRef(i);
30 res_val += arena_v.coeffRef(i).val() * arena_v.coeffRef(i).val();
34 arena_v.adj() += 2.0 * res.adj() * arena_v.val();
47template <
typename T, require_var_matrix_t<T>* =
nullptr>
49 var res = v.val().dot(v.val());
51 [res, v]()
mutable { v.adj() += (2.0 * res.adj()) * v.val(); });
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
auto dot_self(const T &a)
Returns squared norm of a vector or matrix.
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...