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>
84#define OPERATION_LOGIC OperationAdd
85#define FUNCTION operator+
86#include "binaryOverloads.tpp"
89 template<
typename T_Real>
96 template<
typename ArgA,
typename ArgB>
102 template<
typename ArgA,
typename ArgB>
104 Real const& result) {
110 template<
typename ArgA,
typename ArgB>
112 Real const& result) {
117#define OPERATION_LOGIC OperationSubstract
118#define FUNCTION operator-
119#include "binaryOverloads.tpp"
122 template<
typename T_Real>
129 template<
typename ArgA,
typename ArgB>
135 template<
typename ArgA,
typename ArgB>
142 template<
typename ArgA,
typename ArgB>
148#define OPERATION_LOGIC OperationMultiply
149#define FUNCTION operator*
150#include "binaryOverloads.tpp"
153 template<
typename T_Real>
160 template<
typename ArgA,
typename ArgB>
166 template<
typename ArgA,
typename ArgB>
170 checkArguments(argB);
175 template<
typename ArgA,
typename ArgB>
179 checkArguments(argB);
180 return -result / argB;
184 template<
typename ArgB>
185 static CODI_INLINE void checkArguments(ArgB
const& argB) {
188 CODI_EXCEPTION(
"Division called with divisor of zero.");
193#define OPERATION_LOGIC OperationDivide
194#define FUNCTION operator/
195#include "binaryOverloads.tpp"
213 using std::remainder;
217 template<
typename T_Real>
224 template<
typename ArgA,
typename ArgB>
226 return atan2(argA, argB);
230 template<
typename ArgA,
typename ArgB>
234 checkArguments(argA, argB);
235 Real divisor = argA * argA + argB * argB;
236 divisor = 1.0 / divisor;
237 return argB * divisor;
241 template<
typename ArgA,
typename ArgB>
245 checkArguments(argA, argB);
246 Real divisor = argA * argA + argB * argB;
247 divisor = 1.0 / divisor;
248 return -argA * divisor;
252 template<
typename ArgA,
typename ArgB>
253 static CODI_INLINE void checkArguments(ArgA& argA, ArgB& argB) {
256 CODI_EXCEPTION(
"atan2 called at point (0,0).");
261#define OPERATION_LOGIC OperationAtan2
262#define FUNCTION atan2
263#include "binaryOverloads.tpp"
265#define OPERATION_LOGIC OperationAtan2
266#define FUNCTION atan2f
267#include "binaryOverloads.tpp"
269#define OPERATION_LOGIC OperationAtan2
270#define FUNCTION atan2l
271#include "binaryOverloads.tpp"
274 template<
typename T_Real>
281 template<
typename ArgA,
typename ArgB>
283 return copysign(argA, argB);
287 template<
typename ArgA,
typename ArgB>
289 Real const& result) {
309 template<
typename ArgA,
typename ArgB>
311 Real const& result) {
318#define OPERATION_LOGIC OperationCopysign
319#define FUNCTION copysign
320#include "binaryOverloads.tpp"
322#define OPERATION_LOGIC OperationCopysign
323#define FUNCTION copysignf
324#include "binaryOverloads.tpp"
326#define OPERATION_LOGIC OperationCopysign
327#define FUNCTION copysignl
328#include "binaryOverloads.tpp"
331 template<
typename T_Real>
338 template<
typename ArgA,
typename ArgB>
340 return fmod(argA, argB);
344 template<
typename ArgA,
typename ArgB>
346 Real const& result) {
353 template<
typename ArgA,
typename ArgB>
355 Real const& result) {
366#define OPERATION_LOGIC OperationFmod
368#include "binaryOverloads.tpp"
370#define OPERATION_LOGIC OperationFmod
371#define FUNCTION fmodf
372#include "binaryOverloads.tpp"
374#define OPERATION_LOGIC OperationFmod
375#define FUNCTION fmodl
376#include "binaryOverloads.tpp"
379 template<
typename T_Real>
386 template<
typename ArgA,
typename ArgB>
388 return frexp(argA, argB);
392 template<
typename ArgA,
typename ArgB>
396 return ldexp(1.0, -(*argB));
400 template<
typename ArgA,
typename ArgB>
408#ifndef DOXYGEN_DISABLE
409 template<
typename T_StoreData>
410 struct IntPointerConversion :
public ConstantDataConversion<T_StoreData> {
413 using StoreData =
CODI_DD(T_StoreData,
double);
414 using ArgumentData =
int*;
416 static int* fromDataStore(StoreData
const& v) {
417 static int i = (int)v;
421 static StoreData toDataStore(
int const* v) {
422 return (StoreData)*v;
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"
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"
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"
445 template<
typename T_Real>
452 template<
typename ArgA,
typename ArgB>
454 return hypot(argA, argB);
458 template<
typename ArgA,
typename ArgB>
464 return argA / result;
471 template<
typename ArgA,
typename ArgB>
477 return argB / result;
487 CODI_EXCEPTION(
"Zero divisor for hypot derivative.");
493#define OPERATION_LOGIC OperationHypot
494#define FUNCTION hypot
495#include "binaryOverloads.tpp"
497#define OPERATION_LOGIC OperationHypot
498#define FUNCTION hypotf
499#include "binaryOverloads.tpp"
501#define OPERATION_LOGIC OperationHypot
502#define FUNCTION hypotl
503#include "binaryOverloads.tpp"
506 template<
typename T_Real>
513 template<
typename ArgA,
typename ArgB>
515 return ldexp(argA, argB);
519 template<
typename ArgA,
typename ArgB>
523 return ldexp(1.0, argB);
527 template<
typename ArgA,
typename ArgB>
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"
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"
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"
553 template<
typename T_Real>
560 template<
typename ArgA,
typename ArgB>
562 return max(argA, argB);
566 template<
typename ArgA,
typename ArgB>
568 Real const& result) {
579 template<
typename ArgA,
typename ArgB>
581 Real const& result) {
592#define OPERATION_LOGIC OperationMax
594#include "binaryOverloads.tpp"
596#define OPERATION_LOGIC OperationMax
598#include "binaryOverloads.tpp"
600#define OPERATION_LOGIC OperationMax
601#define FUNCTION fmaxf
602#include "binaryOverloads.tpp"
604#define OPERATION_LOGIC OperationMax
605#define FUNCTION fmaxl
606#include "binaryOverloads.tpp"
609 template<
typename T_Real>
616 template<
typename ArgA,
typename ArgB>
618 return min(argA, argB);
622 template<
typename ArgA,
typename ArgB>
624 Real const& result) {
635 template<
typename ArgA,
typename ArgB>
637 Real const& result) {
647#define OPERATION_LOGIC OperationMin
649#include "binaryOverloads.tpp"
651#define OPERATION_LOGIC OperationMin
653#include "binaryOverloads.tpp"
655#define OPERATION_LOGIC OperationMin
656#define FUNCTION fminf
657#include "binaryOverloads.tpp"
659#define OPERATION_LOGIC OperationMin
660#define FUNCTION fminl
661#include "binaryOverloads.tpp"
664 template<
typename T_Real>
671 template<
typename ArgA,
typename ArgB>
673 return pow(argA, argB);
677 template<
typename ArgA,
typename ArgB>
681 checkArguments(argA, argB);
686 return argB * pow(argA, argB - 1.0);
691 template<
typename ArgA,
typename ArgB>
695 checkArguments(argA, argB);
697 return log(argA) * result;
704 template<
typename ArgA,
typename ArgB>
705 static CODI_INLINE void checkArguments(ArgA
const& argA, ArgB
const& argB) {
711 CODI_EXCEPTION(
"Negative base for non-integral exponent in pow function. (Value: %0.15e)",
717#define OPERATION_LOGIC OperationPow
719#include "binaryOverloads.tpp"
721#define OPERATION_LOGIC OperationPow
723#include "binaryOverloads.tpp"
725#define OPERATION_LOGIC OperationPow
727#include "binaryOverloads.tpp"
732 template<
typename T_Real>
739 template<
typename ArgA,
typename ArgB>
741 return remainder(argA, argB);
745 template<
typename ArgA,
typename ArgB>
753 template<
typename ArgA,
typename ArgB>
757 checkArguments(argB);
760 return -
round(argA / argB);
764 template<
typename ArgB>
765 static CODI_INLINE void checkArguments(ArgB
const& argB) {
768 CODI_EXCEPTION(
"Remainder called with divisor of zero.");
773#define OPERATION_LOGIC OperationRemainder
774#define FUNCTION remainder
775#include "binaryOverloads.tpp"
777#define OPERATION_LOGIC OperationRemainder
778#define FUNCTION remainderf
779#include "binaryOverloads.tpp"
781#define OPERATION_LOGIC OperationRemainder
782#define FUNCTION remainderl
783#include "binaryOverloads.tpp"
793 template<
typename Real,
typename Gradient,
typename Tape,
typename Impl>
807 using codi::copysign;
808 using codi::copysignf;
809 using codi::copysignl;
833 using codi::remainder;
834 using codi::remainderf;
835 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: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