| 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_FWD_MAT_FUN_QR_R_HPP
2 #define STAN_MATH_FWD_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 <stan/math/fwd/core.hpp>
8 #include <Eigen/QR>
9
10 namespace stan {
11 namespace math {
12
13 template <typename T>
14 Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>
15 qr_R(const Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>& m) {
16 typedef Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>
17 matrix_fwd_t;
18 check_nonzero_size("qr_R", "m", m);
19 check_greater_or_equal("qr_R", "m.rows()", m.rows(), m.cols());
20 Eigen::HouseholderQR< matrix_fwd_t > qr(m.rows(), m.cols());
21 qr.compute(m);
22 matrix_fwd_t R = qr.matrixQR().topLeftCorner(m.rows(), m.cols());
23 for (int i = 0; i < R.rows(); i++) {
24 for (int j = 0; j < i; j++)
25 R(i, j) = 0.0;
26 if (i < R.cols() && R(i, i) < 0.0)
27 R.row(i) *= -1.0;
28 }
29 return R;
30 }
31
32 }
33 }
34 #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
core.hpp
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::math::fvar
Definition: fvar.hpp:12

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