Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 
5 #include <Eigen/QR>
8 #include <stan/math/fwd/core.hpp>
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  stan::math::check_nonzero_size("qr_R", "m", m);
19  stan::math::check_greater_or_equal("qr_R", "m.rows()", m.rows(),
20  m.cols());
21  Eigen::HouseholderQR< matrix_fwd_t > qr(m.rows(), m.cols());
22  qr.compute(m);
23  matrix_fwd_t R = qr.matrixQR().topLeftCorner(m.rows(), m.cols());
24  for (int i = 0; i < R.rows(); i++) {
25  for (int j = 0; j < i; j++)
26  R(i, j) = 0.0;
27  if (i < R.cols() && R(i, i) < 0.0)
28  R.row(i) *= -1.0;
29  }
30  return R;
31  }
32  }
33 }
34 #endif
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.
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
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.

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