CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
evaluationHelper.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 <array>
38#include <vector>
39
40#include "../../../codi.hpp"
41#include "../../expressions/lhsExpressionInterface.hpp"
42#include "../../misc/constructVector.hpp"
43#include "../../traits/gradientTraits.hpp"
44#include "../../traits/tapeTraits.hpp"
45#include "../data/dummy.hpp"
46#include "../data/hessian.hpp"
47#include "../data/jacobian.hpp"
48#include "tapeHelper.hpp"
49
51namespace codi {
52
64 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
65 typename T_OutputStore = std::vector<T_Type>>
67 public:
68
70 using Func = CODI_DD(T_Func, CODI_T(void (*)(T_InputStore const&, T_OutputStore&)));
71 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
72 using InputStore = CODI_DD(T_InputStore, std::vector<Type>);
73 using OutputStore = CODI_DD(T_OutputStore, std::vector<Type>);
74
75 protected:
76
77 size_t m;
78 size_t n;
79
81
84
87
88 public:
89
91 EvaluationHandleBase(Func& func, size_t m, size_t n)
92 : m(m),
93 n(n),
94 func(func),
98 dummyJacobian() {}
99
101 template<typename VecX, typename VecY>
102 void computePrimal(VecX const& locX, VecY& locY);
103
105 template<typename VecX, typename Jac, typename VecY>
106 void computeJacobian(VecX const& locX, Jac& jac, VecY& locY);
107
109 template<typename VecX, typename Hes, typename VecY, typename Jac>
110 void computeHessian(VecX const& locX, Hes& hes, VecY& locY, Jac& jac);
111
112 protected:
113
115 template<typename VecX>
116 void setPrimalInputs(VecX const& locX);
117
119 template<typename VecY>
120 void getPrimalOutputs(VecY& locY);
121
123 void eval() {
124 func(x, y);
125 }
126 };
127
131 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
132 typename T_OutputStore = std::vector<T_Type>>
133 struct EvaluationHandleForward : public EvaluationHandleBase<T_Func, T_Type, T_InputStore, T_OutputStore> {
134 public:
135
137 using Func = CODI_DD(T_Func, CODI_T(void (*)(T_InputStore const&, T_OutputStore&)));
138 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
139 using InputStore = CODI_DD(T_InputStore, std::vector<Type>);
140 using OutputStore = CODI_DD(T_OutputStore, std::vector<Type>);
141
143
144 // Forward constructors of the base.
146
148 template<typename VecX>
149 void setPrimalInputs(VecX const& locX) {
150 codiAssert(locX.size() <= this->x.size());
151 for (size_t j = 0; j < locX.size(); j += 1) {
152 this->x[j] = locX[j];
153 }
154 }
155
157 template<typename VecY>
158 void getPrimalOutputs(VecY& locY) {
159 codiAssert(locY.size() <= this->y.size());
160 for (size_t i = 0; i < locY.size(); i += 1) {
161 locY[i] = RealTraits::getPassiveValue(this->y[i].getValue());
162 }
163 }
164
166 template<typename VecX, typename VecY>
167 void computePrimal(VecX const& locX, VecY& locY) {
168 setPrimalInputs(locX);
169
170 this->eval();
171
172 getPrimalOutputs(locY);
173 }
174
178 template<typename VecX, typename Jac, typename VecY>
179 void computeJacobian(VecX const& locX, Jac& jac, VecY& locY) {
180 setPrimalInputs(locX);
181
182 JacobianConvertWrapper<Jac> wrapper(jac);
183
185 size_t constexpr VectorSizeFirstOrder = GradientTraits1st::dim;
186
187 for (size_t j = 0; j < locX.size(); j += VectorSizeFirstOrder) {
188 for (size_t vecPos = 0; vecPos < VectorSizeFirstOrder && j + vecPos < locX.size(); vecPos += 1) {
189 GradientTraits1st::at(this->x[j + vecPos].gradient(), vecPos) = 1.0;
190 }
191
192 this->eval();
193
194 if (0 == j) {
195 getPrimalOutputs(locY);
196 }
197
198 for (size_t i = 0; i < this->y.size(); i += 1) {
199 for (size_t vecPos = 0; vecPos < VectorSizeFirstOrder && j + vecPos < locX.size(); vecPos += 1) {
200 wrapper(i, j + vecPos) = GradientTraits1st::at(this->y[i].gradient(), vecPos);
201 }
202 }
203
204 for (size_t vecPos = 0; vecPos < VectorSizeFirstOrder && j + vecPos < locX.size(); vecPos += 1) {
205 GradientTraits1st::at(this->x[j + vecPos].gradient(), vecPos) = 0.0;
206 }
207 }
208 }
209
214 template<typename VecX, typename Hes, typename VecY, typename Jac>
215 void computeHessian(VecX const& locX, Hes& hes, VecY& locY, Jac& jac) {
216 setPrimalInputs(locX);
217
219 size_t constexpr VectorSizeFirstOrder = GradientTraits1st::dim;
220
221 using GradientTraits2nd = GradientTraits::TraitsImplementation<CODI_DD(typename Type::Real::Gradient, double)>;
222 size_t constexpr VectorSizeSecondOrder = GradientTraits2nd::dim;
223
224 for (size_t k = 0; k < locX.size(); k += VectorSizeFirstOrder) {
225 // Set derivatives from k to k + vecSize_k.
226 for (size_t vecPos = 0; vecPos < VectorSizeFirstOrder && k + vecPos < locX.size(); vecPos += 1) {
227 GradientTraits1st::at(this->x[k + vecPos].gradient(), vecPos).value() = 1.0;
228 }
229
230 // The j = k init is no problem, it will evaluate slightly more elements around the diagonal.
231 for (size_t j = k; j < locX.size(); j += VectorSizeSecondOrder) {
232 // Set derivatives from j to j + vecSize_j.
233 for (size_t vecPos = 0; vecPos < VectorSizeSecondOrder && j + vecPos < locX.size(); vecPos += 1) {
234 GradientTraits2nd::at(this->x[j + vecPos].value().gradient(), vecPos) = 1.0;
235 }
236
237 this->eval();
238
239 if (0 == j && 0 == k) {
240 getPrimalOutputs(locY);
241 }
242
243 // Extract all Hessian values, this populates the Hessian from (j,k) to (j + vecSize_j, k + vecSize_k).
244 for (size_t i = 0; i < this->y.size(); i += 1) {
245 for (size_t vecPos1st = 0; vecPos1st < VectorSizeFirstOrder && k + vecPos1st < locX.size();
246 vecPos1st += 1) {
247 for (size_t vecPos2nd = 0; vecPos2nd < VectorSizeSecondOrder && j + vecPos2nd < locX.size();
248 vecPos2nd += 1) {
249 auto& firstGrad = GradientTraits1st::at(this->y[i].gradient(), vecPos1st);
250 auto& secondGrad = GradientTraits2nd::at(firstGrad.gradient(), vecPos2nd);
251
252 hes(i, j + vecPos2nd, k + vecPos1st) = secondGrad;
253 hes(i, k + vecPos1st, j + vecPos2nd) = secondGrad; // Symmetry
254 }
255 }
256
257 if (k == 0) {
258 for (size_t vecPos = 0; vecPos < VectorSizeSecondOrder && j + vecPos < locX.size(); vecPos += 1) {
259 jac(i, j + vecPos) = GradientTraits2nd::at(this->y[i].value().gradient(), vecPos);
260 }
261 }
262 }
263
264 // Reset the derivative seeding.
265 for (size_t vecPos = 0; vecPos < VectorSizeSecondOrder && j + vecPos < locX.size(); vecPos += 1) {
266 GradientTraits2nd::at(this->x[j + vecPos].value().gradient(), vecPos) = 0.0;
267 }
268 }
269
270 // Reset the derivative seeding.
271 for (size_t vecPos = 0; vecPos < VectorSizeFirstOrder && k + vecPos < locX.size(); vecPos += 1) {
272 GradientTraits1st::at(this->x[k + vecPos].gradient(), vecPos).value() = 0.0;
273 }
274 }
275 }
276 };
277
281 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
282 typename T_OutputStore = std::vector<T_Type>>
283 struct EvaluationHandleReverseBase : public EvaluationHandleBase<T_Func, T_Type, T_InputStore, T_OutputStore> {
284 public:
285
287 using Func = CODI_DD(T_Func, CODI_T(void (*)(T_InputStore const&, T_OutputStore&)));
289 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
290 using InputStore = CODI_DD(T_InputStore, std::vector<Type>);
291 using OutputStore = CODI_DD(T_OutputStore, std::vector<Type>);
292
294
295 protected:
296
298
299 public:
300
302 EvaluationHandleReverseBase(Func& func, size_t m, size_t n) : Base(func, m, n), th() {}
303
305 template<typename VecX>
306 void setPrimalInputs(VecX const& locX, bool reg) {
307 codiAssert(locX.size() <= this->x.size());
308 for (size_t j = 0; j < locX.size(); j += 1) {
309 this->x[j] = locX[j];
310
311 if (reg) {
312 th.registerInput(this->x[j]);
313 }
314 }
315 }
316
318 template<typename VecY>
319 void getPrimalOutputs(VecY& locY, bool reg) {
320 codiAssert(locY.size() <= this->y.size());
321 for (size_t i = 0; i < this->y.size(); i += 1) {
322 if (reg) {
323 th.registerOutput(this->y[i]);
324 }
325
326 locY[i] = RealTraits::getPassiveValue(this->y[i].getValue());
327 }
328 }
329
331 template<typename VecX, typename VecY>
332 void computePrimal(VecX const& locX, VecY& locY) {
333 setPrimalInputs(locX, false);
334
335 this->eval();
336
337 getPrimalOutputs(locY, false);
338 }
339
345 template<typename VecX, typename Jac, typename VecY>
346 void computeJacobian(VecX const& locX, Jac& jac, VecY& locY) {
347 recordTape(locX, locY);
348
349 th.evalJacobian(jac);
350 }
351
353 template<typename VecX, typename Hes, typename VecY, typename Jac>
354 void computeHessian(VecX const& locX, Hes& hes, VecY& locY, Jac& jac);
355
356 protected:
357
359 template<typename VecX, typename VecY>
360 void recordTape(VecX const& locX, VecY& locY) {
361 th.startRecording();
362 setPrimalInputs(locX, true);
363
364 this->eval();
365
366 getPrimalOutputs(locY, true);
367 th.stopRecording();
368 }
369 };
370
381 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
382 typename T_OutputStore = std::vector<T_Type>>
384 : public EvaluationHandleReverseBase<T_Func, T_Type, T_InputStore, T_OutputStore> {
385 public:
386
388 using Func = CODI_DD(T_Func, CODI_T(void (*)(T_InputStore const&, T_OutputStore&)));
389 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
390 using InputStore = CODI_DD(T_InputStore, std::vector<Type>);
391 using OutputStore = CODI_DD(T_OutputStore, std::vector<Type>);
392
395
396 // Use constructors of the base class.
398
402 template<typename VecX, typename Hes, typename VecY, typename Jac>
403 void computeHessian(VecX const& locX, Hes& hes, VecY& locY, Jac& jac) {
404 this->recordTape(locX, locY);
405
406 this->th.evalHessian(hes, jac);
407 }
408 };
409
418 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
419 typename T_OutputStore = std::vector<T_Type>>
421 : public EvaluationHandleReverseBase<T_Func, T_Type, T_InputStore, T_OutputStore> {
422 public:
424 using Func = CODI_DD(T_Func, CODI_T(void (*)(T_InputStore const&, T_OutputStore&)));
425 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
426 using InputStore = CODI_DD(T_InputStore, std::vector<Type>);
427 using OutputStore = CODI_DD(T_OutputStore, std::vector<Type>);
428
431
432 // Use constructors of the base class.
434
438 template<typename VecX, typename Hes, typename VecY, typename Jac>
439 void computeHessian(VecX const& locX, Hes& hes, VecY& locY, Jac& jac) {
440 this->setPrimalInputs(locX, false);
441
442 Algorithms<Type>::computeHessian(this->func, this->x, this->y, hes, jac);
443
444 this->getPrimalOutputs(locY, false);
445 }
446 };
447
449 template<typename T_Func, typename T_Type, typename T_InputStore = std::vector<T_Type>,
450 typename T_OutputStore = std::vector<T_Type>, typename = void>
451 struct EvaluationHandle : public EvaluationHandleBase<T_Func, T_Type, T_InputStore, T_OutputStore> {};
452
454 template<typename T_Func, typename T_Type, typename T_InputStore, typename T_OutputStore>
455 struct EvaluationHandle<T_Func, T_Type, T_InputStore, T_OutputStore,
456 TapeTraits::EnableIfForwardTape<typename T_Type::Tape>>
457 : public EvaluationHandleForward<T_Func, T_Type, T_InputStore, T_OutputStore> {
458 using EvaluationHandleForward<T_Func, T_Type, T_InputStore, T_OutputStore>::EvaluationHandleForward;
459 };
460
462 template<typename T_Func, typename T_Type, typename T_InputStore, typename T_OutputStore>
463 struct EvaluationHandle<T_Func, T_Type, T_InputStore, T_OutputStore,
464 TapeTraits::EnableIfJacobianTape<typename T_Type::Tape>>
465 : public EvaluationHandleReverseJacobianTapes<T_Func, T_Type, T_InputStore, T_OutputStore> {
466 using EvaluationHandleReverseJacobianTapes<T_Func, T_Type, T_InputStore,
467 T_OutputStore>::EvaluationHandleReverseJacobianTapes;
468 };
469
471 template<typename T_Func, typename T_Type, typename T_InputStore, typename T_OutputStore>
472 struct EvaluationHandle<T_Func, T_Type, T_InputStore, T_OutputStore,
473 TapeTraits::EnableIfPrimalValueTape<typename T_Type::Tape>>
474 : public EvaluationHandleReversePrimalValueTapes<T_Func, T_Type, T_InputStore, T_OutputStore> {
475 using EvaluationHandleReversePrimalValueTapes<T_Func, T_Type, T_InputStore,
476 T_OutputStore>::EvaluationHandleReversePrimalValueTapes;
477 };
478
564 public:
565
569 template<typename VecIn, typename VecOut>
570 using FunctorInterface = void (*)(VecIn const& x, VecOut& y);
571
575
579
582 template<typename Func>
584
587 template<typename Func>
589
594 template<typename Func, size_t m, size_t n>
597 std::array<JacobianComputationType, m>>;
598
603 template<typename Func, size_t m, size_t n>
606 std::array<HessianComputationType, m>>;
607
617 template<typename Func>
618 static CODI_INLINE DefaultHandle<Func> createHandleDefault(Func& func, size_t m, size_t n) {
619 return DefaultHandle<Func>(func, m, n);
620 }
621
632 template<size_t m, size_t n, typename Func>
636
647 template<typename Func>
648 static CODI_INLINE DefaultHandle2nd<Func> createHandleDefault2nd(Func& func, size_t m, size_t n) {
649 return DefaultHandle2nd<Func>(func, m, n);
650 }
651
662 template<size_t m, size_t n, typename Func>
666
684 template<typename Type, typename Func>
685 static CODI_INLINE EvaluationHandle<Func, Type> createHandle(Func& func, size_t m, size_t n) {
686 return EvaluationHandle<Func, Type>(func, m, n);
687 }
688
706 template<typename Type, size_t m, size_t n, typename Func>
708 Func& func) {
709 return EvaluationHandle<Func, Type, std::array<Type, n>, std::array<Type, m>>(func, m, n);
710 }
711
734 template<typename Type, typename InputStore, typename OutputStore, typename Func>
739
748 template<typename T = double>
749 static CODI_INLINE Jacobian<T> createJacobian(size_t m, size_t n) {
750 return Jacobian<T>(m, n);
751 }
752
760 template<size_t m, size_t n, typename T = double>
764
773 template<typename T = double>
774 static CODI_INLINE Hessian<T> createHessian(size_t m, size_t n) {
775 return Hessian<T>(m, n);
776 }
777
785 template<size_t m, size_t n, typename T = double>
789
802 template<typename Func, typename VecX, typename VecY>
803 static CODI_INLINE void evalPrimal(Func& func, VecX const& x, VecY& y) {
804 auto h = createHandleDefault(func, y.size(), x.size());
805 evalHandlePrimal(h, x, y);
806 }
807
820 template<typename Func, typename VecX, typename Jac>
821 static CODI_INLINE void evalJacobian(Func& func, VecX const& x, size_t const ySize, Jac& jac) {
822 auto h = createHandleDefault(func, ySize, x.size());
823 evalHandleJacobian(h, x, jac);
824 }
825
838 template<typename Func, typename VecX, typename Hes>
839 static CODI_INLINE void evalHessian(Func& func, VecX const& x, size_t const ySize, Hes& hes) {
840 auto h = createHandleDefault2nd(func, ySize, x.size());
841 evalHandleHessian(h, x, hes);
842 }
843
858 template<typename Func, typename VecX, typename VecY, typename Jac>
859 static CODI_INLINE void evalPrimalAndJacobian(Func& func, VecX const& x, VecY& y, Jac& jac) {
860 auto h = createHandleDefault(func, y.size(), x.size());
861 evalHandlePrimalAndJacobian(h, x, y, jac);
862 }
863
878 template<typename Func, typename VecX, typename VecY, typename Hes>
879 static CODI_INLINE void evalPrimalAndHessian(Func& func, VecX const& x, VecY& y, Hes& hes) {
880 auto h = createHandleDefault2nd(func, y.size(), x.size());
881 evalHandlePrimalAndHessian(h, x, y, hes);
882 }
883
900 template<typename Func, typename VecX, typename VecY, typename Jac, typename Hes>
901 static CODI_INLINE void evalPrimalAndJacobianAndHessian(Func& func, VecX const& x, VecY& y, Jac& jac, Hes& hes) {
902 auto h = createHandleDefault2nd(func, y.size(), x.size());
903 evalHandlePrimalAndJacobianAndHessian(h, x, y, jac, hes);
904 }
905
920 template<typename Func, typename VecX, typename Jac, typename Hes>
921 static CODI_INLINE void evalJacobianAndHessian(Func& func, VecX const& x, size_t ySize, Jac& jac, Hes& hes) {
922 auto h = createHandleDefault2nd(func, ySize, x.size());
923 evalHandleJacobianAndHessian(h, x, jac, hes);
924 }
925
938 template<typename Handle, typename VecX, typename VecY>
939 static CODI_INLINE void evalHandlePrimal(Handle& handle, VecX const& x, VecY& y) {
940 handle.computePrimal(x, y);
941 }
942
954 template<typename Handle, typename VecX, typename Jac>
955 static CODI_INLINE void evalHandleJacobian(Handle& handle, VecX const& x, Jac& jac) {
956 DummyVector dv;
957 handle.computeJacobian(x, jac, dv);
958 }
959
971 template<typename Handle, typename VecX, typename Hes>
972 static CODI_INLINE void evalHandleHessian(Handle& handle, VecX const& x, Hes& hes) {
973 DummyVector dv;
974 DummyJacobian dj;
975 handle.computeHessian(x, hes, dv, dj);
976 }
977
992 template<typename Handle, typename VecX, typename VecY, typename Jac>
993 static CODI_INLINE void evalHandlePrimalAndJacobian(Handle& handle, VecX const& x, VecY& y, Jac& jac) {
994 handle.computeJacobian(x, jac, y);
995 }
996
1011 template<typename Handle, typename VecX, typename VecY, typename Hes>
1012 static CODI_INLINE void evalHandlePrimalAndHessian(Handle& handle, VecX const& x, VecY& y, Hes& hes) {
1013 DummyJacobian dj;
1014 handle.computeHessian(x, hes, y, dj);
1015 }
1016
1033 template<typename Handle, typename VecX, typename VecY, typename Jac, typename Hes>
1034 static CODI_INLINE void evalHandlePrimalAndJacobianAndHessian(Handle& handle, VecX const& x, VecY& y, Jac& jac,
1035 Hes& hes) {
1036 handle.computeHessian(x, hes, y, jac);
1037 }
1038
1054 template<typename Handle, typename VecX, typename Jac, typename Hes>
1055 static CODI_INLINE void evalHandleJacobianAndHessian(Handle& handle, VecX const& x, Jac& jac, Hes& hes) {
1056 DummyVector dv;
1057 handle.computeHessian(x, hes, dv, jac);
1058 }
1059 };
1060
1061}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
PassiveReal< Type > const & getPassiveValue(Type const &v)
Get the basic primal value of the type.
Definition realTraits.hpp:127
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
V constructVector(size_t const size)
Helper for the construction of vector types provided by the user.
Definition constructVector.hpp:83
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
static void computeHessian(Func func, VecIn &input, VecOut &output, Hes &hes, Jac &jac=StaticDummy< DummyJacobian >::dummy)
Compute the Hessian with multiple tape recordings and sweeps.
Definition algorithms.hpp:402
Fixed size vector mode implementation.
Definition direction.hpp:57
Dummy Jacobian. Has size zero and no logic in any call.
Definition jacobian.hpp:219
Dummy vector that provides a dummy element access and size function.
Definition dummy.hpp:54
Basic interface and data storage for all EvaluationHandle implementations.
Definition evaluationHelper.hpp:66
void eval()
Helper for the evaluation of the function object with the internal input and output vector.
Definition evaluationHelper.hpp:123
T_OutputStore OutputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:73
void setPrimalInputs(VecX const &locX)
Set the primal values from the user provided vector into the CoDiPack ones.
T_InputStore InputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:72
size_t m
Size of the output vector.
Definition evaluationHelper.hpp:77
void computePrimal(VecX const &locX, VecY &locY)
Perform a primal evaluation with the inputs provided in locX and store the result in locY.
void computeHessian(VecX const &locX, Hes &hes, VecY &locY, Jac &jac)
Perform a Hessian evaluation with the inputs provided in locX and store the result in hes,...
size_t n
Size of the input vector.
Definition evaluationHelper.hpp:78
OutputStore y
Storage for the output arguments.
Definition evaluationHelper.hpp:83
T_Func Func
See EvaluationHandleBase.
Definition evaluationHelper.hpp:70
DummyJacobian dummyJacobian
Used if no output is required.
Definition evaluationHelper.hpp:86
void getPrimalOutputs(VecY &locY)
Store the primal values from the CoDiPack vector into the user vector.
Func & func
The function object for the evaluations.
Definition evaluationHelper.hpp:80
DummyVector dummyVector
Used if no output is required.
Definition evaluationHelper.hpp:85
EvaluationHandleBase(Func &func, size_t m, size_t n)
Constructor.
Definition evaluationHelper.hpp:91
T_Type Type
See EvaluationHandleBase.
Definition evaluationHelper.hpp:71
InputStore x
Storage for the input arguments.
Definition evaluationHelper.hpp:82
void computeJacobian(VecX const &locX, Jac &jac, VecY &locY)
Perform a Jacobian evaluation with the inputs provided in locX and store the result in jac and locY.
Definition evaluationHelper.hpp:133
void computeHessian(VecX const &locX, Hes &hes, VecY &locY, Jac &jac)
Perform a Hessian evaluation with the inputs provided in locX and store the result in hes,...
Definition evaluationHelper.hpp:215
T_Func Func
See EvaluationHandleBase.
Definition evaluationHelper.hpp:137
T_OutputStore OutputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:140
T_InputStore InputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:139
void getPrimalOutputs(VecY &locY)
Store the primal values from the CoDiPack vector into the user vector.
Definition evaluationHelper.hpp:158
void computeJacobian(VecX const &locX, Jac &jac, VecY &locY)
Perform a Jacobian evaluation with the inputs provided in locX and store the result in jac and locY.
Definition evaluationHelper.hpp:179
T_Type Type
See EvaluationHandleBase.
Definition evaluationHelper.hpp:138
void setPrimalInputs(VecX const &locX)
Set the primal values from the user provided vector into the CoDiPack ones.
Definition evaluationHelper.hpp:149
void computePrimal(VecX const &locX, VecY &locY)
Perform a primal evaluation with the inputs provided in locX and store the result in locY.
Definition evaluationHelper.hpp:167
Implementation for reverse mode CoDiPack types of EvaluationHandleBase.
Definition evaluationHelper.hpp:283
EvaluationHandleReverseBase(Func &func, size_t m, size_t n)
Constructor.
Definition evaluationHelper.hpp:302
T_Func Func
See EvaluationHandleBase.
Definition evaluationHelper.hpp:287
T_Type Type
See EvaluationHandleBase.
Definition evaluationHelper.hpp:289
void setPrimalInputs(VecX const &locX, bool reg)
Set the primal values from the user provided vector into the CoDiPack ones.
Definition evaluationHelper.hpp:306
TapeHelper< Type > th
Manages the evaluations.
Definition evaluationHelper.hpp:297
T_OutputStore OutputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:291
void computePrimal(VecX const &locX, VecY &locY)
Perform a primal evaluation with the inputs provided in locX and store the result in locY.
Definition evaluationHelper.hpp:332
void computeHessian(VecX const &locX, Hes &hes, VecY &locY, Jac &jac)
Perform a Hessian evaluation with the inputs provided in locX and store the result in hes,...
void computeJacobian(VecX const &locX, Jac &jac, VecY &locY)
Perform a Jacobian evaluation with the inputs provided in locX and store the result in jac and locY.
Definition evaluationHelper.hpp:346
void recordTape(VecX const &locX, VecY &locY)
Helper function that records a new tape.
Definition evaluationHelper.hpp:360
T_InputStore InputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:290
void getPrimalOutputs(VecY &locY, bool reg)
Store the primal values from the CoDiPack vector into the user vector.
Definition evaluationHelper.hpp:319
Implementation for Jacobian reverse mode CoDiPack types of EvaluationHandleBase.
Definition evaluationHelper.hpp:421
T_InputStore InputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:426
T_Func Func
See EvaluationHandleBase.
Definition evaluationHelper.hpp:424
T_OutputStore OutputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:427
T_Type Type
See EvaluationHandleBase.
Definition evaluationHelper.hpp:425
void computeHessian(VecX const &locX, Hes &hes, VecY &locY, Jac &jac)
Perform a Hessian evaluation with the inputs provided in locX and store the result in hes,...
Definition evaluationHelper.hpp:439
Implementation of EvaluationHandleBase for primal value reverse mode CoDiPack types.
Definition evaluationHelper.hpp:384
void computeHessian(VecX const &locX, Hes &hes, VecY &locY, Jac &jac)
Perform a Hessian evaluation with the inputs provided in locX and store the result in hes,...
Definition evaluationHelper.hpp:403
T_OutputStore OutputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:391
T_Type Type
See EvaluationHandleBase.
Definition evaluationHelper.hpp:389
T_InputStore InputStore
See EvaluationHandleBase.
Definition evaluationHelper.hpp:390
T_Func Func
See EvaluationHandleBase.
Definition evaluationHelper.hpp:388
See EvaluationHandleBase.
Definition evaluationHelper.hpp:451
Evaluate the primal, Jacobian and Hessian of function objects.
Definition evaluationHelper.hpp:563
static void evalJacobian(Func &func, VecX const &x, size_t const ySize, Jac &jac)
Compute the Jacobian of the function object.
Definition evaluationHelper.hpp:821
static void evalPrimalAndJacobianAndHessian(Func &func, VecX const &x, VecY &y, Jac &jac, Hes &hes)
Compute the primal result, Jacobian, and Hessian of the function object.
Definition evaluationHelper.hpp:901
static Jacobian< T > createJacobian(size_t m, size_t n)
Create a Jacobian with the given size.
Definition evaluationHelper.hpp:749
void(*)(VecIn const &x, VecOut &y) FunctorInterface
Definition evaluationHelper.hpp:570
static void evalHandlePrimalAndJacobian(Handle &handle, VecX const &x, VecY &y, Jac &jac)
Compute the primal result and Jacobian of the function object stored in the handle.
Definition evaluationHelper.hpp:993
static DefaultHandleFixed2nd< Func, m, n > createHandleDefaultFixed2nd(Func &func)
Helper function for the creation of a default second order evaluation handle with a compile time vect...
Definition evaluationHelper.hpp:663
static void evalPrimalAndHessian(Func &func, VecX const &x, VecY &y, Hes &hes)
Compute the primal result and Hessian of the function object.
Definition evaluationHelper.hpp:879
static DefaultHandle2nd< Func > createHandleDefault2nd(Func &func, size_t m, size_t n)
Helper function for the creation of a default second order evaluation handle with a variable vector s...
Definition evaluationHelper.hpp:648
static void evalHandleJacobianAndHessian(Handle &handle, VecX const &x, Jac &jac, Hes &hes)
Compute the Hessian of the evaluation procedure in the function object.
Definition evaluationHelper.hpp:1055
static DefaultHandle< Func > createHandleDefault(Func &func, size_t m, size_t n)
Helper function for the creation of a default first order evaluation handle with a variable vector si...
Definition evaluationHelper.hpp:618
static Hessian< T > createHessian(size_t m, size_t n)
Create a Hessian with the given size.
Definition evaluationHelper.hpp:774
static void evalPrimal(Func &func, VecX const &x, VecY &y)
Perform a primal evaluation of the function object with the default first order type.
Definition evaluationHelper.hpp:803
static void evalHandleHessian(Handle &handle, VecX const &x, Hes &hes)
Compute the Hessian of the function object stored in the handle.
Definition evaluationHelper.hpp:972
static void evalHandlePrimalAndJacobianAndHessian(Handle &handle, VecX const &x, VecY &y, Jac &jac, Hes &hes)
Compute the primal result, Jacobian, and Hessian of the function object.
Definition evaluationHelper.hpp:1034
static EvaluationHandle< Func, Type > createHandle(Func &func, size_t m, size_t n)
Helper function for the creation of an evaluation handle with the specified CoDiPack type and a varia...
Definition evaluationHelper.hpp:685
static void evalHessian(Func &func, VecX const &x, size_t const ySize, Hes &hes)
Compute the Hessian of the function object.
Definition evaluationHelper.hpp:839
static Hessian< T, std::array< T, m *n *n > > createHessianFixed()
Create a Hessian with a compile time size.
Definition evaluationHelper.hpp:786
static void evalHandlePrimal(Handle &handle, VecX const &x, VecY &y)
Perform a primal evaluation of the function object stored in the handle.
Definition evaluationHelper.hpp:939
static void evalPrimalAndJacobian(Func &func, VecX const &x, VecY &y, Jac &jac)
Compute the primal result and Jacobian of the function object.
Definition evaluationHelper.hpp:859
static EvaluationHandle< Func, Type, InputStore, OutputStore > createHandleFull(Func &func, size_t m, size_t n)
Helper function for the creation of an evaluation handle with the specified CoDiPack type and storage...
Definition evaluationHelper.hpp:735
static void evalHandlePrimalAndHessian(Handle &handle, VecX const &x, VecY &y, Hes &hes)
Compute the primal result and Hessian of the function object.
Definition evaluationHelper.hpp:1012
static EvaluationHandle< Func, Type, std::array< Type, n >, std::array< Type, m > > createHandleFixed(Func &func)
Helper function for the creation of an evaluation handle with the specified CoDiPack type and a compi...
Definition evaluationHelper.hpp:707
static DefaultHandleFixed< Func, m, n > createHandleDefaultFixed(Func &func)
Helper function for the creation of a default first order evaluation handle with a compile time vecto...
Definition evaluationHelper.hpp:633
static void evalJacobianAndHessian(Func &func, VecX const &x, size_t ySize, Jac &jac, Hes &hes)
Compute the Jacobian and Hessian of the function object.
Definition evaluationHelper.hpp:921
static void evalHandleJacobian(Handle &handle, VecX const &x, Jac &jac)
Compute the Jacobian of the function object stored in the handle.
Definition evaluationHelper.hpp:955
static Jacobian< T, std::array< T, m *n > > createJacobianFixed()
Create a Jacobian with a compile time size.
Definition evaluationHelper.hpp:761
Common traits for all types used as gradients.
Definition gradientTraits.hpp:64
Default implementation of the Hessian interface.
Definition hessian.hpp:59
Wrapper for JacboianInterfaces that requires a passive value conversion.
Definition jacobian.hpp:186
Default implementation of the Jacobian interface.
Definition jacobian.hpp:60
See TapeHelperBase.
Definition tapeHelper.hpp:642