41#include "../../misc/exceptions.hpp"
43#include "../../traits/realTraits.hpp"
44#include "../binaryExpression.hpp"
45#include "../constantExpression.hpp"
46#include "../lhsExpressionInterface.hpp"
56 template<
typename T_Real>
63 template<
typename ArgA,
typename ArgB>
69 template<
typename ArgA,
typename ArgB>
77 template<
typename ArgA,
typename ArgB>
89#define OPERATION_LOGIC OperationAdd
90#define FUNCTION operator+
91#include "binaryOverloads.tpp"
94 template<
typename T_Real>
101 template<
typename ArgA,
typename ArgB>
107 template<
typename ArgA,
typename ArgB>
109 Real const& result) {
115 template<
typename ArgA,
typename ArgB>
117 Real const& result) {
127#define OPERATION_LOGIC OperationSubstract
128#define FUNCTION operator-
129#include "binaryOverloads.tpp"
132 template<
typename T_Real>
139 template<
typename ArgA,
typename ArgB>
145 template<
typename ArgA,
typename ArgB>
152 template<
typename ArgA,
typename ArgB>
163#define OPERATION_LOGIC OperationMultiply
164#define FUNCTION operator*
165#include "binaryOverloads.tpp"
168 template<
typename T_Real>
175 template<
typename ArgA,
typename ArgB>
181 template<
typename ArgA,
typename ArgB>
185 checkArguments(argB);
190 template<
typename ArgA,
typename ArgB>
194 checkArguments(argB);
195 return -result / argB;
204 template<
typename ArgB>
205 static CODI_INLINE void checkArguments(ArgB
const& argB) {
208 CODI_EXCEPTION(
"Division called with divisor of zero.");
213#define OPERATION_LOGIC OperationDivide
214#define FUNCTION operator/
215#include "binaryOverloads.tpp"
233 using std::remainder;
237 template<
typename T_Real>
244 template<
typename ArgA,
typename ArgB>
246 return atan2(argA, argB);
250 template<
typename ArgA,
typename ArgB>
254 checkArguments(argA, argB);
255 Real divisor = argA * argA + argB * argB;
256 divisor = 1.0 / divisor;
257 return argB * divisor;
261 template<
typename ArgA,
typename ArgB>
265 checkArguments(argA, argB);
266 Real divisor = argA * argA + argB * argB;
267 divisor = 1.0 / divisor;
268 return -argA * divisor;
277 template<
typename ArgA,
typename ArgB>
278 static CODI_INLINE void checkArguments(ArgA& argA, ArgB& argB) {
281 CODI_EXCEPTION(
"atan2 called at point (0,0).");
286#define OPERATION_LOGIC OperationAtan2
287#define FUNCTION atan2
288#include "binaryOverloads.tpp"
290#define OPERATION_LOGIC OperationAtan2
291#define FUNCTION atan2f
292#include "binaryOverloads.tpp"
294#define OPERATION_LOGIC OperationAtan2
295#define FUNCTION atan2l
296#include "binaryOverloads.tpp"
299 template<
typename T_Real>
306 template<
typename ArgA,
typename ArgB>
308 return copysign(argA, argB);
312 template<
typename ArgA,
typename ArgB>
314 Real const& result) {
339 template<
typename ArgA,
typename ArgB>
341 Real const& result) {
348#define OPERATION_LOGIC OperationCopysign
349#define FUNCTION copysign
350#include "binaryOverloads.tpp"
352#define OPERATION_LOGIC OperationCopysign
353#define FUNCTION copysignf
354#include "binaryOverloads.tpp"
356#define OPERATION_LOGIC OperationCopysign
357#define FUNCTION copysignl
358#include "binaryOverloads.tpp"
361 template<
typename T_Real>
368 template<
typename ArgA,
typename ArgB>
370 return fmod(argA, argB);
374 template<
typename ArgA,
typename ArgB>
376 Real const& result) {
383 template<
typename ArgA,
typename ArgB>
385 Real const& result) {
401#define OPERATION_LOGIC OperationFmod
403#include "binaryOverloads.tpp"
405#define OPERATION_LOGIC OperationFmod
406#define FUNCTION fmodf
407#include "binaryOverloads.tpp"
409#define OPERATION_LOGIC OperationFmod
410#define FUNCTION fmodl
411#include "binaryOverloads.tpp"
414 template<
typename T_Real>
421 template<
typename ArgA,
typename ArgB>
423 return frexp(argA, argB);
427 template<
typename ArgA,
typename ArgB>
431 return ldexp(1.0, -(*argB));
435 template<
typename ArgA,
typename ArgB>
437 Real const& result) {
448#ifndef DOXYGEN_DISABLE
449 template<
typename T_StoreData>
450 struct IntPointerConversion :
public ConstantDataConversion<T_StoreData> {
453 using StoreData =
CODI_DD(T_StoreData,
double);
454 using ArgumentData =
int*;
456 static int* fromDataStore(StoreData
const& v) {
457 static int i = (int)v;
461 static StoreData toDataStore(
int const* v) {
462 return (StoreData)*v;
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"
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"
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"
485 template<
typename T_Real>
492 template<
typename ArgA,
typename ArgB>
494 return hypot(argA, argB);
498 template<
typename ArgA,
typename ArgB>
504 return argA / result;
511 template<
typename ArgA,
typename ArgB>
517 return argB / result;
532 CODI_EXCEPTION(
"Zero divisor for hypot derivative.");
538#define OPERATION_LOGIC OperationHypot
539#define FUNCTION hypot
540#include "binaryOverloads.tpp"
542#define OPERATION_LOGIC OperationHypot
543#define FUNCTION hypotf
544#include "binaryOverloads.tpp"
546#define OPERATION_LOGIC OperationHypot
547#define FUNCTION hypotl
548#include "binaryOverloads.tpp"
551 template<
typename T_Real>
558 template<
typename ArgA,
typename ArgB>
560 return ldexp(argA, argB);
564 template<
typename ArgA,
typename ArgB>
568 return ldexp(1.0, argB);
572 template<
typename ArgA,
typename ArgB>
574 Real const& result) {
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"
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"
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"
604 template<
typename T_Real>
611 template<
typename ArgA,
typename ArgB>
613 return max(argA, argB);
617 template<
typename ArgA,
typename ArgB>
619 Real const& result) {
635 template<
typename ArgA,
typename ArgB>
637 Real const& result) {
648#define OPERATION_LOGIC OperationMax
650#include "binaryOverloads.tpp"
652#define OPERATION_LOGIC OperationMax
654#include "binaryOverloads.tpp"
656#define OPERATION_LOGIC OperationMax
657#define FUNCTION fmaxf
658#include "binaryOverloads.tpp"
660#define OPERATION_LOGIC OperationMax
661#define FUNCTION fmaxl
662#include "binaryOverloads.tpp"
665 template<
typename T_Real>
672 template<
typename ArgA,
typename ArgB>
674 return min(argA, argB);
678 template<
typename ArgA,
typename ArgB>
680 Real const& result) {
696 template<
typename ArgA,
typename ArgB>
698 Real const& result) {
708#define OPERATION_LOGIC OperationMin
710#include "binaryOverloads.tpp"
712#define OPERATION_LOGIC OperationMin
714#include "binaryOverloads.tpp"
716#define OPERATION_LOGIC OperationMin
717#define FUNCTION fminf
718#include "binaryOverloads.tpp"
720#define OPERATION_LOGIC OperationMin
721#define FUNCTION fminl
722#include "binaryOverloads.tpp"
725 template<
typename T_Real>
732 template<
typename ArgA,
typename ArgB>
734 return pow(argA, argB);
738 template<
typename ArgA,
typename ArgB>
742 checkArguments(argA, argB);
747 return argB * pow(argA, argB - 1.0);
752 template<
typename ArgA,
typename ArgB>
756 checkArguments(argA, argB);
758 return log(argA) * result;
770 template<
typename ArgA,
typename ArgB>
771 static CODI_INLINE void checkArguments(ArgA
const& argA, ArgB
const& argB) {
777 CODI_EXCEPTION(
"Negative base for non-integral exponent in pow function. (Value: %0.15e)",
783#define OPERATION_LOGIC OperationPow
785#include "binaryOverloads.tpp"
787#define OPERATION_LOGIC OperationPow
789#include "binaryOverloads.tpp"
791#define OPERATION_LOGIC OperationPow
793#include "binaryOverloads.tpp"
798 template<
typename T_Real>
805 template<
typename ArgA,
typename ArgB>
807 return remainder(argA, argB);
811 template<
typename ArgA,
typename ArgB>
813 Real const& result) {
820 template<
typename ArgA,
typename ArgB>
824 checkArguments(argB);
827 return -
round(argA / argB);
836 template<
typename ArgB>
837 static CODI_INLINE void checkArguments(ArgB
const& argB) {
840 CODI_EXCEPTION(
"Remainder called with divisor of zero.");
845#define OPERATION_LOGIC OperationRemainder
846#define FUNCTION remainder
847#include "binaryOverloads.tpp"
849#define OPERATION_LOGIC OperationRemainder
850#define FUNCTION remainderf
851#include "binaryOverloads.tpp"
853#define OPERATION_LOGIC OperationRemainder
854#define FUNCTION remainderl
855#include "binaryOverloads.tpp"
865 template<
typename Real,
typename Gradient,
typename Tape,
typename Impl>
879 using codi::copysign;
880 using codi::copysignf;
881 using codi::copysignl;
905 using codi::remainder;
906 using codi::remainderf;
907 using codi::remainderl;
#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