Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
matrixfunctions.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#ifdef ORE_USE_EIGEN
22
23#if defined(__GNUC__)
24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wfloat-conversion"
26#pragma GCC diagnostic ignored "-Wunused-variable"
27#endif
28
29#include <unsupported/Eigen/MatrixFunctions>
30
31#if defined(__GNUC__)
32#pragma GCC diagnostic pop
33#pragma GCC diagnostic pop
34#endif
35
36namespace QuantExt {
37
38namespace {
39
40inline Eigen::MatrixXd ql2eigen(const QuantLib::Matrix& m) {
41 Eigen::MatrixXd res(m.rows(), m.columns());
42 for (size_t i = 0; i < m.rows(); ++i)
43 for (size_t j = 0; j < m.columns(); ++j)
44 res(i, j) = m(i, j);
45 return res;
46}
47
48inline QuantLib::Matrix eigen2ql(const Eigen::MatrixXd& m) {
49 QuantLib::Matrix res(m.rows(), m.cols());
50 for (long i = 0; i < m.rows(); ++i)
51 for (long j = 0; j < m.cols(); ++j)
52 res(i, j) = m(i, j);
53 return res;
54}
55
56} // anonymous namespace
57
58bool supports_Logm() { return true; }
59bool supports_Expm() { return true; }
60
61QuantLib::Matrix Logm(const QuantLib::Matrix& m) {
62 QuantLib::Matrix res = eigen2ql(ql2eigen(m).log());
63 return res;
64}
65
66QuantLib::Matrix Expm(const QuantLib::Matrix& m) {
67 QuantLib::Matrix res = eigen2ql(ql2eigen(m).exp());
68 return res;
69}
70} // namespace QuantExt
71
72#else
73
74#include <ql/math/matrixutilities/expm.hpp>
75
76namespace QuantExt {
77
78bool supports_Logm() { return false; }
79bool supports_Expm() { return true; }
80
81QuantLib::Matrix Logm(const QuantLib::Matrix& m) {
82 QL_FAIL("Logm(): no implementation provided, you can e.g. install Eigen and rebuild ORE to enable this function.");
83}
84
85QuantLib::Matrix Expm(const QuantLib::Matrix& m) { return QuantLib::Expm(m); }
86
87} // namespace QuantExt
88
89#endif
matrix functions
QuantLib::Matrix Logm(const QuantLib::Matrix &m)
QuantLib::Matrix Expm(const QuantLib::Matrix &m)
CompiledFormula exp(CompiledFormula x)
bool supports_Logm()
bool supports_Expm()
CompiledFormula log(CompiledFormula x)