Automatic Differentiation
 
Loading...
Searching...
No Matches
dot_self.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_DOT_SELF_HPP
2#define STAN_MATH_PRIM_FUN_DOT_SELF_HPP
3
7#include <cstddef>
8#include <vector>
9
10namespace stan {
11namespace math {
12
13inline double dot_self(const std::vector<double>& x) {
14 double sum = 0.0;
15 for (double i : x) {
16 sum += i * i;
17 }
18 return sum;
19}
20
28template <typename T, require_eigen_t<T>* = nullptr,
29 require_not_eigen_vt<is_var, T>* = nullptr>
30inline value_type_t<T> dot_self(const T& v) {
31 return v.squaredNorm();
32}
33
34} // namespace math
35} // namespace stan
36
37#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
auto dot_self(const T &a)
Returns squared norm of a vector or matrix.
Definition dot_self.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...