1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// ----------------------------------------------------------------------------
/*
Old Value example now used just for valiadation testing
*/
// BEGIN C++
# include <cppad/cppad.hpp>
bool Value(void)
{ bool ok = true;
using namespace CppAD;
// independent variable vector, indices, values, and declaration
CPPAD_TESTVECTOR(AD<double>) U(2);
size_t s = 0;
size_t t = 1;
U[s] = 3.;
U[t] = 4.;
Independent(U);
// cannot call Value after Independent (tape is recording)
// dependent variable vector and indices
CPPAD_TESTVECTOR(AD<double>) Z(1);
size_t x = 0;
// dependent variable values
Z[x] = - U[t];
// create f: U -> Z and vectors used for derivative calculations
ADFun<double> f(U, Z);
CPPAD_TESTVECTOR(double) v( f.Domain() );
CPPAD_TESTVECTOR(double) w( f.Range() );
// can call Value after ADFun constructor (tape is no longer recording)
// check value of s
double sValue = Value(U[s]);
ok &= ( sValue == 3. );
// check value of x
double xValue = Value(Z[x]);
ok &= ( xValue == -4. );
return ok;
}
// END C++
|