Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qr_R.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__MATRIX__QR_R_HPP
2 #define STAN__AGRAD__FWD__MATRIX__QR_R_HPP
3 
5 #include <Eigen/QR>
9 
10 namespace stan {
11  namespace agrad {
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> matrix_fwd_t;
17  stan::math::check_nonzero_size("qr_R(%1%)",m,"m",(double*)0);
18  stan::math::check_greater_or_equal("qr_R(%1%)",m.rows(),m.cols(),"m.rows()",
19  (double*)0);
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 #endif
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_greater_or_equal(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result)
bool check_nonzero_size(const char *function, const T_y &y, const char *name, T_result *result)
Return true if the specified matrix/vector is of non-zero size.

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