48#ifdef STK_ALGEBRA_DEBUG
51template<
class Container2D >
52void print(Container2D
const& A,
STK::String const& name)
55 stk_cout << name <<
_T(
".isRef() =") << A.isRef() <<
_T(
"\n");
56 stk_cout << name <<
_T(
".cols() =") << A.cols() <<
_T(
"\n");
57 stk_cout << name <<
_T(
".rows() =") << A.rows() <<
_T(
"\n\n");
58 stk_cout << name <<
_T(
".rangeCols().isRef() =") << A.rangeCols().isRef() <<
_T(
"\n");
59 stk_cout << name <<
_T(
".rangeCols() =\n") << A.rangeCols() <<
_T(
"\n");
62void print(ArrayXX
const& A,
STK::String const& name)
65 stk_cout << name <<
_T(
".isRef() =") << A.isRef() <<
_T(
"\n");
66 stk_cout << name <<
_T(
".cols() =") << A.cols() <<
_T(
"\n");
67 stk_cout << name <<
_T(
".rows() =") << A.rows() <<
_T(
"\n\n");
68 stk_cout << name <<
_T(
".rangeCols().isRef() =") << A.rangeCols().isRef() <<
_T(
"\n");
69 stk_cout << name <<
_T(
".rangeCols() =\n") << A.rangeCols() <<
_T(
"\n");
100template <
class Derived>
115 if (
Q.beginRows() !=
Q.beginCols())
121 template<
class DerivedExpr>
124 if (
Q.beginRows() !=
Q.beginCols())
191 template<
class ColVector_>
198 template<
class ColVector_>
203 template<
class OtherDerived>
226template<
class Derived>
230 if (Q_.empty()) { compq_ =
true;
return true;}
232 if (!this->asDerived().runImpl())
return false;
236 int r = R_.beginRows();
239 int n = std::min(R_.endRows(), R_.endCols());
240 for(r= R_.beginRows(), rank_=0; r<n; ++r, ++rank_) {
if (std::abs(R_(r,r)) <
tol)
break;}
244template<
class Derived>
247#ifdef STK_ALGEBRA_VERBOSE
253 int ncol = std::min(Q_.sizeRows(), Q_.sizeCols()),
lastCol;
255 if (
ncol < Q_.sizeCols())
257 Q_.popBackCols(Q_.sizeCols() -
ncol);
258 Q_.popBackCols(Q_.sizeCols() -
ncol);
264 if (
ncol < Q_.sizeRows())
266 Q_.pushBackCols(Q_.sizeRows() -
ncol);
268 Q_.col(
_R(
lastCol+1, Q_.lastIdxCols()) ).setValue(0);
269 for (
int i=
lastCol+1;
i< Q_.endCols(); ++
i) { Q_(
i,
i) = 1.0;}
280 Q_(
_R(Q_.beginRows(),
i-1) ,
i ) = 0.0;
281 Q_(
_R(
i+1, Q_.lastIdxRows()),
i ) *= Q_(
i,
i);
287#ifdef STK_ALGEBRA_VERBOSE
288 stk_cout <<
_T(
"Terminating IQr::compQ().") <<
_T(
"\n");
292template<
class Derived>
297template<
class Derived>
300 if (pos < R_.beginCols())
302 if (R_.lastIdxCols() < pos)
305 if (!compq_) compQ();
307 int niter = std::min(R_.lastIdxCols(), R_.lastIdxRows());
309 for (
int iter = pos+1; iter<=
niter; iter++)
314 R_(iter, iter) = 0.0;
329 R_.update(
Range(pos, std::min(R_.lastIdxRows(), R_.lastIdxCols()), 0));
333template<
class Derived>
334template<
class ColVector_>
339 if (T.range() != Q_.rows())
342 if (!compq_) compQ();
348 for (
int iter = Q_.lastIdxCols()-1,
iter1 = Q_.lastIdxCols(); iter>=
lastColR; iter--,
iter1--)
368template<
class Derived>
369template<
class ColVector_>
373 if (pos < R_.beginCols())
375 if (R_.lastIdxCols() < pos)
377 if (T.range() != Q_.rows())
380 if (!compq_) compQ();
384 R_.update(
_R(pos+1, std::min(R_.lastIdxRows(), R_.lastIdxCols())) );
385 for (
int i=pos+1;
i< std::min(R_.endRows(), R_.endCols()); ++
i) R_(
i,
i) = 0.0;
389 for (
int iter= Q_.lastIdxCols(),
iterm1= Q_.lastIdxCols()-1; iter>pos;
iterm1--, iter--)
406 R_.col(pos) =
Rpos.sub(R_.rangeRowsInCol(pos));
In this file we define and implement utilies class and method for the Algebra project.
In this file we define the ArrayXXTriangular class.
A Array2DVector is a one dimensional horizontal container.
This file define methods for displaying Arrays and Expressions.
In this file we define Givens methods used by the Algebra classes.
In this file we define the Housholder methods used by the Algebra classes.
In this file we define the Interface base class for all the running classes.
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
#define _R(first, last)
Utility macro that can be used in a similar way that first:last.
In this file we define the fundamental type Real.
#define STK_STATIC_ASSERT(COND, MSG)
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
void clear()
clear the object.
The class IQr is an interface class for the method computing the QR Decomposition of a ArrayXX.
virtual ~IQr()
virtual destructor
virtual bool run()
Compute the QR decomposition.
void compQ()
Compute Q (to use after run).
IQr & operator=(IQr const &decomp)
Operator = : overwrite the this with decomp.
hidden::AlgebraTraits< Derived >::RowVector RowVector
hidden::AlgebraTraits< Derived >::Array Array
ArrayUpperTriangularXX R_
R Array of th QR decomposition.
Array const & Q() const
give the matrix Q of the QR decomposition.
void pushBackCol(ColVector_ const &T)
Add a column with value T and update th QR decomposition.
IQr(ExprBase< DerivedExpr > const &Q)
Constructor.
Array Q_
Q Array of the QR decomposition.
void setData(ExprBase< OtherDerived > const &data)
overloading of setData.
ArrayUpperTriangularXX const & R() const
give the matrix R of the QR decomposition.
void popBackCols(int n=1)
Delete the n last columns and update the QR decomposition.
int rank_
estimated rank_ of the matrix A
void eraseCol(int pos)
Delete the column pos and update the QR decomposition.
IQr(Array const &Q, bool ref=false)
Constructor.
bool compq_
is Q computed ?
hidden::AlgebraTraits< Derived >::ColVector ColVector
void setCompQ(bool compq)
Set the compq_ flag.
IQr(IQr const &decomp)
Copy constructor.
void insertCol(ColVector_ const &T, int pos)
Add a column with value T at the position pos and update the QR decomposition.
Interface base class for all classes implementing the curious recursive template paradigm.
Abstract base class for all classes having a.
virtual void update()
update the runner.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
void rightGivens(ArrayBase< TContainer2D > &M, int j1, int j2, typename TContainer2D::Type const &cosinus, typename TContainer2D::Type const &sinus)
Apply Givens rotation.
Real compGivens(Type const &y, Type const &z, Type &cosinus, Type &sinus)
Compute Givens rotation.
void applyLeftHouseholderVector(ArrayBase< Lhs > const &M, ExprBase< Rhs > const &v)
left multiplication by a Householder vector.
void leftGivens(ArrayBase< TContainer2D > &M, int i1, int i2, typename TContainer2D::Type const &cosinus, typename TContainer2D::Type const &sinus)
left multiplication by a Givens ArrayXX.
@ point_
row oriented vector/array/expression
@ vector_
column oriented vector/array/expression
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Arithmetic properties of STK fundamental types.
traits class for the algebra methods.