1 #ifndef STAN_MATH_PRIM_FUN_DIAGONAL_HPP 2 #define STAN_MATH_PRIM_FUN_DIAGONAL_HPP 3 4 #include <stan/math/prim/fun/Eigen.hpp> 5 #include <stan/math/prim/meta.hpp> 6 7 namespace stan { 8 namespace math { 9 10 /** 11 * Return a column vector of the diagonal elements of the 12 * specified matrix. The matrix is not required to be square. 13 * 14 * @tparam T type of the matrix 15 * @param m Specified matrix. 16 * @return Diagonal of the matrix. 17 */ 18 template <typename T, require_matrix_t<T>* = nullptr> diagonal(const T & m)19inline auto diagonal(const T& m) { 20 return m.diagonal(); 21 } 22 23 } // namespace math 24 } // namespace stan 25 26 #endif 27