Automatic Differentiation
 
Loading...
Searching...
No Matches
svd.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SVD_HPP
2#define STAN_MATH_PRIM_FUN_SVD_HPP
3
6
7namespace stan {
8namespace math {
9
19template <typename EigMat, require_eigen_matrix_dynamic_t<EigMat>* = nullptr,
20 require_not_st_var<EigMat>* = nullptr>
21std::tuple<Eigen::Matrix<value_type_t<EigMat>, -1, -1>,
22 Eigen::Matrix<base_type_t<EigMat>, -1, 1>,
23 Eigen::Matrix<value_type_t<EigMat>, -1, -1>>
24svd(const EigMat& m) {
25 if (unlikely(m.size() == 0)) {
26 return std::make_tuple(Eigen::Matrix<value_type_t<EigMat>, -1, -1>(0, 0),
27 Eigen::Matrix<base_type_t<EigMat>, -1, 1>(0, 1),
28 Eigen::Matrix<value_type_t<EigMat>, -1, -1>(0, 0));
29 }
30
31 Eigen::JacobiSVD<Eigen::Matrix<value_type_t<EigMat>, -1, -1>> svd(
32 m, Eigen::ComputeThinU | Eigen::ComputeThinV);
33 return std::make_tuple(std::move(svd.matrixU()),
34 std::move(svd.singularValues()),
35 std::move(svd.matrixV()));
36}
37
38} // namespace math
39} // namespace stan
40
41#endif
#define unlikely(x)
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
std::tuple< Eigen::Matrix< value_type_t< EigMat >, -1, -1 >, Eigen::Matrix< base_type_t< EigMat >, -1, 1 >, Eigen::Matrix< value_type_t< EigMat >, -1, -1 > > svd(const EigMat &m)
Given input matrix m, return the singular value decomposition (U,D,V) such that m = U*diag(D)*V^{T}
Definition svd.hpp:24
typename base_type< T >::type base_type_t
Definition base_type.hpp:30
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...