-
-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathnorm2.hpp
More file actions
34 lines (30 loc) · 1.01 KB
/
norm2.hpp
File metadata and controls
34 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef STAN_MATH_FWD_FUN_NORM2_HPP
#define STAN_MATH_FWD_FUN_NORM2_HPP
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/meta.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#include <stan/math/prim/fun/norm2.hpp>
namespace stan {
namespace math {
/**
* Compute the L2 norm of the specified vector of values.
*
* @tparam T Type of input vector.
* @param[in] x Vector of specified values.
* @return L2 norm of x.
*/
template <typename Container, require_eigen_vt<is_fvar, Container>* = nullptr>
inline auto norm2(Container&& x) {
return apply_vector_unary<ref_type_t<Container>>::reduce(
to_ref(std::forward<Container>(x)), [&](const auto& v) {
using T_fvar_inner = typename value_type_t<decltype(v)>::Scalar;
T_fvar_inner res = norm2(v.val());
return fvar<T_fvar_inner>(res,
v.d().cwiseProduct((v.val() / res)).sum());
});
}
} // namespace math
} // namespace stan
#endif