18#ifndef ADOLC_AD_TYPES_H
19#define ADOLC_AD_TYPES_H
43 std::is_same_v<T, adouble> || std::is_same_v<T, pdouble>;
74 if constexpr (std::is_same_v<T, adouble>)
87 "Tape was deleted before all adoubles are destroyed!");
88 if constexpr (std::is_same_v<T, adouble>)
136 : loc_(
loc), valid_(mode) {}
151 : loc_(other.loc_), valid_(other.valid_) {
171 valid_ = other.valid_;
182 size_t loc()
const {
return loc_; }
273 bool is_valid()
const {
return tape_loc_.is_valid(); }
302 if (
this == &other) {
305 tape_loc_ = std::move(other.tape_loc_);
334 return tape_loc_.loc();
354 explicit operator double()
const {
return value(); }
372 inline adouble &operator/=(
const double coval);
467 tape_loc_ = std::move(other.tape_loc_);
490 size_t loc()
const {
return tape_loc_.loc(); }
519 std::span<const double> inputs) {
520 assert(indeps.size() == inputs.size() &&
"Size mismatch!");
521 for (
size_t i = 0; i < indeps.size(); ++i) {
522 indeps[i] <<= inputs[i];
539 std::span<double> outputs) {
540 assert(deps.size() == outputs.size() &&
"Size mismatch!");
541 for (
size_t i = 0; i < deps.size(); ++i) {
542 deps[i] >>= outputs[i];
568 return std::move(b) + a;
571 return std::move(a) + b;
579 return coval + std::move(a);
586 return -(std::move(b)) + a;
589 return std::move(a) - b;
597 return (-coval) + std::move(a);
605 return std::move(b) * a;
608 return std::move(a) * b;
616 return coval * std::move(a);
625 return std::move(a) / b;
630 return a * (1.0 / coval);
633 return std::move(a) * (1.0 / coval);
639 *
this *= 1.0 / coval;
647 *
this *= 1.0 / std::move(a);
671#ifdef ADOLC_ADVANCED_BRANCHING
700 return (a - b != 0.0);
703 return (a - b == 0.0);
706 return (a - b <= 0.0);
709 return (a - b >= 0.0);
712 return (a - b > 0.0);
715 return (a - b < 0.0);
727 return std::isnormal(a.
value());
753 return std::isfinite(a.
value());
765 return log(a) / ADOLC_MATH_NSP::log(10.0);
768 return log(std::move(a)) / ADOLC_MATH_NSP::log(10.0);
797 if (a.
value() < 0.0) {
799 return 0.5 * (temp - 1.0 / temp);
802 return 0.5 * (1.0 / temp - temp);
806 if (a.value() < 0.0) {
808 return 0.5 * (temp - 1.0 / temp);
811 return 0.5 * (1.0 / temp - temp);
818 return 0.5 * (temp + 1.0 / temp);
821 adouble temp = (a.value() < 0.0) ?
exp(std::move(a)) :
exp(-std::move(a));
822 return 0.5 * (temp + 1.0 / temp);
827 if (a.
value() < 0.0) {
829 return (temp - 1.0) / (temp + 1.0);
832 return (1.0 - temp) / (temp + 1.0);
836 if (a.value() < 0.0) {
838 return (temp - 1.0) / (temp + 1.0);
841 return (1.0 - temp) / (temp + 1.0);
880 return fmin(std::move(a), b);
899 return fmin(std::move(a), b);
902 return fmin(a, std::move(b));
905 return fmin(std::move(a), b);
908 return fmin(coval, a);
911 return fmin(coval, std::move(a));
914 return fmin(a, coval);
917 return fmin(std::move(a), coval);
923 return (-
fmin(-a, -b));
926 return (-
fmin(-std::move(a), -b));
929 return (-
fmin(-a, -std::move(b)));
932 return fmax(std::move(a), b);
935 return (-
fmin(-coval, -a));
938 return (-
fmin(-coval, -std::move(a)));
941 return (-
fmin(-a, -coval));
944 return (-
fmin(-std::move(a), -coval));
952 return fmax(std::move(a), b);
955 return fmax(a, std::move(b));
959 return fmax(std::move(a), b);
962 return fmax(coval, a);
965 return fmax(coval, std::move(a));
968 return fmax(a, coval);
971 return fmax(std::move(a), coval);
987 double coval = std::frexp(a.
value(),
exp);
991 const double coval = std::frexp(a.value(),
exp);
1002 const double &arg1,
const double &arg2) {
1003 res = cond > 0 ? arg1 : arg2;
1009 const double &arg) {
1010 res = cond > 0 ? arg : res;
1016 const double &arg1,
const double &arg2) {
1017 res = cond >= 0 ? arg1 : arg2;
1021 const double &arg) {
1022 res = cond >= 0 ? arg : res;
1043 assert((a.
value() >= 0) &&
"\nADOL-C message: negative basis deactivated\n ");
1044 assert(a.
value() != 0 &&
"\nADOL-C message: zero basis deactivated\n ");
1059 const double pihalf = ADOLC_MATH_NSP::asin(1.0);
1080 const adouble *
const vec_b,
size_t size);
1162#ifdef ADOLC_ADVANCED_BRANCHING
1256 return std::isnormal(p.
value());
1282 return std::isfinite(p.
value());
1339 return fmin(coval, p);
1342 return fmin(p, coval);
1372 return fmax(coval, p);
1375 return fmax(p, coval);
1418 static constexpr bool is_specialized =
true;
1420 static constexpr double min() noexcept {
1421 return std::numeric_limits<double>::min();
1424 static constexpr double max() noexcept {
1425 return std::numeric_limits<double>::max();
1429 return std::numeric_limits<double>::lowest();
1432 static constexpr int digits = std::numeric_limits<double>::digits;
1433 static constexpr int digits10 = std::numeric_limits<double>::digits10;
1434 static constexpr int max_digits10 = std::numeric_limits<double>::max_digits10;
1435 static constexpr bool is_signed = std::numeric_limits<double>::is_signed;
1436 static constexpr bool is_integer = std::numeric_limits<double>::is_integer;
1437 static constexpr bool is_exact = std::numeric_limits<double>::is_exact;
1438 static constexpr int radix = std::numeric_limits<double>::radix;
1441 return std::numeric_limits<double>::epsilon();
1445 return std::numeric_limits<double>::round_error();
1448 static constexpr int min_exponent = std::numeric_limits<double>::min_exponent;
1449 static constexpr int min_exponent10 =
1450 std::numeric_limits<double>::min_exponent10;
1451 static constexpr int max_exponent = std::numeric_limits<double>::max_exponent;
1452 static constexpr int max_exponent10 =
1453 std::numeric_limits<double>::max_exponent10;
1455 static constexpr bool has_infinity =
1456 std::numeric_limits<double>::has_infinity;
1457 static constexpr bool has_quiet_NaN =
1458 std::numeric_limits<double>::has_quiet_NaN;
1459 static constexpr bool has_signaling_NaN =
1460 std::numeric_limits<double>::has_signaling_NaN;
1461 static constexpr float_denorm_style has_denorm =
1462 std::numeric_limits<double>::has_denorm;
1463 static constexpr bool has_denorm_loss =
1464 std::numeric_limits<double>::has_denorm_loss;
1467 return std::numeric_limits<double>::infinity();
1471 return std::numeric_limits<double>::quiet_NaN();
1475 return std::numeric_limits<double>::signaling_NaN();
1479 return std::numeric_limits<double>::denorm_min();
1482 static constexpr bool is_iec559 = std::numeric_limits<double>::is_iec559;
1483 static constexpr bool is_bounded = std::numeric_limits<double>::is_bounded;
1484 static constexpr bool is_modulo = std::numeric_limits<double>::is_modulo;
1486 static constexpr bool traps = std::numeric_limits<double>::traps;
1487 static constexpr bool tinyness_before =
1488 std::numeric_limits<double>::tinyness_before;
1489 static constexpr float_round_style round_style =
1490 std::numeric_limits<double>::round_style;
#define CURRENT_LOCATION
Definition adolcerror.h:26
#define ADOLC_API
Definition adolcexport.h:16
void ADOLC_API adolc_vec_dot(adouble *const dest, const adouble *const src, size_t size)
ADOLC_API bool isfinite(const adouble &a)
This is an overload of std::isfinite for adoubles and not traced on the tape. The value of the adoubl...
Definition adtb_types.h:752
ADOLC_API adouble fmax(const adouble &a, const adouble &b)
Definition adtb_types.h:922
ADOLC_API bool isnormal(const adouble &a)
This is an overload of std::isnormal for adoubles and not traced on the tape. The value of the adoubl...
Definition adtb_types.h:726
ADOLC_API adouble abs(const adouble &a)
Definition adtb_types.h:870
ADOLC_API void operator>>=(std::span< adouble > deps, std::span< double > outputs)
Stores a contiguous sequence of adouble values into passive storage and marks them as dependent varia...
Definition adtb_types.h:538
ADOLC_API adouble max(const adouble &a, const adouble &b)
Definition adtb_types.h:947
ADOLC_API adouble asinh(const adouble &a)
ADOLC_API adouble atan(const adouble &a)
ADOLC_API bool operator>=(const double coval, const adouble &a)
ADOLC_API void condeqassign(adouble &res, const adouble &cond, const adouble &arg1, const adouble &arg2)
ADOLC_API adouble log10(const adouble &a)
Definition adtb_types.h:764
ADOLC_API adouble fabs(const adouble &a)
ADOLC_API adouble operator+(const adouble &a)
ADOLC_API adouble fmin(const adouble &a, const adouble &b)
ADOLC_API adouble pow(const adouble &a, const double exp)
ADOLC_API std::ostream & operator<<(std::ostream &, const adouble &)
ADOLC_API adouble frexp(const adouble &a, int *exp)
Definition adtb_types.h:986
ADOLC_API adouble sqrt(const adouble &a)
ADOLC_API void condassign(adouble &res, const adouble &cond, const adouble &arg1, const adouble &arg2)
ADOLC_API void operator<<=(std::span< adouble > indeps, std::span< const double > inputs)
Assigns passive values to a contiguous sequence of adoubles and marks them as independent variables.
Definition adtb_types.h:518
ADOLC_API adouble operator*(const adouble &a, const adouble &b)
ADOLC_API adouble sin(const adouble &a)
ADOLC_API adouble erfc(const adouble &a)
ADOLC_API adouble tan(const adouble &a)
Definition adtb_types.h:783
ADOLC_API adouble erf(const adouble &a)
ADOLC_API adouble tanh(const adouble &a)
Definition adtb_types.h:826
ADOLC_API std::istream & operator>>(std::istream &, const adouble &)
ADOLC_API adouble exp(const adouble &a)
ADOLC_API adouble atan2(const adouble &a, const adouble &b)
Definition adtb_types.h:1057
ADOLC_API adouble cbrt(const adouble &a)
ADOLC_API adouble ldexp(const adouble &a, const int exp)
Definition adtb_types.h:977
ADOLC_API bool isnan(const adouble &a)
This is an overload of std::isnan for adoubles and not traced on the tape. The value of the adouble o...
Definition adtb_types.h:736
ADOLC_API adouble asin(const adouble &a)
void ADOLC_API adolc_vec_copy(adouble *const dest, const adouble *const src, size_t size)
ADOLC_API bool operator<(const double coval, const adouble &a)
void ADOLC_API adolc_vec_axpy(adouble *const res, const adouble &a, const adouble *const vec_a, const adouble *const vec_b, size_t size)
ADOLC_API adouble atanh(const adouble &a)
ADOLC_API adouble cosh(const adouble &a)
Definition adtb_types.h:816
ADOLC_API adouble floor(const adouble &a)
ADOLC_API adouble operator-(const adouble &a)
ADOLC_API adouble operator/(const adouble &a, const adouble &b)
ADOLC_API bool operator>(const double coval, const adouble &a)
ADOLC_API bool operator==(const double coval, const adouble &a)
ADOLC_API adouble ceil(const adouble &a)
ADOLC_API adouble sinh(const adouble &a)
Definition adtb_types.h:796
ADOLC_API bool operator!=(const adouble &a, const double coval)
ADOLC_API adouble min(const adouble &a, const adouble &b)
Definition adtb_types.h:895
ADOLC_API adouble acosh(const adouble &a)
ADOLC_API adouble acos(const adouble &a)
ADOLC_API double myquad(double x)
ADOLC_API adouble log(const adouble &a)
ADOLC_API adouble cos(const adouble &a)
ADOLC_API bool isinf(const adouble &a)
This is an overload of std::isinf for adoubles and not traced on the tape. The value of the adouble o...
Definition adtb_types.h:744
ADOLC_API bool operator<=(const double coval, const adouble &a)
size_t p_next_loc()
Definition valuetape.h:522
double get_ad_value(size_t loc) const
Definition valuetape.h:534
void set_ad_value(size_t loc, double coval)
Definition valuetape.h:535
void set_pd_value(size_t loc, double coval)
Definition valuetape.h:540
size_t next_loc()
Definition valuetape.h:520
void free_loc(size_t loc) const
Definition valuetape.h:525
double get_pd_value(size_t loc) const
Definition valuetape.h:539
Taped active scalar for reusable forward and reverse differentiation.
Definition adtb_types.h:211
adouble & operator-=(const adouble &a)
adouble & operator=(const adouble &a)
Copy an active value and record the assignment while tracing.
void declareIndependent()
Declares the adouble as an independent variable on the tape.
size_t loc() const
Retrieves the location of the adouble on the tape.
Definition adtb_types.h:332
double value() const
Retrieves the current value stored at the tape location.
Definition adtb_types.h:323
adouble & operator=(const double coval)
Assign a passive value and record the assignment while tracing.
static adouble borrow_location(size_t loc)
Constructs an adouble borrowing an existing tape location.
Definition adtb_types.h:261
void declareDependent()
Declares the adouble as a dependent variable on the tape.
adouble & operator=(adouble &&other) noexcept
Move assignment.
Definition adtb_types.h:301
adouble & operator+=(const adouble &a)
adouble & operator=(const pdouble &p)
Registers the assignment of the pdouble to the adouble.
adouble(adouble &&other) noexcept
Move constructor.
Definition adtb_types.h:253
adouble & operator*=(const adouble &a)
adouble & operator-=(const double coval)
adouble & operator-=(adouble &&a)
adouble & operator>>=(double &out)
Stores the value of adouble in the provided reference and marks the adouble as a dependent variable.
adouble()
Allocate an active-value location on the current tape.
void value(const double coval)
Updates the value stored at the tape location.
Definition adtb_types.h:342
adouble & operator*=(const double coval)
adouble & operator+=(const double coval)
bool is_valid() const
Definition adtb_types.h:273
adouble & operator<<=(const double input)
Registers the assignment of the input value to the adouble and marks the adouble as an independent va...
~adouble()=default
Default destructor.
adouble & operator+=(adouble &&a)
adouble(double coval)
Allocate a location on the current tape and initialize its value.
adouble & operator/=(const double coval)
Definition adtb_types.h:638
size_t release_loc()
Releases ownership of this adouble's location.
Definition adtb_types.h:272
adouble(const adouble &a)
Copy constructor.
Mutable passive parameter stored on a recorded tape.
Definition adtb_types.h:431
pdouble & operator=(pdouble &&other) noexcept
Move assignment.
Definition adtb_types.h:463
pdouble(const double pval)
Allocate a parameter location on the current tape and set its value.
pdouble()=delete
Deleted default constructor.
void value(const double pval)
Updates the value stored at the tape location.
Definition adtb_types.h:502
pdouble & operator=(const pdouble &)=delete
size_t loc() const
Retrieves the location on the tape of the pdouble.
Definition adtb_types.h:490
pdouble(pdouble &&other) noexcept
Move constructor.
Definition adtb_types.h:453
~pdouble()=default
Default destructor.
pdouble(const pdouble &)=delete
Deleted copy constructor and assignment.
double value() const
Retrieves the current value stored at the tape location.
Definition adtb_types.h:496
RAII type for a location in the current tape's value store.
Definition adtb_types.h:57
tape_location(size_t loc, ownership_mode mode=OWNING)
Constructs a tape location from an existing location.
Definition adtb_types.h:135
tape_location(tape_location &&other) noexcept
Transfer the location and its ownership state; invalidate the source.
Definition adtb_types.h:150
~tape_location()
Release an owned active-value location; leave borrowed locations alone.
Definition adtb_types.h:117
ownership_mode
Definition adtb_types.h:107
@ OWNING
Definition adtb_types.h:109
@ INVALID
Definition adtb_types.h:108
@ BORROWED
Definition adtb_types.h:110
tape_location()
Constructs a tape_location with the next available location on the tape.
Definition adtb_types.h:127
size_t loc() const
Retrieves the tape location.
Definition adtb_types.h:182
bool owns_location() const
Returns whether this location owns tape memory.
Definition adtb_types.h:187
tape_location & operator=(tape_location &&other) noexcept
Release the old owned location and transfer the source state.
Definition adtb_types.h:161
bool is_valid() const
Definition adtb_types.h:188
tape_location & operator=(const tape_location &)=delete
Deleted copy assignment operator.
tape_location(const tape_location &)=delete
Deleted copy constructor.
size_t release()
Return the location index and invalidate this token.
Definition adtb_types.h:195
Concept to check if a type is either adouble or pdouble.
Definition adtb_types.h:42
void ADOLC_API fail(ErrorType error, const source_location LocInfo, const FailInfo &failinfo=FailInfo())
Numeric limits for taped active scalars.
Definition adtb_types.h:1417
static constexpr double signaling_NaN() noexcept
Definition adtb_types.h:1474
static constexpr double min() noexcept
Definition adtb_types.h:1420
static constexpr double quiet_NaN() noexcept
Definition adtb_types.h:1470
static constexpr double denorm_min() noexcept
Definition adtb_types.h:1478
static constexpr double epsilon() noexcept
Definition adtb_types.h:1440
static constexpr double lowest() noexcept
Definition adtb_types.h:1428
static constexpr double max() noexcept
Definition adtb_types.h:1424
static constexpr double infinity() noexcept
Definition adtb_types.h:1466
static constexpr double round_error() noexcept
Definition adtb_types.h:1444
ValueTape & currentTape()
Returns a reference to the current ValueTape.
Definition taperegistry.h:113
ADOLC_API ValueTape *& currentTapePtr()
Returns a thread-local reference to the pointer to the current ValueTape.
Definition taperegistry.h:99