CoDiPack  2.3.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
85 static CODI_INLINE std::string getMathRep() {
86 return "+";
87 }
88 };
89#define OPERATION_LOGIC OperationAdd
90#define FUNCTION operator+
91#include "binaryOverloads.tpp"
92
94 template<typename T_Real>
95 struct OperationSubstract : public BinaryOperation<T_Real> {
96 public:
97
98 using Real = CODI_DD(T_Real, double);
99
101 template<typename ArgA, typename ArgB>
102 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
103 return argA - argB;
104 }
105
107 template<typename ArgA, typename ArgB>
108 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
109 Real const& result) {
110 CODI_UNUSED(argA, argB, result);
111 return 1.0;
112 }
113
115 template<typename ArgA, typename ArgB>
116 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
117 Real const& result) {
118 CODI_UNUSED(argA, argB, result);
119 return -1.0;
120 }
121
123 static CODI_INLINE std::string getMathRep() {
124 return "-";
125 }
126 };
127#define OPERATION_LOGIC OperationSubstract
128#define FUNCTION operator-
129#include "binaryOverloads.tpp"
130
132 template<typename T_Real>
133 struct OperationMultiply : public BinaryOperation<T_Real> {
134 public:
135
136 using Real = CODI_DD(T_Real, double);
137
139 template<typename ArgA, typename ArgB>
140 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
141 return argA * argB;
142 }
143
145 template<typename ArgA, typename ArgB>
146 static CODI_INLINE ArgB const& gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
147 CODI_UNUSED(argA, argB, result);
148 return argB;
149 }
150
152 template<typename ArgA, typename ArgB>
153 static CODI_INLINE ArgA const& gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
154 CODI_UNUSED(argA, argB, result);
155 return argA;
156 }
157
159 static CODI_INLINE std::string getMathRep() {
160 return "*";
161 }
162 };
163#define OPERATION_LOGIC OperationMultiply
164#define FUNCTION operator*
165#include "binaryOverloads.tpp"
166
168 template<typename T_Real>
169 struct OperationDivide : public BinaryOperation<T_Real> {
170 public:
171
172 using Real = CODI_DD(T_Real, double);
173
175 template<typename ArgA, typename ArgB>
176 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
177 return argA / argB;
178 }
179
181 template<typename ArgA, typename ArgB>
182 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
183 CODI_UNUSED(argA, result);
184
185 checkArguments(argB);
186 return 1.0 / argB;
187 }
188
190 template<typename ArgA, typename ArgB>
191 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
192 CODI_UNUSED(argA, result);
193
194 checkArguments(argB);
195 return -result / argB;
196 }
197
199 static CODI_INLINE std::string getMathRep() {
200 return "/";
201 }
202
203 private:
204 template<typename ArgB>
205 static CODI_INLINE void checkArguments(ArgB const& argB) {
208 CODI_EXCEPTION("Division called with divisor of zero.");
209 }
210 }
211 }
212 };
213#define OPERATION_LOGIC OperationDivide
214#define FUNCTION operator/
215#include "binaryOverloads.tpp"
216
218 /*******************************************************************************/
221
222 using std::atan2;
223 using std::copysign;
224 using std::fmax;
225 using std::fmin;
226 using std::fmod;
227 using std::frexp;
228 using std::hypot;
229 using std::ldexp;
230 using std::max;
231 using std::min;
232 using std::pow;
233 using std::remainder;
234 using std::trunc;
235
237 template<typename T_Real>
238 struct OperationAtan2 : public BinaryOperation<T_Real> {
239 public:
240
241 using Real = CODI_DD(T_Real, double);
242
244 template<typename ArgA, typename ArgB>
245 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
246 return atan2(argA, argB);
247 }
248
250 template<typename ArgA, typename ArgB>
251 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
252 CODI_UNUSED(result);
253
254 checkArguments(argA, argB);
255 Real divisor = argA * argA + argB * argB;
256 divisor = 1.0 / divisor;
257 return argB * divisor;
258 }
259
261 template<typename ArgA, typename ArgB>
262 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
263 CODI_UNUSED(result);
264
265 checkArguments(argA, argB);
266 Real divisor = argA * argA + argB * argB;
267 divisor = 1.0 / divisor;
268 return -argA * divisor;
269 }
270
272 static CODI_INLINE std::string getMathRep() {
273 return "atan2()";
274 }
275
276 private:
277 template<typename ArgA, typename ArgB>
278 static CODI_INLINE void checkArguments(ArgA& argA, ArgB& argB) {
280 if (0.0 == RealTraits::getPassiveValue(argA) && 0.0 == RealTraits::getPassiveValue(argB)) {
281 CODI_EXCEPTION("atan2 called at point (0,0).");
282 }
283 }
284 }
285 };
286#define OPERATION_LOGIC OperationAtan2
287#define FUNCTION atan2
288#include "binaryOverloads.tpp"
289
290#define OPERATION_LOGIC OperationAtan2
291#define FUNCTION atan2f
292#include "binaryOverloads.tpp"
293
294#define OPERATION_LOGIC OperationAtan2
295#define FUNCTION atan2l
296#include "binaryOverloads.tpp"
297
299 template<typename T_Real>
300 struct OperationCopysign : public BinaryOperation<T_Real> {
301 public:
302
303 using Real = CODI_DD(T_Real, double);
304
306 template<typename ArgA, typename ArgB>
307 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
308 return copysign(argA, argB);
309 }
310
312 template<typename ArgA, typename ArgB>
313 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
314 Real const& result) {
315 CODI_UNUSED(result);
316 if (RealTraits::getPassiveValue(argA) < 0.0) {
317 if (RealTraits::getPassiveValue(argB) < 0.0) {
319 } else {
321 }
322 } else if (RealTraits::getPassiveValue(argA) > 0.0) {
323 if (RealTraits::getPassiveValue(argB) < 0.0) {
325 } else {
327 }
328 } else {
330 }
331 }
332
334 static CODI_INLINE std::string getMathRep() {
335 return "copysign()";
336 }
337
339 template<typename ArgA, typename ArgB>
340 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
341 Real const& result) {
342 CODI_UNUSED(argA, argB, result);
343
345 }
346 };
347
348#define OPERATION_LOGIC OperationCopysign
349#define FUNCTION copysign
350#include "binaryOverloads.tpp"
351
352#define OPERATION_LOGIC OperationCopysign
353#define FUNCTION copysignf
354#include "binaryOverloads.tpp"
355
356#define OPERATION_LOGIC OperationCopysign
357#define FUNCTION copysignl
358#include "binaryOverloads.tpp"
359
361 template<typename T_Real>
362 struct OperationFmod : public BinaryOperation<T_Real> {
363 public:
364
365 using Real = CODI_DD(T_Real, double);
366
368 template<typename ArgA, typename ArgB>
369 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
370 return fmod(argA, argB);
371 }
372
374 template<typename ArgA, typename ArgB>
375 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
376 Real const& result) {
377 CODI_UNUSED(argA, argB, result);
378
380 }
381
383 template<typename ArgA, typename ArgB>
384 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
385 Real const& result) {
386 CODI_UNUSED(result);
387
388 if (RealTraits::getPassiveValue(argB) == 0.0) {
390 } else {
391 return -trunc(RealTraits::getPassiveValue(argA / argB));
392 }
393 }
394
396 static CODI_INLINE std::string getMathRep() {
397 return "fmod()";
398 }
399 };
400
401#define OPERATION_LOGIC OperationFmod
402#define FUNCTION fmod
403#include "binaryOverloads.tpp"
404
405#define OPERATION_LOGIC OperationFmod
406#define FUNCTION fmodf
407#include "binaryOverloads.tpp"
408
409#define OPERATION_LOGIC OperationFmod
410#define FUNCTION fmodl
411#include "binaryOverloads.tpp"
412
414 template<typename T_Real>
415 struct OperationFrexp : public BinaryOperation<T_Real> {
416 public:
417
418 using Real = CODI_DD(T_Real, double);
419
421 template<typename ArgA, typename ArgB>
422 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
423 return frexp(argA, argB);
424 }
425
427 template<typename ArgA, typename ArgB>
428 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
429 CODI_UNUSED(argA, result);
430 /* The result is always computed beforehand, therefore we can safely use the value of b. */
431 return ldexp(1.0, -(*argB));
432 }
433
435 template<typename ArgA, typename ArgB>
436 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
437 Real const& result) {
438 CODI_UNUSED(argA, argB, result);
439
440 return 0.0;
441 }
443 static CODI_INLINE std::string getMathRep() {
444 return "frexp()";
445 }
446 };
447
448#ifndef DOXYGEN_DISABLE
449 template<typename T_StoreData>
450 struct IntPointerConversion : public ConstantDataConversion<T_StoreData> {
451 public:
452
453 using StoreData = CODI_DD(T_StoreData, double);
454 using ArgumentData = int*;
455
456 static int* fromDataStore(StoreData const& v) {
457 static int i = (int)v;
458 return &i;
459 }
460
461 static StoreData toDataStore(int const* v) {
462 return (StoreData)*v;
463 }
464 };
465#endif
466#define OPERATION_LOGIC OperationFrexp
467#define FUNCTION frexp
468#define SECOND_ARG_TYPE int*
469#define SECOND_ARG_CONVERSION IntPointerConversion
470#include "binaryFirstArgumentOverloads.tpp"
471
472#define OPERATION_LOGIC OperationFrexp
473#define FUNCTION frexpf
474#define SECOND_ARG_TYPE int*
475#define SECOND_ARG_CONVERSION IntPointerConversion
476#include "binaryFirstArgumentOverloads.tpp"
477
478#define OPERATION_LOGIC OperationFrexp
479#define FUNCTION frexpl
480#define SECOND_ARG_TYPE int*
481#define SECOND_ARG_CONVERSION IntPointerConversion
482#include "binaryFirstArgumentOverloads.tpp"
483
485 template<typename T_Real>
486 struct OperationHypot : public BinaryOperation<T_Real> {
487 public:
488
489 using Real = CODI_DD(T_Real, double);
490
492 template<typename ArgA, typename ArgB>
493 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
494 return hypot(argA, argB);
495 }
496
498 template<typename ArgA, typename ArgB>
499 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
500 CODI_UNUSED(argB);
501
502 checkResult(result);
503 if (result != 0.0) {
504 return argA / result;
505 } else {
506 return Real();
507 }
508 }
509
511 template<typename ArgA, typename ArgB>
512 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
513 CODI_UNUSED(argA);
514
515 checkResult(result);
516 if (result != 0.0) {
517 return argB / result;
518 } else {
519 return Real();
520 }
521 }
522
524 static CODI_INLINE std::string getMathRep() {
525 return "hypot()";
526 }
527
528 private:
529 static CODI_INLINE void checkResult(Real const& result) {
531 if (RealTraits::getPassiveValue(result) == 0.0) {
532 CODI_EXCEPTION("Zero divisor for hypot derivative.");
533 }
534 }
535 }
536 };
537
538#define OPERATION_LOGIC OperationHypot
539#define FUNCTION hypot
540#include "binaryOverloads.tpp"
541
542#define OPERATION_LOGIC OperationHypot
543#define FUNCTION hypotf
544#include "binaryOverloads.tpp"
545
546#define OPERATION_LOGIC OperationHypot
547#define FUNCTION hypotl
548#include "binaryOverloads.tpp"
549
551 template<typename T_Real>
552 struct OperationLdexp : public BinaryOperation<T_Real> {
553 public:
554
555 using Real = CODI_DD(T_Real, double);
556
558 template<typename ArgA, typename ArgB>
559 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
560 return ldexp(argA, argB);
561 }
562
564 template<typename ArgA, typename ArgB>
565 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
566 CODI_UNUSED(argA, result);
567
568 return ldexp(1.0, argB);
569 }
570
572 template<typename ArgA, typename ArgB>
573 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
574 Real const& result) {
575 CODI_UNUSED(argA, argB, result);
576
577 return 0.0;
578 }
579
581 static CODI_INLINE std::string getMathRep() {
582 return "ldexp()";
583 }
584 };
585#define OPERATION_LOGIC OperationLdexp
586#define FUNCTION ldexp
587#define SECOND_ARG_TYPE int
588#define SECOND_ARG_CONVERSION ConstantDataConversion
589#include "binaryFirstArgumentOverloads.tpp"
590
591#define OPERATION_LOGIC OperationLdexp
592#define FUNCTION ldexpl
593#define SECOND_ARG_TYPE int
594#define SECOND_ARG_CONVERSION ConstantDataConversion
595#include "binaryFirstArgumentOverloads.tpp"
596
597#define OPERATION_LOGIC OperationLdexp
598#define FUNCTION ldexpf
599#define SECOND_ARG_TYPE int
600#define SECOND_ARG_CONVERSION ConstantDataConversion
601#include "binaryFirstArgumentOverloads.tpp"
602
604 template<typename T_Real>
605 struct OperationMax : public BinaryOperation<T_Real> {
606 public:
607
608 using Real = CODI_DD(T_Real, double);
609
611 template<typename ArgA, typename ArgB>
612 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
613 return max(argA, argB);
614 }
615
617 template<typename ArgA, typename ArgB>
618 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
619 Real const& result) {
620 CODI_UNUSED(result);
621
623 return 1.0;
624 } else {
625 return 0.0;
626 }
627 }
628
630 static CODI_INLINE std::string getMathRep() {
631 return "max()";
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
648#define OPERATION_LOGIC OperationMax
649#define FUNCTION max
650#include "binaryOverloads.tpp"
651
652#define OPERATION_LOGIC OperationMax
653#define FUNCTION fmax
654#include "binaryOverloads.tpp"
655
656#define OPERATION_LOGIC OperationMax
657#define FUNCTION fmaxf
658#include "binaryOverloads.tpp"
659
660#define OPERATION_LOGIC OperationMax
661#define FUNCTION fmaxl
662#include "binaryOverloads.tpp"
663
665 template<typename T_Real>
666 struct OperationMin : public BinaryOperation<T_Real> {
667 public:
668
669 using Real = CODI_DD(T_Real, double);
670
672 template<typename ArgA, typename ArgB>
673 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
674 return min(argA, argB);
675 }
676
678 template<typename ArgA, typename ArgB>
679 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
680 Real const& result) {
681 CODI_UNUSED(result);
682
684 return 1.0;
685 } else {
686 return 0.0;
687 }
688 }
689
691 static CODI_INLINE std::string getMathRep() {
692 return "min()";
693 }
694
696 template<typename ArgA, typename ArgB>
697 static CODI_INLINE RealTraits::PassiveReal<Real> gradientB(ArgA const& argA, ArgB const& argB,
698 Real const& result) {
699 CODI_UNUSED(result);
700
702 return 0.0;
703 } else {
704 return 1.0;
705 }
706 }
707 };
708#define OPERATION_LOGIC OperationMin
709#define FUNCTION min
710#include "binaryOverloads.tpp"
711
712#define OPERATION_LOGIC OperationMin
713#define FUNCTION fmin
714#include "binaryOverloads.tpp"
715
716#define OPERATION_LOGIC OperationMin
717#define FUNCTION fminf
718#include "binaryOverloads.tpp"
719
720#define OPERATION_LOGIC OperationMin
721#define FUNCTION fminl
722#include "binaryOverloads.tpp"
723
725 template<typename T_Real>
726 struct OperationPow : public BinaryOperation<T_Real> {
727 public:
728
729 using Real = CODI_DD(T_Real, double);
730
732 template<typename ArgA, typename ArgB>
733 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
734 return pow(argA, argB);
735 }
736
738 template<typename ArgA, typename ArgB>
739 static CODI_INLINE Real gradientA(ArgA const& argA, ArgB const& argB, Real const& result) {
740 CODI_UNUSED(result);
741
742 checkArguments(argA, argB);
743 if (RealTraits::getPassiveValue(argA) <= 0.0 && 1 <= RealTraits::MaxDerivativeOrder<ArgB>()) {
744 // Special case for higher order derivatives. Derivative will be wrong since the argB part is not evaluated.
745 return RealTraits::getPassiveValue(argB) * pow(argA, argB - 1.0);
746 } else {
747 return argB * pow(argA, argB - 1.0);
748 }
749 }
750
752 template<typename ArgA, typename ArgB>
753 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
754 CODI_UNUSED(argB);
755
756 checkArguments(argA, argB);
757 if (RealTraits::getPassiveValue(argA) > 0.0) {
758 return log(argA) * result;
759 } else {
760 return Real();
761 }
762 }
763
765 static CODI_INLINE std::string getMathRep() {
766 return "pow()";
767 }
768
769 private:
770 template<typename ArgA, typename ArgB>
771 static CODI_INLINE void checkArguments(ArgA const& argA, ArgB const& argB) {
773 RealTraits::PassiveReal<ArgB> integralPart = 0.0;
774 std::modf(RealTraits::getPassiveValue(argB), &integralPart);
775
776 if (RealTraits::getPassiveValue(argA) < 0.0 && RealTraits::getPassiveValue(argB) != integralPart) {
777 CODI_EXCEPTION("Negative base for non-integral exponent in pow function. (Value: %0.15e)",
779 }
780 }
781 }
782 };
783#define OPERATION_LOGIC OperationPow
784#define FUNCTION pow
785#include "binaryOverloads.tpp"
786
787#define OPERATION_LOGIC OperationPow
788#define FUNCTION powf
789#include "binaryOverloads.tpp"
790
791#define OPERATION_LOGIC OperationPow
792#define FUNCTION powl
793#include "binaryOverloads.tpp"
794
798 template<typename T_Real>
799 struct OperationRemainder : public BinaryOperation<T_Real> {
800 public:
801
802 using Real = CODI_DD(T_Real, double);
803
805 template<typename ArgA, typename ArgB>
806 static CODI_INLINE Real primal(ArgA const& argA, ArgB const& argB) {
807 return remainder(argA, argB);
808 }
809
811 template<typename ArgA, typename ArgB>
812 static CODI_INLINE RealTraits::PassiveReal<Real> gradientA(ArgA const& argA, ArgB const& argB,
813 Real const& result) {
814 CODI_UNUSED(argA, argB, result);
815
816 return 1.0;
817 }
818
820 template<typename ArgA, typename ArgB>
821 static CODI_INLINE Real gradientB(ArgA const& argA, ArgB const& argB, Real const& result) {
822 CODI_UNUSED(result);
823
824 checkArguments(argB);
825
826 using std::round;
827 return -round(argA / argB);
828 }
829
831 static CODI_INLINE std::string getMathRep() {
832 return "%";
833 }
834
835 private:
836 template<typename ArgB>
837 static CODI_INLINE void checkArguments(ArgB const& argB) {
839 if (0.0 == RealTraits::getPassiveValue(argB)) {
840 CODI_EXCEPTION("Remainder called with divisor of zero.");
841 }
842 }
843 }
844 };
845#define OPERATION_LOGIC OperationRemainder
846#define FUNCTION remainder
847#include "binaryOverloads.tpp"
848
849#define OPERATION_LOGIC OperationRemainder
850#define FUNCTION remainderf
851#include "binaryOverloads.tpp"
852
853#define OPERATION_LOGIC OperationRemainder
854#define FUNCTION remainderl
855#include "binaryOverloads.tpp"
856
861
862 using std::swap;
863
865 template<typename Real, typename Gradient, typename Tape, typename Impl>
871
873}
874
875namespace std {
876 using codi::atan2;
877 using codi::atan2f;
878 using codi::atan2l;
879 using codi::copysign;
880 using codi::copysignf;
881 using codi::copysignl;
882 using codi::fmax;
883 using codi::fmaxf;
884 using codi::fmaxl;
885 using codi::fmin;
886 using codi::fminf;
887 using codi::fminl;
888 using codi::fmod;
889 using codi::fmodf;
890 using codi::fmodl;
891 using codi::frexp;
892 using codi::frexpf;
893 using codi::frexpl;
894 using codi::hypot;
895 using codi::hypotf;
896 using codi::hypotl;
897 using codi::ldexp;
898 using codi::ldexpf;
899 using codi::ldexpl;
900 using codi::max;
901 using codi::min;
902 using codi::pow;
903 using codi::powf;
904 using codi::powl;
905 using codi::remainder;
906 using codi::remainderf;
907 using codi::remainderl;
908 using codi::swap;
909}
#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:91
RealTraits::PassiveReal< Real > round(ExpressionInterface< Real, Arg > const &arg)
Function overload for round.
Definition unaryOperators.hpp:874
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:866
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 std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:85
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:238
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:245
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:262
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:241
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:272
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:251
BinaryOperation implementation for copysign.
Definition binaryOperators.hpp:300
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:303
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:313
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:340
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:334
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:307
BinaryOperation implementation for operator /.
Definition binaryOperators.hpp:169
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:182
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:176
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:191
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:199
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:172
BinaryOperation implementation for fmod.
Definition binaryOperators.hpp:362
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:396
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:365
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:384
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:375
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:369
BinaryOperation implementation for frexp.
Definition binaryOperators.hpp:415
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:428
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:418
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:436
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:422
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:443
BinaryOperation implementation for hypot.
Definition binaryOperators.hpp:486
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:493
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:512
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:524
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:489
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:499
BinaryOperation implementation for ldexp.
Definition binaryOperators.hpp:552
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:559
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:555
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:581
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:573
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:565
BinaryOperation implementation for max.
Definition binaryOperators.hpp:605
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:618
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:630
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:612
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:636
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:608
BinaryOperation implementation for min.
Definition binaryOperators.hpp:666
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:669
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:691
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:673
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:697
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:679
BinaryOperation implementation for operator *.
Definition binaryOperators.hpp:133
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:136
static ArgB const & gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:146
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:140
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:159
static ArgA const & gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:153
BinaryOperation implementation for pow.
Definition binaryOperators.hpp:726
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:733
static Real gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:739
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:729
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:765
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:753
Definition binaryOperators.hpp:799
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:802
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:806
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:831
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:812
static Real gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:821
BinaryOperation implementation for operator -.
Definition binaryOperators.hpp:95
static RealTraits::PassiveReal< Real > gradientA(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:108
T_Real Real
See BinaryOperation.
Definition binaryOperators.hpp:98
static std::string getMathRep()
Get the math symbol of the binary operation. E.g. + for operators and pow() for functions.
Definition binaryOperators.hpp:123
static Real primal(ArgA const &argA, ArgB const &argB)
Definition binaryOperators.hpp:102
static RealTraits::PassiveReal< Real > gradientB(ArgA const &argA, ArgB const &argB, Real const &result)
Definition binaryOperators.hpp:116