Automatic Differentiation
 
Loading...
Searching...
No Matches
qr_Q.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_QR_Q_HPP
2#define STAN_MATH_PRIM_FUN_QR_Q_HPP
3
7#include <algorithm>
8
9namespace stan {
10namespace math {
11
19template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
20Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic, Eigen::Dynamic> qr_Q(
21 const EigMat& m) {
22 using matrix_t
23 = Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic, Eigen::Dynamic>;
24 if (unlikely(m.size() == 0)) {
25 return matrix_t(0, 0);
26 }
27
28 Eigen::HouseholderQR<matrix_t> qr(m.rows(), m.cols());
29 qr.compute(m);
30 matrix_t Q = qr.householderQ();
31 const int min_size = std::min(m.rows(), m.cols());
32 for (int i = 0; i < min_size; i++) {
33 if (qr.matrixQR().coeff(i, i) < 0) {
34 Q.col(i) *= -1.0;
35 }
36 }
37 return Q;
38}
39
40} // namespace math
41} // namespace stan
42
43#endif
#define unlikely(x)
matrix_cl< double > qr_Q(T_m &&m)
Returns the orthogonal factor of the fat QR decomposition.
Definition qr_Q.hpp:20
std::tuple< Eigen::Matrix< value_type_t< EigMat >, Eigen::Dynamic, Eigen::Dynamic >, Eigen::Matrix< value_type_t< EigMat >, Eigen::Dynamic, Eigen::Dynamic > > qr(const EigMat &m)
Returns the fat QR decomposition.
Definition qr.hpp:25
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...