38 std::unique_ptr<int[]> lipvt(
new int[
n]);
39 std::unique_ptr<Real[]> rdiag(
new Real[
n]);
40 std::unique_ptr<Real[]> wa(
new Real[
n]);
43 lipvt.get(),
n, rdiag.get(), rdiag.get(), wa.get());
44 if (
r.columns() !=
n ||
r.rows() !=
n)
47 for (
Size i=0; i <
n; ++i) {
48 std::fill(
r.row_begin(i),
r.row_begin(i)+i, 0.0);
55 std::fill(
r.row_begin(i)+i+1,
r.row_end(i), 0.0);
59 if (
q.rows() != m ||
q.columns() !=
n)
63 std::fill(
q.begin(),
q.end(), 0.0);
70 for (
Integer i=u-1; i >=0; --i) {
72 const Real tau = 1.0/mT[i][i];
74 std::fill(
v.begin(),
v.begin()+i, 0.0);
78 for (
Size l=0; l <
n; ++l)
79 w[l] += std::inner_product(
80 v.begin()+i,
v.end(),
q.column_begin(l)+i,
Real(0.0));
82 for (
Size k=i; k < m; ++k) {
83 const Real a = tau*
v[k];
84 for (
Size l=0; l <
n; ++l)
92 for (
Size k=0; k < m; ++k) {
96 for (
Size j=0; j < std::min(
n, m); ++j) {
97 const Real t3 = mT[j][j];
102 for (
Size i=j; i<m; ++i) {
108 std::fill(
q.row_begin(k) + std::min(
n, m),
q.row_end(k), 0.0);
112 std::vector<Size> ipvt(
n);
115 std::copy(lipvt.get(), lipvt.get()+
n, ipvt.begin());
118 for (
Size i=0; i <
n; ++i)
126 bool pivot,
const Array&
d) {
130 QL_REQUIRE(
b.size() == m,
"dimensions of A and b don't match");
132 "dimensions of A and d don't match");
138 std::unique_ptr<int[]> ipvt(
new int[
n]);
139 std::copy(lipvt.begin(), lipvt.end(), ipvt.get());
143 std::unique_ptr<Real[]> sdiag(
new Real[
n]);
144 std::unique_ptr<Real[]> wa(
new Real[
n]);
148 std::copy(
d.begin(),
d.end(), ld.
begin());
156 x.
begin(), sdiag.get(), wa.get());
1-D array used in linear algebra.
const_iterator end() const
const_iterator begin() const
Matrix used in linear algebra.
const_row_iterator row_begin(Size i) const
const_iterator begin() const
const_column_iterator column_begin(Size i) const
const_row_iterator row_end(Size i) const
const_column_iterator column_end(Size i) const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
wrapper for MINPACK minimization routine
void qrfac(int m, int n, Real *a, int, int pivot, int *ipvt, int, Real *rdiag, Real *acnorm, Real *wa)
void qrsolv(int n, Real *r, int ldr, const int *ipvt, const Real *diag, const Real *qtb, Real *x, Real *sdiag, Real *wa)
Array qrSolve(const Matrix &a, const Array &b, bool pivot, const Array &d)
QR Solve.
std::vector< Size > qrDecomposition(const Matrix &M, Matrix &q, Matrix &r, bool pivot)
QR decompoisition.
Matrix transpose(const Matrix &m)
ext::shared_ptr< YieldTermStructure > q
ext::shared_ptr< YieldTermStructure > r
ext::shared_ptr< BlackVolTermStructure > v