Stan Math Library  2.20.0
reverse mode automatic differentiation
qr_Q.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_QR_Q_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_QR_Q_HPP
3 
7 #include <algorithm>
8 
9 namespace stan {
10 namespace math {
11 
18 template <typename T>
19 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> qr_Q(
20  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& m) {
21  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> matrix_t;
22  check_nonzero_size("qr_Q", "m", m);
23  Eigen::HouseholderQR<matrix_t> qr(m.rows(), m.cols());
24  qr.compute(m);
25  matrix_t Q = qr.householderQ();
26  const int min_size = std::min(m.rows(), m.cols());
27  for (int i = 0; i < min_size; i++)
28  if (qr.matrixQR().coeff(i, i) < 0)
29  Q.col(i) *= -1.0;
30  return Q;
31 }
32 
33 } // namespace math
34 } // namespace stan
35 #endif
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
int min(const std::vector< int > &x)
Returns the minimum coefficient in the specified column vector.
Definition: min.hpp:20
Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > qr_Q(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > &m)
Definition: qr_Q.hpp:13

     [ Stan Home Page ] © 2011–2018, Stan Development Team.