1 #ifndef STAN_MATH_PRIM_FUN_SVD_U_HPP
2 #define STAN_MATH_PRIM_FUN_SVD_U_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  * Given input matrix m, return matrix U where `m = UDV^{T}`
12  *
13  * @tparam EigMat type of the matrix
14  * @param m MxN input matrix
15  * @return Orthogonal matrix U
16  */
17 template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
18           require_not_st_var<EigMat>* = nullptr>
svd_U(const EigMat & m)19 Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic, Eigen::Dynamic> svd_U(
20     const EigMat& m) {
21   check_nonzero_size("svd_U", "m", m);
22 
23   return Eigen::JacobiSVD<Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic,
24                                         Eigen::Dynamic> >(m,
25                                                           Eigen::ComputeThinU)
26       .matrixU();
27 }
28 
29 }  // namespace math
30 }  // namespace stan
31 
32 #endif
33