| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/arr/err/check_nonzero_size.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/prim/scal/err/check_greater_or_equal.hpp>
7 #include <Eigen/QR>
8
9 namespace stan {
10 namespace math {
11
12 template <typename T>
13 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
14 qr_Q(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& m) {
15 typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> matrix_t;
16 check_nonzero_size("qr_Q", "m", m);
17 check_greater_or_equal("qr_Q", "m.rows()",
18 static_cast<size_t>(m.rows()),
19 static_cast<size_t>(m.cols()));
20
21 Eigen::HouseholderQR<matrix_t> qr(m.rows(), m.cols());
22 qr.compute(m);
23 matrix_t Q = qr.householderQ();
24 for (int i = 0; i < m.cols(); i++)
25 if (qr.matrixQR().coeff(i, i) < 0)
26 Q.col(i) *= -1.0;
27 return Q;
28 }
29
30 }
31 }
32 #endif
stan::math::check_greater_or_equal
bool check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is greater or equal than low.
Definition: check_greater_or_equal.hpp:84
stan
Definition: log_sum_exp.hpp:8
stan::math::qr_Q
Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > qr_Q(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > &m)
Definition: qr_Q.hpp:15
stan::math::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:29
Eigen.hpp
check_greater_or_equal.hpp
check_nonzero_size.hpp

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