CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
binaryOperators.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 <cmath>
38#include <utility>
39
40#include "../../config.h"
41#include "../../misc/exceptions.hpp"
42#include "../../misc/macros.hpp"
43#include "../../traits/realTraits.hpp"
44#include "../binaryExpression.hpp"
45#include "../constantExpression.hpp"
46#include "../lhsExpressionInterface.hpp"
47
49namespace codi {
50
51 /*******************************************************************************/
54
56 template<typename T_Real>
57 struct OperationAdd : public BinaryOperation<T_Real> {
58 public:
59
60 using Real = CODI_DD(T_Real, double);
61
63 template<typename ArgA, typename ArgB>
64 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
65 return argA + argB;
66 }
67
69 template<typename ArgA, typename ArgB>
70 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
71 Real const& result) {
72 CODI_UNUSED(argA, argB, result);
73 return 1.0;
74 }
75
77 template<typename ArgA, typename ArgB>
78 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
79 Real const& result) {
80 CODI_UNUSED(argA, argB, result);
81 return 1.0;
82 }
83 };
84#define OPERATION_LOGIC OperationAdd
85#define FUNCTION operator+
86#include "binaryOverloads.tpp"
87
89 template<typename T_Real>
90 struct OperationSubstract : public BinaryOperation<T_Real> {
91 public:
92
93 using Real = CODI_DD(T_Real, double);
94
96 template<typename ArgA, typename ArgB>
97 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
98 return argA - argB;
99 }
100
102 template<typename ArgA, typename ArgB>
103 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
104 Real const& result) {
105 CODI_UNUSED(argA, argB, result);
106 return 1.0;
107 }
108
110 template<typename ArgA, typename ArgB>
111 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
112 Real const& result) {
113 CODI_UNUSED(argA, argB, result);
114 return -1.0;
115 }
116 };
117#define OPERATION_LOGIC OperationSubstract
118#define FUNCTION operator-
119#include "binaryOverloads.tpp"
120
122 template<typename T_Real>
123 struct OperationMultiply : public BinaryOperation<T_Real> {
124 public:
125
126 using Real = CODI_DD(T_Real, double);
127
129 template<typename ArgA, typename ArgB>
130 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
131 return argA * argB;
132 }
133
135 template<typename ArgA, typename ArgB>
136 static CODI_INLINE ArgB const& gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
137 CODI_UNUSED(argA, argB, result);
138 return argB;
139 }
140
142 template<typename ArgA, typename ArgB>
143 static CODI_INLINE ArgA const& gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
144 CODI_UNUSED(argA, argB, result);
145 return argA;
146 }
147 };
148#define OPERATION_LOGIC OperationMultiply
149#define FUNCTION operator*
150#include "binaryOverloads.tpp"
151
153 template<typename T_Real>
154 struct OperationDivide : public BinaryOperation<T_Real> {
155 public:
156
157 using Real = CODI_DD(T_Real, double);
158
160 template<typename ArgA, typename ArgB>
161 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
162 return argA / argB;
163 }
164
166 template<typename ArgA, typename ArgB>
167 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
168 CODI_UNUSED(argA, result);
169
170 checkArguments(argB);
171 return 1.0 / argB;
172 }
173
175 template<typename ArgA, typename ArgB>
176 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
177 CODI_UNUSED(argA, result);
178
179 checkArguments(argB);
180 return -result / argB;
181 }
182
183 private:
184 template<typename ArgB>
185 static CODI_INLINE void checkArguments(ArgB const& argB) {
188 CODI_EXCEPTION("Division called with divisor of zero.");
189 }
190 }
191 }
192 };
193#define OPERATION_LOGIC OperationDivide
194#define FUNCTION operator/
195#include "binaryOverloads.tpp"
196
198 /*******************************************************************************/
201
202 using std::atan2;
203 using std::copysign;
204 using std::fmax;
205 using std::fmin;
206 using std::fmod;
207 using std::frexp;
208 using std::hypot;
209 using std::ldexp;
210 using std::max;
211 using std::min;
212 using std::pow;
213 using std::remainder;
214 using std::trunc;
215
217 template<typename T_Real>
218 struct OperationAtan2 : public BinaryOperation<T_Real> {
219 public:
220
221 using Real = CODI_DD(T_Real, double);
222
224 template<typename ArgA, typename ArgB>
225 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
226 return atan2(argA, argB);
227 }
228
230 template<typename ArgA, typename ArgB>
231 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
232 CODI_UNUSED(result);
233
234 checkArguments(argA, argB);
235 Real divisor = argA * argA + argB * argB;
236 divisor = 1.0 / divisor;
237 return argB * divisor;
238 }
239
241 template<typename ArgA, typename ArgB>
242 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
243 CODI_UNUSED(result);
244
245 checkArguments(argA, argB);
246 Real divisor = argA * argA + argB * argB;
247 divisor = 1.0 / divisor;
248 return -argA * divisor;
249 }
250
251 private:
252 template<typename ArgA, typename ArgB>
253 static CODI_INLINE void checkArguments(ArgA& argA, ArgB& argB) {
255 if (0.0 == RealTraits::getPassiveValue(argA) && 0.0 == RealTraits::getPassiveValue(argB)) {
256 CODI_EXCEPTION("atan2 called at point (0,0).");
257 }
258 }
259 }
260 };
261#define OPERATION_LOGIC OperationAtan2
262#define FUNCTION atan2
263#include "binaryOverloads.tpp"
264
265#define OPERATION_LOGIC OperationAtan2
266#define FUNCTION atan2f
267#include "binaryOverloads.tpp"
268
269#define OPERATION_LOGIC OperationAtan2
270#define FUNCTION atan2l
271#include "binaryOverloads.tpp"
272
274 template<typename T_Real>
275 struct OperationCopysign : public BinaryOperation<T_Real> {
276 public:
277
278 using Real = CODI_DD(T_Real, double);
279
281 template<typename ArgA, typename ArgB>
282 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
283 return copysign(argA, argB);
284 }
285
287 template<typename ArgA, typename ArgB>
288 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
289 Real const& result) {
290 CODI_UNUSED(result);
291 if (RealTraits::getPassiveValue(argA) < 0.0) {
292 if (RealTraits::getPassiveValue(argB) < 0.0) {
294 } else {
296 }
297 } else if (RealTraits::getPassiveValue(argA) > 0.0) {
298 if (RealTraits::getPassiveValue(argB) < 0.0) {
300 } else {
302 }
303 } else {
305 }
306 }
307
309 template<typename ArgA, typename ArgB>
310 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
311 Real const& result) {
312 CODI_UNUSED(argA, argB, result);
313
315 }
316 };
317
318#define OPERATION_LOGIC OperationCopysign
319#define FUNCTION copysign
320#include "binaryOverloads.tpp"
321
322#define OPERATION_LOGIC OperationCopysign
323#define FUNCTION copysignf
324#include "binaryOverloads.tpp"
325
326#define OPERATION_LOGIC OperationCopysign
327#define FUNCTION copysignl
328#include "binaryOverloads.tpp"
329
331 template<typename T_Real>
332 struct OperationFmod : public BinaryOperation<T_Real> {
333 public:
334
335 using Real = CODI_DD(T_Real, double);
336
338 template<typename ArgA, typename ArgB>
339 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
340 return fmod(argA, argB);
341 }
342
344 template<typename ArgA, typename ArgB>
345 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
346 Real const& result) {
347 CODI_UNUSED(argA, argB, result);
348
350 }
351
353 template<typename ArgA, typename ArgB>
354 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
355 Real const& result) {
356 CODI_UNUSED(result);
357
358 if (RealTraits::getPassiveValue(argB) == 0.0) {
360 } else {
361 return -trunc(RealTraits::getPassiveValue(argA / argB));
362 }
363 }
364 };
365
366#define OPERATION_LOGIC OperationFmod
367#define FUNCTION fmod
368#include "binaryOverloads.tpp"
369
370#define OPERATION_LOGIC OperationFmod
371#define FUNCTION fmodf
372#include "binaryOverloads.tpp"
373
374#define OPERATION_LOGIC OperationFmod
375#define FUNCTION fmodl
376#include "binaryOverloads.tpp"
377
379 template<typename T_Real>
380 struct OperationFrexp : public BinaryOperation<T_Real> {
381 public:
382
383 using Real = CODI_DD(T_Real, double);
384
386 template<typename ArgA, typename ArgB>
387 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
388 return frexp(argA, argB);
389 }
390
392 template<typename ArgA, typename ArgB>
393 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
394 CODI_UNUSED(argA, result);
395 /* The result is always computed beforehand, therefore we can safely use the value of b. */
396 return ldexp(1.0, -(*argB));
397 }
398
400 template<typename ArgA, typename ArgB>
401 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
402 CODI_UNUSED(argA, argB, result);
403
404 return 0.0;
405 }
406 };
407
408#ifndef DOXYGEN_DISABLE
409 template<typename T_StoreData>
410 struct IntPointerConversion : public ConstantDataConversion<T_StoreData> {
411 public:
412
413 using StoreData = CODI_DD(T_StoreData, double);
414 using ArgumentData = int*;
415
416 static int* fromDataStore(StoreData const& v) {
417 static int i = (int)v;
418 return &i;
419 }
420
421 static StoreData toDataStore(int const* v) {
422 return (StoreData)*v;
423 }
424 };
425#endif
426#define OPERATION_LOGIC OperationFrexp
427#define FUNCTION frexp
428#define SECOND_ARG_TYPE int*
429#define SECOND_ARG_CONVERSION IntPointerConversion
430#include "binaryFirstArgumentOverloads.tpp"
431
432#define OPERATION_LOGIC OperationFrexp
433#define FUNCTION frexpf
434#define SECOND_ARG_TYPE int*
435#define SECOND_ARG_CONVERSION IntPointerConversion
436#include "binaryFirstArgumentOverloads.tpp"
437
438#define OPERATION_LOGIC OperationFrexp
439#define FUNCTION frexpl
440#define SECOND_ARG_TYPE int*
441#define SECOND_ARG_CONVERSION IntPointerConversion
442#include "binaryFirstArgumentOverloads.tpp"
443
445 template<typename T_Real>
446 struct OperationHypot : public BinaryOperation<T_Real> {
447 public:
448
449 using Real = CODI_DD(T_Real, double);
450
452 template<typename ArgA, typename ArgB>
453 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
454 return hypot(argA, argB);
455 }
456
458 template<typename ArgA, typename ArgB>
459 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
460 CODI_UNUSED(argB);
461
462 checkResult(result);
463 if (result != 0.0) {
464 return argA / result;
465 } else {
466 return Real();
467 }
468 }
469
471 template<typename ArgA, typename ArgB>
472 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
473 CODI_UNUSED(argA);
474
475 checkResult(result);
476 if (result != 0.0) {
477 return argB / result;
478 } else {
479 return Real();
480 }
481 }
482
483 private:
484 static CODI_INLINE void checkResult(Real const& result) {
486 if (RealTraits::getPassiveValue(result) == 0.0) {
487 CODI_EXCEPTION("Zero divisor for hypot derivative.");
488 }
489 }
490 }
491 };
492
493#define OPERATION_LOGIC OperationHypot
494#define FUNCTION hypot
495#include "binaryOverloads.tpp"
496
497#define OPERATION_LOGIC OperationHypot
498#define FUNCTION hypotf
499#include "binaryOverloads.tpp"
500
501#define OPERATION_LOGIC OperationHypot
502#define FUNCTION hypotl
503#include "binaryOverloads.tpp"
504
506 template<typename T_Real>
507 struct OperationLdexp : public BinaryOperation<T_Real> {
508 public:
509
510 using Real = CODI_DD(T_Real, double);
511
513 template<typename ArgA, typename ArgB>
514 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
515 return ldexp(argA, argB);
516 }
517
519 template<typename ArgA, typename ArgB>
520 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
521 CODI_UNUSED(argA, result);
522
523 return ldexp(1.0, argB);
524 }
525
527 template<typename ArgA, typename ArgB>
528 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
529 CODI_UNUSED(argA, argB, result);
530
531 return 0.0;
532 }
533 };
534#define OPERATION_LOGIC OperationLdexp
535#define FUNCTION ldexp
536#define SECOND_ARG_TYPE int
537#define SECOND_ARG_CONVERSION ConstantDataConversion
538#include "binaryFirstArgumentOverloads.tpp"
539
540#define OPERATION_LOGIC OperationLdexp
541#define FUNCTION ldexpl
542#define SECOND_ARG_TYPE int
543#define SECOND_ARG_CONVERSION ConstantDataConversion
544#include "binaryFirstArgumentOverloads.tpp"
545
546#define OPERATION_LOGIC OperationLdexp
547#define FUNCTION ldexpf
548#define SECOND_ARG_TYPE int
549#define SECOND_ARG_CONVERSION ConstantDataConversion
550#include "binaryFirstArgumentOverloads.tpp"
551
553 template<typename T_Real>
554 struct OperationMax : public BinaryOperation<T_Real> {
555 public:
556
557 using Real = CODI_DD(T_Real, double);
558
560 template<typename ArgA, typename ArgB>
561 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
562 return max(argA, argB);
563 }
564
566 template<typename ArgA, typename ArgB>
567 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
568 Real const& result) {
569 CODI_UNUSED(result);
570
572 return 1.0;
573 } else {
574 return 0.0;
575 }
576 }
577
579 template<typename ArgA, typename ArgB>
580 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
581 Real const& result) {
582 CODI_UNUSED(result);
583
585 return 0.0;
586 } else {
587 return 1.0;
588 }
589 }
590 };
591
592#define OPERATION_LOGIC OperationMax
593#define FUNCTION max
594#include "binaryOverloads.tpp"
595
596#define OPERATION_LOGIC OperationMax
597#define FUNCTION fmax
598#include "binaryOverloads.tpp"
599
600#define OPERATION_LOGIC OperationMax
601#define FUNCTION fmaxf
602#include "binaryOverloads.tpp"
603
604#define OPERATION_LOGIC OperationMax
605#define FUNCTION fmaxl
606#include "binaryOverloads.tpp"
607
609 template<typename T_Real>
610 struct OperationMin : public BinaryOperation<T_Real> {
611 public:
612
613 using Real = CODI_DD(T_Real, double);
614
616 template<typename ArgA, typename ArgB>
617 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
618 return min(argA, argB);
619 }
620
622 template<typename ArgA, typename ArgB>
623 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
624 Real const& result) {
625 CODI_UNUSED(result);
626
628 return 1.0;
629 } else {
630 return 0.0;
631 }
632 }
633
635 template<typename ArgA, typename ArgB>
636 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
637 Real const& result) {
638 CODI_UNUSED(result);
639
641 return 0.0;
642 } else {
643 return 1.0;
644 }
645 }
646 };
647#define OPERATION_LOGIC OperationMin
648#define FUNCTION min
649#include "binaryOverloads.tpp"
650
651#define OPERATION_LOGIC OperationMin
652#define FUNCTION fmin
653#include "binaryOverloads.tpp"
654
655#define OPERATION_LOGIC OperationMin
656#define FUNCTION fminf
657#include "binaryOverloads.tpp"
658
659#define OPERATION_LOGIC OperationMin
660#define FUNCTION fminl
661#include "binaryOverloads.tpp"
662
664 template<typename T_Real>
665 struct OperationPow : public BinaryOperation<T_Real> {
666 public:
667
668 using Real = CODI_DD(T_Real, double);
669
671 template<typename ArgA, typename ArgB>
672 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
673 return pow(argA, argB);
674 }
675
677 template<typename ArgA, typename ArgB>
678 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
679 CODI_UNUSED(result);
680
681 checkArguments(argA, argB);
682 if (RealTraits::getPassiveValue(argA) <= 0.0 && 1 <= RealTraits::MaxDerivativeOrder<ArgB>()) {
683 // Special case for higher order derivatives. Derivative will be wrong since the argB part is not evaluated.
684 return RealTraits::getPassiveValue(argB) * pow(argA, argB - 1.0);
685 } else {
686 return argB * pow(argA, argB - 1.0);
687 }
688 }
689
691 template<typename ArgA, typename ArgB>
692 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
693 CODI_UNUSED(argB);
694
695 checkArguments(argA, argB);
696 if (RealTraits::getPassiveValue(argA) > 0.0) {
697 return log(argA) * result;
698 } else {
699 return Real();
700 }
701 }
702
703 private:
704 template<typename ArgA, typename ArgB>
705 static CODI_INLINE void checkArguments(ArgA const& argA, ArgB const& argB) {
707 RealTraits::PassiveReal<ArgB> integralPart = 0.0;
708 std::modf(RealTraits::getPassiveValue(argB), &integralPart);
709
710 if (RealTraits::getPassiveValue(argA) < 0.0 && RealTraits::getPassiveValue(argB) != integralPart) {
711 CODI_EXCEPTION("Negative base for non-integral exponent in pow function. (Value: %0.15e)",
713 }
714 }
715 }
716 };
717#define OPERATION_LOGIC OperationPow
718#define FUNCTION pow
719#include "binaryOverloads.tpp"
720
721#define OPERATION_LOGIC OperationPow
722#define FUNCTION powf
723#include "binaryOverloads.tpp"
724
725#define OPERATION_LOGIC OperationPow
726#define FUNCTION powl
727#include "binaryOverloads.tpp"
728
732 template<typename T_Real>
733 struct OperationRemainder : public BinaryOperation<T_Real> {
734 public:
735
736 using Real = CODI_DD(T_Real, double);
737
739 template<typename ArgA, typename ArgB>
740 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
741 return remainder(argA, argB);
742 }
743
745 template<typename ArgA, typename ArgB>
746 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
747 CODI_UNUSED(argA, argB, result);
748
749 return 1.0;
750 }
751
753 template<typename ArgA, typename ArgB>
754 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
755 CODI_UNUSED(result);
756
757 checkArguments(argB);
758
759 using std::round;
760 return -round(argA / argB);
761 }
762
763 private:
764 template<typename ArgB>
765 static CODI_INLINE void checkArguments(ArgB const& argB) {
767 if (0.0 == RealTraits::getPassiveValue(argB)) {
768 CODI_EXCEPTION("Remainder called with divisor of zero.");
769 }
770 }
771 }
772 };
773#define OPERATION_LOGIC OperationRemainder
774#define FUNCTION remainder
775#include "binaryOverloads.tpp"
776
777#define OPERATION_LOGIC OperationRemainder
778#define FUNCTION remainderf
779#include "binaryOverloads.tpp"
780
781#define OPERATION_LOGIC OperationRemainder
782#define FUNCTION remainderl
783#include "binaryOverloads.tpp"
784
789
790 using std::swap;
791
793 template<typename Real, typename Gradient, typename Tape, typename Impl>
799
801}
802
803namespace std {
804 using codi::atan2;
805 using codi::atan2f;
806 using codi::atan2l;
807 using codi::copysign;
808 using codi::copysignf;
809 using codi::copysignl;
810 using codi::fmax;
811 using codi::fmaxf;
812 using codi::fmaxl;
813 using codi::fmin;
814 using codi::fminf;
815 using codi::fminl;
816 using codi::fmod;
817 using codi::fmodf;
818 using codi::fmodl;
819 using codi::frexp;
820 using codi::frexpf;
821 using codi::frexpl;
822 using codi::hypot;
823 using codi::hypotf;
824 using codi::hypotl;
825 using codi::ldexp;
826 using codi::ldexpf;
827 using codi::ldexpl;
828 using codi::max;
829 using codi::min;
830 using codi::pow;
831 using codi::powf;
832 using codi::powl;
833 using codi::remainder;
834 using codi::remainderf;
835 using codi::remainderl;
836 using codi::swap;
837}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
bool constexpr CheckExpressionArguments
Check for invalid arguments to expressions like division by zero.
Definition config.h:146
PassiveReal< Type > const & getPassiveValue(Type const &v)
Get the basic primal value of the type.
Definition realTraits.hpp:127
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type, that was used in the application.
Definition realTraits.hpp:117
bool isTotalZero(Type const &v)
Function for checking if the value of the type is completely zero.
Definition realTraits.hpp:139
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
RealTraits::PassiveReal< Real > round(ExpressionInterface< Real, Arg > const &arg)
Function overload for round.
Definition unaryOperators.hpp:637
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
void swap(LhsExpressionInterface< Real, Gradient, Tape, Impl > &lhs, LhsExpressionInterface< Real, Gradient, Tape, Impl > &rhs)
Optimized swap for lhs expressions that does not call the copy constructor.
Definition binaryOperators.hpp:794
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Interface for implementing the logic for a BinaryExpression.
Definition binaryExpression.hpp:56
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Real const & value() const
Get a constant reference to the lvalue represented by the expression.
Identifier const & getIdentifier() const
BinaryOperation implementation for operator +.
Definition binaryOperators.hpp:57
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:70
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:60
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:64
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:78
BinaryOperation implementation for atan2.
Definition binaryOperators.hpp:218
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:225
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:242
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:221
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:231
BinaryOperation implementation for copysign.
Definition binaryOperators.hpp:275
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:278
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:288
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:310
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:282
BinaryOperation implementation for operator /.
Definition binaryOperators.hpp:154
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:167
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:161
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:176
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:157
BinaryOperation implementation for fmod.
Definition binaryOperators.hpp:332
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:335
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:354
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:345
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:339
BinaryOperation implementation for frexp.
Definition binaryOperators.hpp:380
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:393
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:383
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:401
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:387
BinaryOperation implementation for hypot.
Definition binaryOperators.hpp:446
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:453
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:472
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:449
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:459
BinaryOperation implementation for ldexp.
Definition binaryOperators.hpp:507
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:514
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:510
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:528
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:520
BinaryOperation implementation for max.
Definition binaryOperators.hpp:554
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:567
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:561
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:580
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:557
BinaryOperation implementation for min.
Definition binaryOperators.hpp:610
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:613
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:617
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:636
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:623
BinaryOperation implementation for operator *.
Definition binaryOperators.hpp:123
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:126
static ArgB const & gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:136
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:130
static ArgA const & gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:143
BinaryOperation implementation for pow.
Definition binaryOperators.hpp:665
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:672
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:678
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:668
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:692
Definition binaryOperators.hpp:733
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:736
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:740
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:746
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:754
BinaryOperation implementation for operator -.
Definition binaryOperators.hpp:90
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:103
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:93
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:97
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:111