Automatic Differentiation
 
Loading...
Searching...
No Matches
norm2.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_NORM2_HPP
2#define STAN_MATH_FWD_FUN_NORM2_HPP
3
10
11namespace stan {
12namespace math {
13
21template <typename Container, require_eigen_vt<is_fvar, Container>* = nullptr>
22inline auto norm2(const Container& x) {
24 to_ref(x), [&](const auto& v) {
25 using T_fvar_inner = typename value_type_t<decltype(v)>::Scalar;
26 T_fvar_inner res = norm2(v.val());
27 return fvar<T_fvar_inner>(res,
28 v.d().cwiseProduct((v.val() / res)).sum());
29 });
30}
31
32} // namespace math
33} // namespace stan
34#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
auto norm2(const Container &x)
Compute the L2 norm of the specified vector of values.
Definition norm2.hpp:22
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40