Complex¶
Overview¶
XAD implements specialisations of std::complex for the XAD active data types AReal and FReal. They are are provided in the header XAD/Complex.hpp, along with all the mathematical operations defined in the standard.
Note that the complex header is not automatically included with XAD/XAD.hpp. Users must include it as needed.
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 modifyable and the const versions.
imag¶
Returns a reference rather than a copy, for both the modifyable and the const versions.
setDerivative¶
void complex::setDerivative(const T& real_derivative, const T& imag_derivative = T()) sets the derivatives (either \(\dot{x}\) or \(\bar{x}\)) 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 \(\dot{x}\) or \(\bar{x}\) 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
None-Member Functions¶
derivative¶
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¶
Returns the value of the z variable (underlying double type), represented as a complex number.
real¶
Access to the real part by reference.
imag¶
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.