@(@\newcommand{\W}[1]{ \; #1 \; }
\newcommand{\R}[1]{ {\rm #1} }
\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }
\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }
\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }
\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@
This is cppad-20221105 documentation. Here is a link to its
current documentation
.
AD Boolean Functions: Example and Test
# include <cppad/cppad.hpp>
# include <complex>
// define abbreviation for double precision complextypedef std::complex<double> Complex;
namespace {
// a unary bool function with Complex argumentstatic bool IsReal(const Complex &x)
{ return x.imag() == 0.; }
// a binary bool function with Complex argumentsstatic bool AbsGeq(const Complex &x, const Complex &y)
{ double axsq = x.real() * x.real() + x.imag() * x.imag();
double aysq = y.real() * y.real() + y.imag() * y.imag();
return axsq >= aysq;
}
// Create version of IsReal with AD<Complex> argument// inside of namespace and outside of any other function.CPPAD_BOOL_UNARY(Complex, IsReal)
// Create version of AbsGeq with AD<Complex> arguments// inside of namespace and outside of any other function.CPPAD_BOOL_BINARY(Complex, AbsGeq)
}
bool BoolFun(void)
{ bool ok = true;
CppAD::AD<Complex> x = Complex(1., 0.);
CppAD::AD<Complex> y = Complex(1., 1.);
ok &= IsReal(x);
ok &= ! AbsGeq(x, y);
return ok;
}