31 #include <TooN/TooN.h> 51 template<
int Rows=Dynamic,
int Cols=Rows,
typename Precision=
double>
class QR 55 static const int square_Size = (Rows>=0 && Cols>=0)?(Rows<Cols?Rows:Cols):Dynamic;
61 template<
int R,
int C,
class P,
class B>
63 :m(m_), Q(Identity(square_size()))
85 template<
class B1,
class B2>
107 for(
int col=0; col < A.num_cols(); col++)
109 Precision va = v * A.T()[col] / s;
111 for(
int row=0; row < A.num_rows(); row++)
112 A[row][col] -= v[row] * va;
133 for(
int n=0; n < square_size()-1; n++)
137 int sz = square_size() - n;
138 int nc = m.num_cols() - n;
156 Precision nx2 =
norm_sq(s.T()[0]);
158 Precision a =
sqrt(nx2) * (s.T()[0][0] < 0?-1:1);
170 Precision H = -a * s.T()[0][0];
202 pre_multiply_by_householder(s.slice(0, 1, sz, nc-1).
ref(), s.T()[0], H);
205 pre_multiply_by_householder(Q.slice(n,0,sz,square_size()).ref(), s.T()[0], H);
211 s.T()[0].slice(1, sz-1) = Zeros;
219 for(
int r=0; r < Q.num_rows(); r++)
220 for(
int c=r+1; c < Q.num_cols(); c++)
221 swap(Q[r][c], Q[c][r]);
231 return std::min(m.num_rows(), m.num_cols());
const Matrix< square_Size, square_Size, Precision, ColMajor > & get_Q()
Return Q.
Definition: QR.h:78
Matrix & ref()
return me as a non const reference - useful for temporaries
Definition: matrix.hh:298
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
A vector.
Definition: vector.hh:126
Precision norm_sq(const Vector< Size, Precision, Base > &v)
Compute the norm of v.
Definition: helpers.h:106
const Matrix< Rows, Cols, Precision > & get_R()
Return R.
Definition: QR.h:72
QR(const Matrix< R, C, P, B > &m_)
Construct the QR decomposition of a matrix.
Definition: QR.h:62
Matrix< R, C, P > sqrt(const Matrix< R, C, P, B > &m)
computes a matrix square root of a matrix m by the product form of the Denman and Beavers iteration a...
Definition: helpers.h:350
Performs QR decomposition.
Definition: QR.h:51