FReal direct
Overview
template <class Scalar, std::size_t N = 1>
struct FRealDirect : public RealDirect<FReal<Scalar, N>, FRealDirect<Scalar, N>> The class FRealDirect has the same interface as FReal, but does not use expression templates for the operations: each operation returns an FRealDirect straight away. It is a drop-in replacement for FReal (see below), for existing code bases which may have issues integrating with expression templates; it also makes debugging easier.
Compatibility with FReal
FRealDirect is designed as a drop-in replacement for FReal 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 FRealDirect<FRealDirect<double>>), XAD provides the same functionality as for FReal:
- 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 toFRealDirect(for example a type with a conversion operator, like QuantLib'sNull<Real>). As forFReal, higher-order types do not mix in arithmetic with their inner active type. Compound assignments and++/--return a reference toFRealDirect. - Conversions: implicit conversion from built-in arithmetic types, no implicit conversion to
doubleorint(as forFReal), explicit conversion tobooland (withXAD_ALLOW_INT_CONVERSION, the default) explicit conversion to integer types viastatic_cast.FRealDirectis not constructible from unrelated types, so thatstd::is_constructibleandstd::is_convertiblegive the same answers as forFReal. - Mathematical functions: all functions listed in Mathematical Operations, in the
xadnamespace and (after includingXAD/StdCompatibility.hpp) in thestdnamespace, with the same mixed-argument overloads asFReal. All of them propagate derivatives. stdcompatibility (XAD/StdCompatibility.hpp):std::numeric_limits(all members, returning the underlying passive type as forFReal),std::hash,std::to_string, and the type traitsstd::is_floating_point,std::is_arithmetic,std::is_signed,std::is_fundamental,std::is_scalar,std::is_compoundandstd::is_trivially_copyable(including the C++17_vvariable templates).- Complex numbers (
XAD/Complex.hpp):std::complex<FRealDirect<T>>with the same operators and functions asstd::complex<FReal<T>>. - Stream operators
<<and>>. - Mode interface:
fwdd<T>and the higher-order mode classes useFRealDirectas the active type. Jacobian and Hessian helpers are available forFRealDirect<T>andFRealDirect<FRealDirect<T>>.
See also
FReal, 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.