1 #ifndef STAN_MATH_PRIM_FUN_SYMMETRIZE_FROM_LOWER_TRI_HPP
2 #define STAN_MATH_PRIM_FUN_SYMMETRIZE_FROM_LOWER_TRI_HPP
3 
4 #include <stan/math/prim/err.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 
7 namespace stan {
8 namespace math {
9 
10 /**
11  * Return a symmetric matrix using elements from the lower triangular part of
12  * the input matrix.
13  *
14  * @tparam T type of elements in the matrix
15  * @param m Matrix.
16  * @throw std:invalid_argument if the matrix is not square.
17  */
18 template <typename T, require_eigen_t<T>* = nullptr>
19 inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
symmetrize_from_lower_tri(const T & m)20 symmetrize_from_lower_tri(const T& m) {
21   check_square("symmetrize_from_lower_tri", "m", m);
22   return m.template selfadjointView<Eigen::Lower>();
23 }
24 
25 }  // namespace math
26 }  // namespace stan
27 
28 #endif
29