#include "QRD.h" // Empty constructor QRD::QRD(){_n=-1;} // 1) Perform QR Decomp via LINPACK 'dqrdc2' subroutine // 2) Populate QRD member data with decomposed QR matrix and // info about decomp routine QRD::QRD(const Matrix& A, const double tol=1E-12) { // Initialize member data and allocate heap memory _n=A.Nrows(); _p=A.Ncols(); _tol=tol; _qr=C2F(A); _pivot=(int*)R_alloc(_p,sizeof(int)); _tau=(double*)R_alloc(_p,sizeof(double)); _work=(double*)R_alloc(_p*2,sizeof(double)); for(int i=0;i<_p;i++) { _pivot[i]=i+1; _tau[i]=0; _work[i]=0; _work[i+_p]=0; } // LINPACK QR factorization via householder transformations F77_CALL(dqrdc2)(_qr, &_n, &_n, &_p, &_tol, &_rank, _tau, _pivot, _work); } // Return Generalized Orthogonal Factor Q(n,n) ReturnMatrix QRD::Q() const { // Pull member data, allocate memory and initialize Y/Q int i, j, ct=0, n=_n, rank=_rank; double *y, *q; y=(double *)R_alloc(n*n,sizeof(double)); q=(double *)R_alloc(n*n,sizeof(double)); for(i=0;i