Complex numbers
Overview
XAD implements specialisations of std::complex for the XAD active data types AReal and FReal, and their direct mode counterparts ARealDirect and FRealDirect. They are provided in the header XAD/Complex.hpp, along with all the mathematical operations defined in the standard. This header is included by XAD/XAD.hpp.
std::complex Specialisations
Both std::complex<AReal<T>> and std::complex<FReal<T>> are provided specialisations for the standard complex type (in std namespace), for adjoint and forward modes respectively.
Member Functions
All standard complex member functions are implemented.
Below are the non-standard additions and changes of the interface only, using the placeholder XReal<T> as a placeholder inner type, which can be FReal<T> or AReal<T>.
real
XReal<T>& complex::real() returns a reference rather than a copy of the real part, to allow for easy access and adjusting of derivatives using derivative(). This applies to both the modifiable and the const versions.
imag
Returns a reference rather than a copy, for both the modifiable and the const versions.
setDerivative
void complex::setDerivative(const T& real_derivative, const T& imag_derivative = T()) sets the derivatives (either or ) for both the real and imaginary parts.
setAdjoint
void complex::setAdjoint(const T& real_derivative, const T& imag_derivative = T()) is an alias for setDerivative
getDerivative
std::complex<T> getDerivative() const gets the derivatives (either or ) for both the real and imaginary parts, represented as a complex of the underlying (double) type.
getAdjoint
std::complex<T> getAdjoint() const is an alias for getDerivative
Non-Member Functions
derivative
template <typename T>
std::complex<T> derivative(const std::complex<XReal<T> >& z) Returns the adjoints of the z variable, represented as a complex number of the underlying double type.
Note that since the return type is not a reference, setting derivatives should be done by using the member functions setDerivative or using the real and imag member functions instead.
value
template <typename T>
std::complex<T> value(const std::complex<XReal<T> >& z) Returns the value of the z variable (underlying double type), represented as a complex number.
real
template <typename T>
XReal<T>& real(std::complex<XReal<T> >& z) Access to the real part by reference.
imag
template <typename T>
XReal<T>& imag(std::complex<XReal<T> >& z) Access to the imaginary part by reference.
Math Operations
All arithmetic operators and mathematical functions in the C++11 standard have been specialised with the XAD complex data types as well. This also includes the stream read and write operations.
Questions or issues: GitHub Discussions · issues. Would you rather we AAD-enabled your code? Get a free speed-up estimate.