36 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
38 int main(
int argc,
const char *argv[]) {
42 size = std::stoi(argv[1]);
48 EigenMat A_eigen = EigenMat::Zero(size, size);
49 std::copy(A.
begin(), A.
end(), A_eigen.data());
55 auto start = std::chrono::high_resolution_clock::now();
57 auto finish = std::chrono::high_resolution_clock::now();
59 std::chrono::duration<double> elapsed = finish - start;
61 double err_fro = (A - QR).normFro();
62 std::cout <<
"Elapsed time HouseholderQR: " << elapsed.count() <<
" s\n"
63 <<
"Error QR - A in Frobenius norm: " << std::scientific
64 << err_fro << std::defaultfloat << std::endl;
68 Eigen::HouseholderQR<EigenMat> qr_eigen;
70 auto start = std::chrono::high_resolution_clock::now();
71 qr_eigen.compute(std::move(A_eigen_cpy));
72 auto finish = std::chrono::high_resolution_clock::now();
74 std::chrono::duration<double> elapsed = finish - start;
75 EigenMat QR = qr_eigen.matrixQR().triangularView<Eigen::Upper>();
76 qr_eigen.householderQ().applyThisOnTheLeft(QR);
77 auto err_fro = (A_eigen - QR).norm();
78 std::cout <<
"Elapsed time Eigen: " << elapsed.count() <<
" s\n"
79 <<
"Error QR - A in Frobenius norm: " << std::scientific
80 << err_fro << std::defaultfloat << std::endl;
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > EigenMat
int main(int argc, const char *argv[])
QR factorization using Householder reflectors.
Matrix apply_Q(const Matrix &X) const
Compute the product QB.
Matrix get_R() const &
Get a copy of the upper-triangular matrix R.
void compute(Matrix &&matrix)
Perform the QR factorization of the given matrix.
static Matrix random(size_t rows, size_t cols, double min=0, double max=1, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Create a matrix with uniformly distributed random values.
storage_t::iterator end()
Get the iterator to the element past the end of the matrix.
storage_t::iterator begin()
Get the iterator to the first element of the matrix.