CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
hessian.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <vector>
38
39#include "../../config.h"
40#include "../../misc/constructVector.hpp"
41#include "dummy.hpp"
42#include "hessianInterface.hpp"
43#include "staticDummy.hpp"
44
46namespace codi {
47
58 template<typename T_T, typename T_Store = std::vector<T_T>>
59 struct Hessian : public HessianInterface<T_T> {
60 public:
61
62 using T = CODI_DD(T_T, double);
63 using Store = CODI_DD(T_Store, std::vector<double>);
64
65 protected:
67
68 size_t m;
69 size_t n;
70
71 public:
72
74 explicit Hessian(size_t m, size_t n) : values(constructVector<Store>(n * n * m)), m(m), n(n) {}
75
77 CODI_INLINE size_t getM() const {
78 return m;
79 }
80
82 CODI_INLINE size_t getN() const {
83 return n;
84 }
85
87 CODI_INLINE T operator()(size_t const i, size_t const j, size_t const k) const {
88 return values.data()[computeIndex(i, j, k)];
89 }
90
92 CODI_INLINE T& operator()(size_t const i, size_t const j, size_t const k) {
93 return values.data()[computeIndex(i, j, k)];
94 }
95
97 CODI_INLINE void resize(size_t const m, size_t const n) {
98 this->m = m;
99 this->n = n;
100
101 values.resize(m * n * n);
102 }
103
105 CODI_INLINE size_t size() const {
106 return m * n * n;
107 }
108
109 private:
110 CODI_INLINE size_t computeIndex(size_t const i, size_t const j, size_t const k) const {
111 return k * n * m + i * n + j;
112 }
113 };
114
116 struct DummyHessian : public HessianInterface<DummyValue> {
117 public:
118
120 size_t getM() const {
121 return 0;
122 }
123
125 size_t getN() const {
126 return 0;
127 }
128
130 CODI_INLINE DummyValue operator()(size_t const i, size_t const j, size_t const k) const {
131 CODI_UNUSED(i, j, k);
132
133 return DummyValue();
134 }
135
137 CODI_INLINE_NO_FA DummyValue& operator()(size_t const i, size_t const j, size_t const k) {
138 CODI_UNUSED(i, j, k);
139
141 }
142
144 void resize(size_t const m, size_t const n) {
145 CODI_UNUSED(m, n);
146 }
147
149 size_t size() const {
150 return 0;
151 }
152 };
153}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_INLINE_NO_FA
See codi::Config::ForcedInlines.
Definition config.h:459
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
V constructVector(size_t const size)
Helper for the construction of vector types provided by the user.
Definition constructVector.hpp:83
Dummy Hessian. Has size zero and no logic in any call.
Definition hessian.hpp:116
DummyValue & operator()(size_t const i, size_t const j, size_t const k)
Reference access.
Definition hessian.hpp:137
size_t getN() const
Get size of columns (input variables).
Definition hessian.hpp:125
void resize(size_t const m, size_t const n)
Resize to the new dimensions.
Definition hessian.hpp:144
DummyValue operator()(size_t const i, size_t const j, size_t const k) const
Value access.
Definition hessian.hpp:130
size_t getM() const
Get size of rows (output variables).
Definition hessian.hpp:120
size_t size() const
Get total size of the Hessian.
Definition hessian.hpp:149
Dummy value that can be assigned.
Definition dummy.hpp:43
General interface for Hessian access in CoDiPack.
Definition hessianInterface.hpp:64
Default implementation of the Hessian interface.
Definition hessian.hpp:59
Hessian(size_t m, size_t n)
Constructor.
Definition hessian.hpp:74
T_T T
See Hessian.
Definition hessian.hpp:62
size_t getN() const
Get size of columns (input variables).
Definition hessian.hpp:82
size_t n
Number of function inputs.
Definition hessian.hpp:69
size_t m
Number of function outputs.
Definition hessian.hpp:68
T operator()(size_t const i, size_t const j, size_t const k) const
Value access.
Definition hessian.hpp:87
void resize(size_t const m, size_t const n)
Resize to the new dimensions.
Definition hessian.hpp:97
T_Store Store
See Hessian.
Definition hessian.hpp:63
size_t getM() const
Get size of rows (output variables).
Definition hessian.hpp:77
Store values
Storage for the data.
Definition hessian.hpp:66
size_t size() const
Get total size of the Hessian.
Definition hessian.hpp:105
T & operator()(size_t const i, size_t const j, size_t const k)
Reference access.
Definition hessian.hpp:92
Static dummy objects for e.g. default reference arguments.
Definition staticDummy.hpp:42