1 #ifndef STAN_MATH_PRIM_FUN_ROWS_DOT_SELF_HPP
2 #define STAN_MATH_PRIM_FUN_ROWS_DOT_SELF_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Returns the dot product of each row of a matrix with itself.
12  *
13  * @tparam T type of the matrix (must be derived from \c
14  * Eigen::MatrixBase)
15  *
16  * @param x matrix
17  */
18 template <typename T, require_eigen_t<T>* = nullptr,
19           require_not_st_var<T>* = nullptr>
rows_dot_self(const T & x)20 inline Eigen::Matrix<value_type_t<T>, T::RowsAtCompileTime, 1> rows_dot_self(
21     const T& x) {
22   return x.rowwise().squaredNorm();
23 }
24 
25 }  // namespace math
26 }  // namespace stan
27 
28 #endif
29