| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

qr_R.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_QR_R_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_QR_R_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_R(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_R", "m", m);
17 check_greater_or_equal("qr_R",
18 "m.rows()",
19 static_cast<size_t>(m.rows()),
20 static_cast<size_t>(m.cols()));
21 Eigen::HouseholderQR<matrix_t> qr(m.rows(), m.cols());
22 qr.compute(m);
23 matrix_t R = qr.matrixQR();
24 if (m.rows() > m.cols())
25 R.bottomRows(m.rows() - m.cols()).setZero();
26 for (int i = 0; i < R.cols(); i++) {
27 for (int j = 0; j < i; j++)
28 R.coeffRef(i, j) = 0.0;
29 if (R(i, i) < 0)
30 R.row(i) *= -1.0;
31 }
32 return R;
33 }
34 }
35 }
36 #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::math::qr_R
Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > qr_R(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, Eigen::Dynamic > &m)
Definition: qr_R.hpp:15
stan
Definition: log_sum_exp.hpp:8
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.