qr_R.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_FWD_MAT_FUN_QR_R_HPP
#define STAN_MATH_FWD_MAT_FUN_QR_R_HPP
#include <stan/math/prim/arr/err/check_nonzero_size.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/check_greater_or_equal.hpp>
#include <stan/math/fwd/core.hpp>
#include <Eigen/QR>
namespace stan {
namespace math {
template <typename T>
Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>
qr_R(const Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>& m) {
typedef Eigen::Matrix<fvar<T>, Eigen::Dynamic, Eigen::Dynamic>
matrix_fwd_t;
check_nonzero_size("qr_R", "m", m);
check_greater_or_equal("qr_R", "m.rows()", m.rows(), m.cols());
Eigen::HouseholderQR< matrix_fwd_t > qr(m.rows(), m.cols());
qr.compute(m);
matrix_fwd_t R = qr.matrixQR().topLeftCorner(m.rows(), m.cols());
for (int i = 0; i < R.rows(); i++) {
for (int j = 0; j < i; j++)
R(i, j) = 0.0;
if (i < R.cols() && R(i, i) < 0.0)
R.row(i) *= -1.0;
}
return R;
}
}
}
#endif
core.hpp
stan::math::check_nonzero_size
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:27
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_greater_or_equal
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is greater or equal than low.
Definition: check_greater_or_equal.hpp:78
Eigen.hpp
check_greater_or_equal.hpp
check_nonzero_size.hpp
stan::math::fvar
Definition: fvar.hpp:14

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