40#include "../../misc/exceptions.hpp"
42#include "../../traits/realTraits.hpp"
43#include "../unaryExpression.hpp"
53 template<
typename T_Real>
60 template<
typename Arg>
66 template<
typename Arg>
73#define OPERATION_LOGIC OperationUnaryMinus
74#define FUNCTION operator-
75#include "unaryOverloads.tpp"
78 template<
typename Real,
typename Arg>
117 template<
typename T_Real>
124 template<
typename Arg>
130 template<
typename Arg>
135 }
else if (arg > 0.0) {
142#define OPERATION_LOGIC OperationAbs
144#include "unaryOverloads.tpp"
146#define OPERATION_LOGIC OperationAbs
148#include "unaryOverloads.tpp"
150#define OPERATION_LOGIC OperationAbs
151#define FUNCTION fabsf
152#include "unaryOverloads.tpp"
154#define OPERATION_LOGIC OperationAbs
155#define FUNCTION fabsl
156#include "unaryOverloads.tpp"
159 template<
typename T_Real>
166 template<
typename Arg>
172 template<
typename Arg>
180 return -1.0 / sqrt(1.0 - arg * arg);
183#define OPERATION_LOGIC OperationAcos
185#include "unaryOverloads.tpp"
187#define OPERATION_LOGIC OperationAcos
188#define FUNCTION acosf
189#include "unaryOverloads.tpp"
191#define OPERATION_LOGIC OperationAcos
192#define FUNCTION acosl
193#include "unaryOverloads.tpp"
196 template<
typename T_Real>
203 template<
typename Arg>
209 template<
typename Arg>
217 return 1.0 / sqrt(1.0 - arg * arg);
220#define OPERATION_LOGIC OperationAsin
222#include "unaryOverloads.tpp"
224#define OPERATION_LOGIC OperationAsin
225#define FUNCTION asinf
226#include "unaryOverloads.tpp"
228#define OPERATION_LOGIC OperationAsin
229#define FUNCTION asinl
230#include "unaryOverloads.tpp"
233 template<
typename T_Real>
240 template<
typename Arg>
246 template<
typename Arg>
249 return 1.0 / (1.0 + arg * arg);
252#define OPERATION_LOGIC OperationAtan
254#include "unaryOverloads.tpp"
256#define OPERATION_LOGIC OperationAtan
257#define FUNCTION atanf
258#include "unaryOverloads.tpp"
260#define OPERATION_LOGIC OperationAtan
261#define FUNCTION atanl
262#include "unaryOverloads.tpp"
265 template<
typename T_Real>
272 template<
typename Arg>
278 template<
typename Arg>
286 return 1.0 / (1.0 - arg * arg);
289#define OPERATION_LOGIC OperationAtanh
290#define FUNCTION atanh
291#include "unaryOverloads.tpp"
293#define OPERATION_LOGIC OperationAtanh
294#define FUNCTION atanhf
295#include "unaryOverloads.tpp"
297#define OPERATION_LOGIC OperationAtanh
298#define FUNCTION atanhl
299#include "unaryOverloads.tpp"
302 template<
typename T_Real>
309 template<
typename Arg>
315 template<
typename Arg>
323 return 1.0 / (3.0 * result * result);
329#define OPERATION_LOGIC OperationCbrt
331#include "unaryOverloads.tpp"
333#define OPERATION_LOGIC OperationCbrt
334#define FUNCTION cbrtf
335#include "unaryOverloads.tpp"
337#define OPERATION_LOGIC OperationCbrt
338#define FUNCTION cbrtl
339#include "unaryOverloads.tpp"
342 template<
typename Real,
typename Arg>
348 template<
typename Real,
typename Arg>
354 template<
typename Real,
typename Arg>
360 template<
typename T_Real>
367 template<
typename Arg>
373 template<
typename Arg>
379#define OPERATION_LOGIC OperationCos
381#include "unaryOverloads.tpp"
383#define OPERATION_LOGIC OperationCos
385#include "unaryOverloads.tpp"
387#define OPERATION_LOGIC OperationCos
389#include "unaryOverloads.tpp"
392 template<
typename T_Real>
399 template<
typename Arg>
405 template<
typename Arg>
411#define OPERATION_LOGIC OperationCosh
413#include "unaryOverloads.tpp"
415#define OPERATION_LOGIC OperationCosh
416#define FUNCTION coshf
417#include "unaryOverloads.tpp"
419#define OPERATION_LOGIC OperationCosh
420#define FUNCTION coshl
421#include "unaryOverloads.tpp"
424 template<
typename T_Real>
431 template<
typename Arg>
437 template<
typename Arg>
440 return 1.128379167095513 * exp(-(arg * arg));
443#define OPERATION_LOGIC OperationErf
445#include "unaryOverloads.tpp"
447#define OPERATION_LOGIC OperationErf
449#include "unaryOverloads.tpp"
451#define OPERATION_LOGIC OperationErf
453#include "unaryOverloads.tpp"
456 template<
typename T_Real>
463 template<
typename Arg>
469 template<
typename Arg>
472 return -1.128379167095513 * exp(-(arg * arg));
475#define OPERATION_LOGIC OperationErfc
477#include "unaryOverloads.tpp"
479#define OPERATION_LOGIC OperationErfc
480#define FUNCTION erfcf
481#include "unaryOverloads.tpp"
483#define OPERATION_LOGIC OperationErfc
484#define FUNCTION erfcl
485#include "unaryOverloads.tpp"
488 template<
typename T_Real>
495 template<
typename Arg>
501 template<
typename Arg>
507#define OPERATION_LOGIC OperationExp
509#include "unaryOverloads.tpp"
511#define OPERATION_LOGIC OperationExp
513#include "unaryOverloads.tpp"
515#define OPERATION_LOGIC OperationExp
517#include "unaryOverloads.tpp"
520 template<
typename Real,
typename Arg>
526 template<
typename Real,
typename Arg>
532 template<
typename Real,
typename Arg>
538 template<
typename Real,
typename Arg>
544 template<
typename Real,
typename Arg>
550 template<
typename Real,
typename Arg>
556 template<
typename Real,
typename Arg>
562 template<
typename T_Real>
569 template<
typename Arg>
575 template<
typename Arg>
586#define OPERATION_LOGIC OperationLog
588#include "unaryOverloads.tpp"
590#define OPERATION_LOGIC OperationLog
592#include "unaryOverloads.tpp"
594#define OPERATION_LOGIC OperationLog
596#include "unaryOverloads.tpp"
599 template<
typename T_Real>
606 template<
typename Arg>
612 template<
typename Arg>
620 return 0.434294481903252 / arg;
623#define OPERATION_LOGIC OperationLog10
624#define FUNCTION log10
625#include "unaryOverloads.tpp"
627#define OPERATION_LOGIC OperationLog10
628#define FUNCTION log10f
629#include "unaryOverloads.tpp"
631#define OPERATION_LOGIC OperationLog10
632#define FUNCTION log10l
633#include "unaryOverloads.tpp"
636 template<
typename Real,
typename Arg>
642 template<
typename Real,
typename Arg>
648 template<
typename Real,
typename Arg>
654 template<
typename T_Real>
661 template<
typename Arg>
667 template<
typename Arg>
673#define OPERATION_LOGIC OperationSin
675#include "unaryOverloads.tpp"
677#define OPERATION_LOGIC OperationSin
679#include "unaryOverloads.tpp"
681#define OPERATION_LOGIC OperationSin
683#include "unaryOverloads.tpp"
686 template<
typename T_Real>
693 template<
typename Arg>
699 template<
typename Arg>
705#define OPERATION_LOGIC OperationSinh
707#include "unaryOverloads.tpp"
709#define OPERATION_LOGIC OperationSinh
710#define FUNCTION sinhf
711#include "unaryOverloads.tpp"
713#define OPERATION_LOGIC OperationSinh
714#define FUNCTION sinhl
715#include "unaryOverloads.tpp"
718 template<
typename T_Real>
725 template<
typename Arg>
731 template<
typename Arg>
745#define OPERATION_LOGIC OperationSqrt
747#include "unaryOverloads.tpp"
749#define OPERATION_LOGIC OperationSqrt
750#define FUNCTION sqrtf
751#include "unaryOverloads.tpp"
753#define OPERATION_LOGIC OperationSqrt
754#define FUNCTION sqrtl
755#include "unaryOverloads.tpp"
758 template<
typename T_Real>
765 template<
typename Arg>
771 template<
typename Arg>
779 Real tmp = 1.0 / cos(arg);
783#define OPERATION_LOGIC OperationTan
785#include "unaryOverloads.tpp"
787#define OPERATION_LOGIC OperationTan
789#include "unaryOverloads.tpp"
791#define OPERATION_LOGIC OperationTan
793#include "unaryOverloads.tpp"
796 template<
typename T_Real>
803 template<
typename Arg>
809 template<
typename Arg>
812 return 1.0 - result * result;
815#define OPERATION_LOGIC OperationTanh
817#include "unaryOverloads.tpp"
819#define OPERATION_LOGIC OperationTanh
820#define FUNCTION tanhf
821#include "unaryOverloads.tpp"
823#define OPERATION_LOGIC OperationTanh
824#define FUNCTION tanhl
825#include "unaryOverloads.tpp"
828 template<
typename T_Real>
835 template<
typename Arg>
841 template<
typename Arg>
844 std::cout <<
"Derivative for gamma function only for positive arguments at the moment" << std::endl;
856 if (arg <= 0.000001) {
857 const Real eulerMascheroni = 0.57721566490153286060;
858 diGamma = -eulerMascheroni - 1.0 / arg + 1.6449340668482264365 * arg;
862 Real shiftBound = 8.5;
864 Real shiftedValue = arg;
865 while (shiftedValue < shiftBound) {
866 diGamma -= 1.0 / shiftedValue;
871 Real r = 1.0 / shiftedValue;
872 diGamma += log(shiftedValue) - 0.5 * r;
875 diGamma -= rSqr * (1.0 / 12.0 -
876 rSqr * (1.0 / 120.0 - rSqr * (1.0 / 252.0 - rSqr * (1.0 / 240.0 - rSqr * (1.0 / 132.0)))));
879 return diGamma * result;
882#define OPERATION_LOGIC OperationTgamma
883#define FUNCTION tgamma
884#include "unaryOverloads.tpp"
886#define OPERATION_LOGIC OperationTgamma
887#define FUNCTION tgammaf
888#include "unaryOverloads.tpp"
890#define OPERATION_LOGIC OperationTgamma
891#define FUNCTION tgammal
892#include "unaryOverloads.tpp"
900 template<
typename Real,
typename Arg>
902 using std::to_string;
952 using codi::isfinite;
955 using codi::isnormal;
#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
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
RealTraits::PassiveReal< Real > ceil(ExpressionInterface< Real, Arg > const &arg)
Function overload for ceil.
Definition unaryOperators.hpp:343
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
RealTraits::PassiveReal< Real > roundf(ExpressionInterface< Real, Arg > const &arg)
Function overload for roundf.
Definition unaryOperators.hpp:643
bool isfinite(ExpressionInterface< Real, Arg > const &arg)
Function overload for isfinite.
Definition unaryOperators.hpp:539
RealTraits::PassiveReal< Real > floorf(ExpressionInterface< Real, Arg > const &arg)
Function overload for floorf.
Definition unaryOperators.hpp:527
bool isnan(ExpressionInterface< Real, Arg > const &arg)
Function overload for isnan.
Definition unaryOperators.hpp:551
std::string to_string(ExpressionInterface< Real, Arg > const &arg)
Function overload for to_string.
Definition unaryOperators.hpp:901
RealTraits::PassiveReal< Real > roundl(ExpressionInterface< Real, Arg > const &arg)
Function overload for roundl.
Definition unaryOperators.hpp:649
RealTraits::PassiveReal< Real > floorl(ExpressionInterface< Real, Arg > const &arg)
Function overload for floorl.
Definition unaryOperators.hpp:533
ExpressionInterface< Real, Arg > const & operator+(ExpressionInterface< Real, Arg > const &arg)
Function overload for operator +.
Definition unaryOperators.hpp:79
RealTraits::PassiveReal< Real > ceilf(ExpressionInterface< Real, Arg > const &arg)
Function overload for ceilf.
Definition unaryOperators.hpp:349
RealTraits::PassiveReal< Real > floor(ExpressionInterface< Real, Arg > const &arg)
Function overload for floor.
Definition unaryOperators.hpp:521
bool isinf(ExpressionInterface< Real, Arg > const &arg)
Function overload for isinf.
Definition unaryOperators.hpp:545
bool isnormal(ExpressionInterface< Real, Arg > const &arg)
Function overload for isnormal.
Definition unaryOperators.hpp:557
RealTraits::PassiveReal< Real > ceill(ExpressionInterface< Real, Arg > const &arg)
Function overload for ceill.
Definition unaryOperators.hpp:355
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Impl const & cast() const
Cast to the implementation.
Definition expressionInterface.hpp:75
UnaryOperation implementation for abs.
Definition unaryOperators.hpp:118
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:125
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:121
static RealTraits::PassiveReal< Real > gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:131
UnaryOperation implementation for acos.
Definition unaryOperators.hpp:160
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:173
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:167
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:163
UnaryOperation implementation for asin.
Definition unaryOperators.hpp:197
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:204
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:210
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:200
UnaryOperation implementation for atan.
Definition unaryOperators.hpp:234
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:241
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:237
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:247
UnaryOperation implementation for atanh.
Definition unaryOperators.hpp:266
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:279
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:269
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:273
UnaryOperation implementation for cbrt.
Definition unaryOperators.hpp:303
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:306
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:316
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:310
UnaryOperation implementation for cos.
Definition unaryOperators.hpp:361
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:364
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:368
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:374
UnaryOperation implementation for cosh.
Definition unaryOperators.hpp:393
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:396
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:406
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:400
UnaryOperation implementation for erf.
Definition unaryOperators.hpp:425
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:432
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:428
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:438
UnaryOperation implementation for erfc.
Definition unaryOperators.hpp:457
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:464
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:470
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:460
UnaryOperation implementation for exp.
Definition unaryOperators.hpp:489
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:496
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:492
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:502
UnaryOperation implementation for log10.
Definition unaryOperators.hpp:600
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:603
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:607
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:613
UnaryOperation implementation for log.
Definition unaryOperators.hpp:563
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:570
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:576
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:566
UnaryOperation implementation for sin.
Definition unaryOperators.hpp:655
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:662
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:668
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:658
UnaryOperation implementation for sinh.
Definition unaryOperators.hpp:687
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:690
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:694
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:700
UnaryOperation implementation for sqrt.
Definition unaryOperators.hpp:719
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:732
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:726
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:722
UnaryOperation implementation for tan.
Definition unaryOperators.hpp:759
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:766
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:762
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:772
UnaryOperation implementation for tanh.
Definition unaryOperators.hpp:797
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:810
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:804
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:800
UnaryOperation implementation for tgamma.
Definition unaryOperators.hpp:829
static Real gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:842
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:836
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:832
UnaryOperation implementation for operator -.
Definition unaryOperators.hpp:54
static RealTraits::PassiveReal< Real > gradient(Arg const &arg, Real const &result)
Definition unaryOperators.hpp:67
static Real primal(Arg const &arg)
Definition unaryOperators.hpp:61
T_Real Real
See BinaryOperation.
Definition unaryOperators.hpp:57
Interface for implementing the logic for a UnaryExpression.
Definition unaryExpression.hpp:55