AReal direct
Overview
template <class Scalar, std::size_t N=1>
struct ARealDirect : public RealDirect<AReal<Scalar, N>, ARealDirect<Scalar, N>> The class ARealDirect has the same interface as AReal, but does not use expression templates for the operations: each operation returns an ARealDirect straight away. It is a drop-in replacement for AReal (see below), for existing code bases which may have issues with expression templates; it also makes debugging easier.
Compatibility with AReal
ARealDirect is designed as a drop-in replacement for AReal in generic code, for example large numerical libraries that are templated on (or typedef) their floating point type. For first-order and higher-order direct mode types (such as ARealDirect<FRealDirect<double>>), XAD provides the same functionality as for AReal:
- Arithmetic and comparisons with the same type, with any built-in arithmetic type (including integer literals, e.g.
x < 0or2 * x), with XAD expressions, and with types that implicitly convert toARealDirect(for example a type with a conversion operator, like QuantLib'sNull<Real>). As forAReal, higher-order types do not mix in arithmetic with their inner active type. Compound assignments and++/--return a reference toARealDirect. - Conversions: implicit conversion from built-in arithmetic types, no implicit conversion to
doubleorint(as forAReal), explicit conversion tobooland (withXAD_ALLOW_INT_CONVERSION, the default) explicit conversion to integer types viastatic_cast.ARealDirectis not constructible from unrelated types, so thatstd::is_constructibleandstd::is_convertiblegive the same answers as forAReal. - Mathematical functions: all functions listed in Mathematical Operations, in the
xadnamespace and (after includingXAD/StdCompatibility.hpp) in thestdnamespace, with the same mixed-argument overloads asAReal. All of them propagate derivatives. stdcompatibility (XAD/StdCompatibility.hpp):std::numeric_limits(all members, returning the underlying passive type as forAReal),std::hash,std::to_string, and the type traitsstd::is_floating_point,std::is_arithmetic,std::is_signed,std::is_fundamental,std::is_scalarandstd::is_compound(including the C++17_vvariable templates).- Complex numbers (
XAD/Complex.hpp):std::complex<ARealDirect<T>>with the same operators and functions asstd::complex<AReal<T>>. - Stream operators
<<and>>. - Mode interface:
adjd<T>and the higher-order mode classes useARealDirectas the active type, and the Tape registration functions (registerInput,registerOutput,registerInputs,registerOutputs) acceptARealDirectvariables andstd::complex<ARealDirect<T>>directly. Jacobian and Hessian helpers are available forARealDirect<T>andARealDirect<FRealDirect<T>>.
See also
AReal, Tape, Global Functions, AD Mode Interface, Mathematical Operations
Questions or issues: GitHub Discussions · issues. Would you rather we AAD-enabled your code? Get a free speed-up estimate.