Prev Next ad_assign.cpp Headings

@(@\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}} }@)@
AD Assignment: Example and Test

# include <cppad/cppad.hpp>

bool ad_assign(void)
{     bool ok = true;   // initialize test result flag
     using CppAD::AD;  // so can use AD in place of CppAD::AD

     // assignment to base value
     AD<double> a;
     a = 1.;
     ok &= a == 1.;

     // assignment to a value that converts to the base type
     a = 2;
     ok &= a == 2.;

     // assignment to an AD<Base>
     AD<double> b(3.);
     a = b;
     ok &= a == 3.;

     // assignment to an VecAD<Base> element
     CppAD::VecAD<double> v(1);
     v[0] = 4.;
     a = v[0];
     ok &= a == 4.;

     return ok;
}

Input File: example/general/ad_assign.cpp