Stan Math Library  2.20.0
reverse mode automatic differentiation
qr_Q.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_QR_Q_HPP
2 #define STAN_MATH_FWD_MAT_FUN_QR_Q_HPP
3 
7 #include <stan/math/fwd/core.hpp>
8 
9 namespace stan {
10 namespace math {
11 
12 template <typename T>
13 Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic> qr_Q(
14  const Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>& m) {
15  typedef Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic> matrix_fwd_t;
16  check_nonzero_size("qr_Q", "m", m);
17  check_greater_or_equal("qr_Q", "m.rows()", m.rows(), m.cols());
18  Eigen::HouseholderQR<matrix_fwd_t> qr(m.rows(), m.cols());
19  qr.compute(m);
20  matrix_fwd_t Q = qr.householderQ();
21  for (int i = 0; i < m.cols(); i++)
22  if (qr.matrixQR()(i, i) < 0.0)
23  Q.col(i) *= -1.0;
24  return Q;
25 }
26 
27 } // namespace math
28 } // namespace stan
29 #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.
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
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is greater or equal than low.
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41

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