QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
matrix.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6 Copyright (C) 2003, 2004 Ferdinando Ametrano
7 Copyright (C) 2015 Michael von den Driesch
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file matrix.hpp
23 \brief matrix used in linear algebra.
24*/
25
26#ifndef quantlib_matrix_hpp
27#define quantlib_matrix_hpp
28
29#include <ql/math/array.hpp>
31#include <initializer_list>
32#include <iterator>
33
34namespace QuantLib {
35
36 //! %Matrix used in linear algebra.
37 /*! This class implements the concept of Matrix as used in linear
38 algebra. As such, it is <b>not</b> meant to be used as a
39 container.
40 */
41 class Matrix {
42 public:
43 //! \name Constructors, destructor, and assignment
44 //@{
45 //! creates a null matrix
46 Matrix();
47 //! creates a matrix with the given dimensions
49 //! creates the matrix and fills it with <tt>value</tt>
51 //! creates the matrix and fills it with data from a range.
52 /*! \warning if the range defined by [begin, end) is larger
53 than the size of the matrix, a memory access violation
54 might occur. It is up to the user to avoid this.
55 */
56 template <class Iterator>
57 Matrix(Size rows, Size columns, Iterator begin, Iterator end);
58 Matrix(const Matrix&);
59 Matrix(Matrix&&) noexcept;
60 Matrix(std::initializer_list<std::initializer_list<Real>>);
61 ~Matrix() = default;
62
63 Matrix& operator=(const Matrix&);
64 Matrix& operator=(Matrix&&) noexcept;
65
66 bool operator==(const Matrix&) const;
67 bool operator!=(const Matrix&) const;
68 //@}
69
70 //! \name Algebraic operators
71 /*! \pre all matrices involved in an algebraic expression must have
72 the same size.
73 */
74 //@{
75 const Matrix& operator+=(const Matrix&);
76 const Matrix& operator-=(const Matrix&);
77 const Matrix& operator*=(Real);
78 const Matrix& operator/=(Real);
79 //@}
80
81 typedef Real* iterator;
82 typedef const Real* const_iterator;
86 typedef const Real* const_row_iterator;
96 //! \name Iterator access
97 //@{
98 const_iterator begin() const;
100 const_iterator end() const;
101 iterator end();
122 //@}
123
124 //! \name Element access
125 //@{
126 const_row_iterator operator[](Size) const;
128 row_iterator operator[](Size);
130 Array diagonal() const;
131 Real& operator()(Size i, Size j) const;
132 //@}
133
134 //! \name Inspectors
135 //@{
136 Size rows() const;
137 Size columns() const;
138 bool empty() const;
139 Size size1() const;
140 Size size2() const;
141 //@}
142
143 //! \name Utilities
144 //@{
145 void swap(Matrix&) noexcept;
146 //@}
147 private:
148 std::unique_ptr<Real[]> data_;
150 };
151
152 // algebraic operators
153
154 /*! \relates Matrix */
155 Matrix operator+(const Matrix&, const Matrix&);
156 /*! \relates Matrix */
157 Matrix operator+(const Matrix&, Matrix&&);
158 /*! \relates Matrix */
159 Matrix operator+(Matrix&&, const Matrix&);
160 /*! \relates Matrix */
161 Matrix operator+(Matrix&&, Matrix&&);
162 /*! \relates Matrix */
163 Matrix operator-(const Matrix&);
164 /*! \relates Matrix */
165 Matrix operator-(Matrix&&);
166 /*! \relates Matrix */
167 Matrix operator-(const Matrix&, const Matrix&);
168 /*! \relates Matrix */
169 Matrix operator-(const Matrix&, Matrix&&);
170 /*! \relates Matrix */
171 Matrix operator-(Matrix&&, const Matrix&);
172 /*! \relates Matrix */
173 Matrix operator-(Matrix&&, Matrix&&);
174 /*! \relates Matrix */
175 Matrix operator*(const Matrix&, Real);
176 /*! \relates Matrix */
177 Matrix operator*(Matrix&&, Real);
178 /*! \relates Matrix */
179 Matrix operator*(Real, const Matrix&);
180 /*! \relates Matrix */
181 Matrix operator*(Real, Matrix&&);
182 /*! \relates Matrix */
183 Matrix operator/(const Matrix&, Real);
184 /*! \relates Matrix */
185 Matrix operator/(Matrix&&, Real);
186
187 // vectorial products
188
189 /*! \relates Matrix */
190 Array operator*(const Array&, const Matrix&);
191 /*! \relates Matrix */
192 Array operator*(const Matrix&, const Array&);
193 /*! \relates Matrix */
194 Matrix operator*(const Matrix&, const Matrix&);
195
196 // misc. operations
197
198 /*! \relates Matrix */
199 Matrix transpose(const Matrix&);
200
201 /*! \relates Matrix */
202 Matrix outerProduct(const Array& v1, const Array& v2);
203
204 /*! \relates Matrix */
205 template <class Iterator1, class Iterator2>
206 Matrix outerProduct(Iterator1 v1begin, Iterator1 v1end, Iterator2 v2begin, Iterator2 v2end);
207
208 /*! \relates Matrix */
209 void swap(Matrix&, Matrix&) noexcept;
210
211 /*! \relates Matrix */
212 std::ostream& operator<<(std::ostream&, const Matrix&);
213
214 /*! \relates Matrix */
215 Matrix inverse(const Matrix& m);
216
217 /*! \relates Matrix */
218 Real determinant(const Matrix& m);
219
220 // inline definitions
221
222 inline Matrix::Matrix() : data_((Real*)nullptr) {}
223
225 : data_(rows * columns > 0 ? new Real[rows * columns] : (Real*)nullptr), rows_(rows),
226 columns_(columns) {}
227
228 inline Matrix::Matrix(Size rows, Size columns, Real value)
229 : data_(rows * columns > 0 ? new Real[rows * columns] : (Real*)nullptr), rows_(rows),
230 columns_(columns) {
231 std::fill(begin(),end(),value);
232 }
233
234 template <class Iterator>
235 inline Matrix::Matrix(Size rows, Size columns, Iterator begin, Iterator end)
236 : data_(rows * columns > 0 ? new Real[rows * columns] : (Real*)nullptr), rows_(rows),
237 columns_(columns) {
238 std::copy(begin, end, this->begin());
239 }
240
241 inline Matrix::Matrix(const Matrix& from)
242 : data_(!from.empty() ? new Real[from.rows_ * from.columns_] : (Real*)nullptr),
243 rows_(from.rows_), columns_(from.columns_) {
244 #if defined(QL_PATCH_MSVC) && defined(QL_DEBUG)
245 if (!from.empty())
246 #endif
247 std::copy(from.begin(),from.end(),begin());
248 }
249
250 inline Matrix::Matrix(Matrix&& from) noexcept
251 : data_((Real*)nullptr) {
252 swap(from);
253 }
254
255 inline Matrix::Matrix(std::initializer_list<std::initializer_list<Real>> data)
256 : data_(data.size() == 0 || data.begin()->size() == 0 ?
257 (Real*)nullptr : new Real[data.size() * data.begin()->size()]),
258 rows_(data.size()), columns_(data.size() == 0 ? 0 : data.begin()->size()) {
259 Size i=0;
260 for (const auto& row : data) {
261 #if defined(QL_EXTRA_SAFETY_CHECKS)
262 QL_REQUIRE(row.size() == columns_,
263 "a matrix needs the same number of elements for each row");
264 #endif
265 std::copy(row.begin(), row.end(), row_begin(i));
266 ++i;
267 }
268 }
269
270 inline Matrix& Matrix::operator=(const Matrix& from) {
271 // strong guarantee
272 Matrix temp(from);
273 swap(temp);
274 return *this;
275 }
276
277 inline Matrix& Matrix::operator=(Matrix&& from) noexcept {
278 swap(from);
279 return *this;
280 }
281
282 inline bool Matrix::operator==(const Matrix& to) const {
283 return rows_ == to.rows_ && columns_ == to.columns_ &&
284 std::equal(begin(), end(), to.begin());
285 }
286
287 inline bool Matrix::operator!=(const Matrix& to) const {
288 return !this->operator==(to);
289 }
290
291 inline void Matrix::swap(Matrix& from) noexcept {
292 data_.swap(from.data_);
293 std::swap(rows_, from.rows_);
294 std::swap(columns_, from.columns_);
295 }
296
297 inline const Matrix& Matrix::operator+=(const Matrix& m) {
299 "matrices with different sizes (" <<
300 m.rows_ << "x" << m.columns_ << ", " <<
301 rows_ << "x" << columns_ << ") cannot be "
302 "added");
303 std::transform(begin(), end(), m.begin(), begin(), std::plus<>());
304 return *this;
305 }
306
307 inline const Matrix& Matrix::operator-=(const Matrix& m) {
309 "matrices with different sizes (" <<
310 m.rows_ << "x" << m.columns_ << ", " <<
311 rows_ << "x" << columns_ << ") cannot be "
312 "subtracted");
313 std::transform(begin(), end(), m.begin(), begin(), std::minus<>());
314 return *this;
315 }
316
317 inline const Matrix& Matrix::operator*=(Real x) {
318 std::transform(begin(), end(), begin(), [=](Real y) -> Real { return y * x; });
319 return *this;
320 }
321
322 inline const Matrix& Matrix::operator/=(Real x) {
323 std::transform(begin(),end(),begin(), [=](Real y) -> Real { return y / x; });
324 return *this;
325 }
326
328 return data_.get();
329 }
330
332 return data_.get();
333 }
334
336 return data_.get()+rows_*columns_;
337 }
338
340 return data_.get()+rows_*columns_;
341 }
342
344 return const_reverse_iterator(end());
345 }
346
348 return reverse_iterator(end());
349 }
350
353 }
354
356 return reverse_iterator(begin());
357 }
358
361 #if defined(QL_EXTRA_SAFETY_CHECKS)
363 "row index (" << i << ") must be less than " << rows_ <<
364 ": matrix cannot be accessed out of range");
365 #endif
366 return data_.get()+columns_*i;
367 }
368
370 #if defined(QL_EXTRA_SAFETY_CHECKS)
372 "row index (" << i << ") must be less than " << rows_ <<
373 ": matrix cannot be accessed out of range");
374 #endif
375 return data_.get()+columns_*i;
376 }
377
379 #if defined(QL_EXTRA_SAFETY_CHECKS)
381 "row index (" << i << ") must be less than " << rows_ <<
382 ": matrix cannot be accessed out of range");
383 #endif
384 return data_.get()+columns_*(i+1);
385 }
386
388 #if defined(QL_EXTRA_SAFETY_CHECKS)
390 "row index (" << i << ") must be less than " << rows_ <<
391 ": matrix cannot be accessed out of range");
392 #endif
393 return data_.get()+columns_*(i+1);
394 }
395
399 }
400
402 return reverse_row_iterator(row_end(i));
403 }
404
408 }
409
412 }
413
416 #if defined(QL_EXTRA_SAFETY_CHECKS)
418 "column index (" << i << ") must be less than " << columns_ <<
419 ": matrix cannot be accessed out of range");
420 #endif
421 return const_column_iterator(data_.get()+i,columns_);
422 }
423
425 #if defined(QL_EXTRA_SAFETY_CHECKS)
427 "column index (" << i << ") must be less than " << columns_ <<
428 ": matrix cannot be accessed out of range");
429 #endif
430 return column_iterator(data_.get()+i,columns_);
431 }
432
435 #if defined(QL_EXTRA_SAFETY_CHECKS)
437 "column index (" << i << ") must be less than " << columns_ <<
438 ": matrix cannot be accessed out of range");
439 #endif
441 }
442
444 #if defined(QL_EXTRA_SAFETY_CHECKS)
446 "column index (" << i << ") must be less than " << columns_ <<
447 ": matrix cannot be accessed out of range");
448 #endif
450 }
451
455 }
456
460 }
461
465 }
466
470 }
471
474 return row_begin(i);
475 }
476
478 Matrix::at(Size i) const {
479 QL_REQUIRE(i < rows_, "matrix access out of range");
480 return row_begin(i);
481 }
482
484 return row_begin(i);
485 }
486
488 QL_REQUIRE(i < rows_, "matrix access out of range");
489 return row_begin(i);
490 }
491
492 inline Array Matrix::diagonal() const {
493 Size arraySize = std::min<Size>(rows(), columns());
494 Array tmp(arraySize);
495 for(Size i = 0; i < arraySize; i++)
496 tmp[i] = (*this)[i][i];
497 return tmp;
498 }
499
500 inline Real &Matrix::operator()(Size i, Size j) const {
501 return data_[i*columns()+j];
502 }
503
504 inline Size Matrix::rows() const {
505 return rows_;
506 }
507
508 inline Size Matrix::columns() const {
509 return columns_;
510 }
511
512 inline Size Matrix::size1() const {
513 return rows();
514 }
515
516 inline Size Matrix::size2() const {
517 return columns();
518 }
519
520 inline bool Matrix::empty() const {
521 return rows_ == 0 || columns_ == 0;
522 }
523
524 inline Matrix operator+(const Matrix& m1, const Matrix& m2) {
525 QL_REQUIRE(m1.rows() == m2.rows() &&
526 m1.columns() == m2.columns(),
527 "matrices with different sizes (" <<
528 m1.rows() << "x" << m1.columns() << ", " <<
529 m2.rows() << "x" << m2.columns() << ") cannot be "
530 "added");
531 Matrix temp(m1.rows(),m1.columns());
532 std::transform(m1.begin(), m1.end(), m2.begin(), temp.begin(), std::plus<>());
533 return temp;
534 }
535
536 inline Matrix operator+(const Matrix& m1, Matrix&& m2) {
537 QL_REQUIRE(m1.rows() == m2.rows() &&
538 m1.columns() == m2.columns(),
539 "matrices with different sizes (" <<
540 m1.rows() << "x" << m1.columns() << ", " <<
541 m2.rows() << "x" << m2.columns() << ") cannot be "
542 "added");
543 std::transform(m1.begin(), m1.end(), m2.begin(), m2.begin(), std::plus<>());
544 return std::move(m2);
545 }
546
547 inline Matrix operator+(Matrix&& m1, const Matrix& m2) {
548 QL_REQUIRE(m1.rows() == m2.rows() &&
549 m1.columns() == m2.columns(),
550 "matrices with different sizes (" <<
551 m1.rows() << "x" << m1.columns() << ", " <<
552 m2.rows() << "x" << m2.columns() << ") cannot be "
553 "added");
554 std::transform(m1.begin(), m1.end(), m2.begin(), m1.begin(), std::plus<>());
555 return std::move(m1);
556 }
557
558 inline Matrix operator+(Matrix&& m1, Matrix&& m2) { // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
559 QL_REQUIRE(m1.rows() == m2.rows() &&
560 m1.columns() == m2.columns(),
561 "matrices with different sizes (" <<
562 m1.rows() << "x" << m1.columns() << ", " <<
563 m2.rows() << "x" << m2.columns() << ") cannot be "
564 "added");
565 std::transform(m1.begin(), m1.end(), m2.begin(), m1.begin(), std::plus<>());
566 return std::move(m1);
567 }
568
569 inline Matrix operator-(const Matrix& m1) {
570 Matrix temp(m1.rows(), m1.columns());
571 std::transform(m1.begin(), m1.end(), temp.begin(), std::negate<>());
572 return temp;
573 }
574
575 inline Matrix operator-(Matrix&& m1) {
576 std::transform(m1.begin(), m1.end(), m1.begin(), std::negate<>());
577 return std::move(m1);
578 }
579
580 inline Matrix operator-(const Matrix& m1, const Matrix& m2) {
581 QL_REQUIRE(m1.rows() == m2.rows() &&
582 m1.columns() == m2.columns(),
583 "matrices with different sizes (" <<
584 m1.rows() << "x" << m1.columns() << ", " <<
585 m2.rows() << "x" << m2.columns() << ") cannot be "
586 "subtracted");
587 Matrix temp(m1.rows(),m1.columns());
588 std::transform(m1.begin(), m1.end(), m2.begin(), temp.begin(), std::minus<>());
589 return temp;
590 }
591
592 inline Matrix operator-(const Matrix& m1, Matrix&& m2) {
593 QL_REQUIRE(m1.rows() == m2.rows() &&
594 m1.columns() == m2.columns(),
595 "matrices with different sizes (" <<
596 m1.rows() << "x" << m1.columns() << ", " <<
597 m2.rows() << "x" << m2.columns() << ") cannot be "
598 "subtracted");
599 std::transform(m1.begin(), m1.end(), m2.begin(), m2.begin(), std::minus<>());
600 return std::move(m2);
601 }
602
603 inline Matrix operator-(Matrix&& m1, const Matrix& m2) {
604 QL_REQUIRE(m1.rows() == m2.rows() &&
605 m1.columns() == m2.columns(),
606 "matrices with different sizes (" <<
607 m1.rows() << "x" << m1.columns() << ", " <<
608 m2.rows() << "x" << m2.columns() << ") cannot be "
609 "subtracted");
610 std::transform(m1.begin(), m1.end(), m2.begin(), m1.begin(), std::minus<>());
611 return std::move(m1);
612 }
613
614 inline Matrix operator-(Matrix&& m1, Matrix&& m2) { // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
615 QL_REQUIRE(m1.rows() == m2.rows() &&
616 m1.columns() == m2.columns(),
617 "matrices with different sizes (" <<
618 m1.rows() << "x" << m1.columns() << ", " <<
619 m2.rows() << "x" << m2.columns() << ") cannot be "
620 "subtracted");
621 std::transform(m1.begin(), m1.end(), m2.begin(), m1.begin(), std::minus<>());
622 return std::move(m1);
623 }
624
625 inline Matrix operator*(const Matrix& m, Real x) {
626 Matrix temp(m.rows(),m.columns());
627 std::transform(m.begin(), m.end(), temp.begin(), [=](Real y) -> Real { return y * x; });
628 return temp;
629 }
630
631 inline Matrix operator*(Matrix&& m, Real x) {
632 std::transform(m.begin(), m.end(), m.begin(), [=](Real y) -> Real { return y * x; });
633 return std::move(m);
634 }
635
636 inline Matrix operator*(Real x, const Matrix& m) {
637 Matrix temp(m.rows(),m.columns());
638 std::transform(m.begin(), m.end(), temp.begin(), [=](Real y) -> Real { return x * y; });
639 return temp;
640 }
641
642 inline Matrix operator*(Real x, Matrix&& m) {
643 std::transform(m.begin(), m.end(), m.begin(), [=](Real y) -> Real { return x * y; });
644 return std::move(m);
645 }
646
647 inline Matrix operator/(const Matrix& m, Real x) {
648 Matrix temp(m.rows(),m.columns());
649 std::transform(m.begin(), m.end(), temp.begin(), [=](Real y) -> Real { return y / x; });
650 return temp;
651 }
652
653 inline Matrix operator/(Matrix&& m, Real x) {
654 std::transform(m.begin(), m.end(), m.begin(), [=](Real y) -> Real { return y / x; });
655 return std::move(m);
656 }
657
658 inline Array operator*(const Array& v, const Matrix& m) {
659 QL_REQUIRE(v.size() == m.rows(),
660 "vectors and matrices with different sizes ("
661 << v.size() << ", " << m.rows() << "x" << m.columns() <<
662 ") cannot be multiplied");
663 Array result(m.columns());
664 for (Size i=0; i<result.size(); i++)
665 result[i] =
666 std::inner_product(v.begin(),v.end(),
667 m.column_begin(i),Real(0.0));
668 return result;
669 }
670
671 inline Array operator*(const Matrix& m, const Array& v) {
672 QL_REQUIRE(v.size() == m.columns(),
673 "vectors and matrices with different sizes ("
674 << v.size() << ", " << m.rows() << "x" << m.columns() <<
675 ") cannot be multiplied");
676 Array result(m.rows());
677 for (Size i=0; i<result.size(); i++)
678 result[i] =
679 std::inner_product(v.begin(),v.end(),m.row_begin(i),Real(0.0));
680 return result;
681 }
682
683 inline Matrix operator*(const Matrix& m1, const Matrix& m2) {
684 QL_REQUIRE(m1.columns() == m2.rows(),
685 "matrices with different sizes (" <<
686 m1.rows() << "x" << m1.columns() << ", " <<
687 m2.rows() << "x" << m2.columns() << ") cannot be "
688 "multiplied");
689 Matrix result(m1.rows(),m2.columns(),0.0);
690 for (Size i=0; i<result.rows(); ++i) {
691 for (Size k=0; k<m1.columns(); ++k) {
692 for (Size j=0; j<result.columns(); ++j) {
693 result[i][j] += m1[i][k]*m2[k][j];
694 }
695 }
696 }
697 return result;
698 }
699
700 inline Matrix transpose(const Matrix& m) {
701 Matrix result(m.columns(),m.rows());
702 #if defined(QL_PATCH_MSVC) && defined(QL_DEBUG)
703 if (!m.empty())
704 #endif
705 for (Size i=0; i<m.rows(); i++)
706 std::copy(m.row_begin(i),m.row_end(i),result.column_begin(i));
707 return result;
708 }
709
710 inline Matrix outerProduct(const Array& v1, const Array& v2) {
711 return outerProduct(v1.begin(), v1.end(), v2.begin(), v2.end());
712 }
713
714 template <class Iterator1, class Iterator2>
715 inline Matrix outerProduct(Iterator1 v1begin, Iterator1 v1end, Iterator2 v2begin, Iterator2 v2end) {
716
717 Size size1 = std::distance(v1begin, v1end);
718 QL_REQUIRE(size1>0, "null first vector");
719
720 Size size2 = std::distance(v2begin, v2end);
721 QL_REQUIRE(size2>0, "null second vector");
722
723 Matrix result(size1, size2);
724
725 for (Size i=0; v1begin!=v1end; i++, v1begin++)
726 std::transform(v2begin, v2end, result.row_begin(i),
727 [=](Real y) -> Real { return y * (*v1begin); });
728
729 return result;
730 }
731
732 inline void swap(Matrix& m1, Matrix& m2) noexcept {
733 m1.swap(m2);
734 }
735
736 inline std::ostream& operator<<(std::ostream& out, const Matrix& m) {
737 std::streamsize width = out.width();
738 for (Size i=0; i<m.rows(); i++) {
739 out << "| ";
740 for (Size j=0; j<m.columns(); j++)
741 out << std::setw(int(width)) << m[i][j] << " ";
742 out << "|\n";
743 }
744 return out;
745 }
746
747}
748
749
750#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
Size size() const
dimension of the array
Definition: array.hpp:495
const_iterator begin() const
Definition: array.hpp:503
Matrix used in linear algebra.
Definition: matrix.hpp:41
const Real * const_iterator
Definition: matrix.hpp:82
std::unique_ptr< Real[]> data_
Definition: matrix.hpp:148
const_row_iterator row_begin(Size i) const
Definition: matrix.hpp:360
const Matrix & operator/=(Real)
Definition: matrix.hpp:322
std::reverse_iterator< row_iterator > reverse_row_iterator
Definition: matrix.hpp:87
Size size2() const
Definition: matrix.hpp:516
const_reverse_iterator rend() const
Definition: matrix.hpp:351
Real * iterator
Definition: matrix.hpp:81
Matrix transpose(const Matrix &)
Definition: matrix.hpp:700
Matrix()
creates a null matrix
Definition: matrix.hpp:222
const_reverse_row_iterator row_rbegin(Size i) const
Definition: matrix.hpp:397
const_iterator begin() const
Definition: matrix.hpp:327
Size size1() const
Definition: matrix.hpp:512
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: matrix.hpp:84
const_reverse_column_iterator column_rend(Size i) const
Definition: matrix.hpp:463
bool operator!=(const Matrix &) const
Definition: matrix.hpp:287
const Matrix & operator-=(const Matrix &)
Definition: matrix.hpp:307
bool empty() const
Definition: matrix.hpp:520
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: matrix.hpp:93
Size rows() const
Definition: matrix.hpp:504
std::reverse_iterator< const_row_iterator > const_reverse_row_iterator
Definition: matrix.hpp:89
Array diagonal() const
Definition: matrix.hpp:492
const_iterator end() const
Definition: matrix.hpp:335
const_reverse_row_iterator row_rend(Size i) const
Definition: matrix.hpp:406
Size columns() const
Definition: matrix.hpp:508
const_column_iterator column_begin(Size i) const
Definition: matrix.hpp:415
Matrix outerProduct(const Array &v1, const Array &v2)
Definition: matrix.hpp:710
std::reverse_iterator< iterator > reverse_iterator
Definition: matrix.hpp:83
const_row_iterator row_end(Size i) const
Definition: matrix.hpp:378
Real * row_iterator
Definition: matrix.hpp:85
~Matrix()=default
Real & operator()(Size i, Size j) const
Definition: matrix.hpp:500
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: matrix.hpp:95
const_column_iterator column_end(Size i) const
Definition: matrix.hpp:434
void swap(Matrix &) noexcept
Definition: matrix.hpp:291
Matrix & operator=(const Matrix &)
Definition: matrix.hpp:270
const_row_iterator operator[](Size) const
Definition: matrix.hpp:473
step_iterator< iterator > column_iterator
Definition: matrix.hpp:90
const_reverse_column_iterator column_rbegin(Size i) const
Definition: matrix.hpp:453
const_row_iterator at(Size) const
Definition: matrix.hpp:478
step_iterator< const_iterator > const_column_iterator
Definition: matrix.hpp:91
const_reverse_iterator rbegin() const
Definition: matrix.hpp:343
bool operator==(const Matrix &) const
Definition: matrix.hpp:282
const Matrix & operator*=(Real)
Definition: matrix.hpp:317
const Matrix & operator+=(const Matrix &)
Definition: matrix.hpp:297
Real determinant(const Matrix &m)
Definition: matrix.cpp:81
Matrix inverse(const Matrix &m)
Definition: matrix.cpp:44
const Real * const_row_iterator
Definition: matrix.hpp:86
Iterator advancing in constant steps.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Quantity operator-(const Quantity &m1, const Quantity &m2)
Definition: quantity.hpp:171
Quantity operator*(const Quantity &m, Real x)
Definition: quantity.hpp:177
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
Quantity operator+(const Quantity &m1, const Quantity &m2)
Definition: quantity.hpp:165
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
Matrix outerProduct(const Array &v1, const Array &v2)
Definition: matrix.hpp:710
Matrix transpose(const Matrix &m)
Definition: matrix.hpp:700
Real operator/(const Quantity &m1, const Quantity &m2)
Definition: quantity.cpp:86
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v
Iterator advancing in constant steps.