26 #ifndef TOON_INCLUDE_QR_LAPACK_H 27 #define TOON_INCLUDE_QR_LAPACK_H 30 #include <TooN/TooN.h> 31 #include <TooN/lapack.h> 56 template<
int Rows=Dynamic,
int Cols=Rows,
class Precision=
double>
60 static const int square_Size = (Rows>=0 && Cols>=0)?(Rows<Cols?Rows:Cols):Dynamic;
67 template<
int R,
int C,
class P,
class B>
69 :copy(m),tau(square_size()),
70 Q(square_size(), square_size()),
72 pivot(Zeros(m.num_cols()))
103 FortranInteger M = copy.num_rows();
104 FortranInteger N = copy.num_cols();
106 FortranInteger LWORK=-1;
108 FortranInteger lda = M;
116 for(
int i=0; i < pivot.size(); i++)
121 geqp3_(&M, &N, copy.get_data_ptr(), &lda, pivot.get_data_ptr(), tau.get_data_ptr(), &size, &LWORK, &INFO);
123 LWORK = (FortranInteger) size;
125 Precision* work =
new Precision[LWORK];
127 geqp3_(&M, &N, copy.get_data_ptr(), &lda, pivot.get_data_ptr(), tau.get_data_ptr(), work, &LWORK, &INFO);
131 std::cerr <<
"error in QR, INFO was " << INFO << std::endl;
137 Q = copy.template slice<0,0,square_Size, square_Size>(0,0,square_size(), square_size());
139 FortranInteger K = square_size();
143 orgqr_(&M, &N, &K, Q.get_data_ptr(), &lda, tau.get_data_ptr(), work, &LWORK, &INFO);
146 std::cerr <<
"error in QR, INFO was " << INFO << std::endl;
151 for(
int r=1; r < square_size(); r++)
152 for(
int c=0; c<r; c++)
157 for(
int i=0; i < pivot.size(); i++)
170 return std::min(copy.num_rows(), copy.num_cols());
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
A vector.
Definition: vector.hh:126
const Matrix< square_Size, square_Size, Precision, ColMajor > & get_Q()
Return Q.
Definition: QR_Lapack.h:87
Performs QR decomposition.
Definition: QR_Lapack.h:57
const Vector< Cols, int > & get_P()
Return the permutation vector.
Definition: QR_Lapack.h:94
const Matrix< Rows, Cols, Precision, ColMajor > & get_R()
Return R.
Definition: QR_Lapack.h:81
QR_Lapack(const Matrix< R, C, P, B > &m, bool p=0)
Construct the QR decomposition of a matrix.
Definition: QR_Lapack.h:68