source: trunk/test_more/value.cpp @ 3495

Last change on this file since 3495 was 2506, checked in by bradbell, 7 years ago

Change Licenses: CPL-1.0 -> EPL-1.0, GPL-2.0->GPL-3.0

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1/* $Id: value.cpp 2506 2012-10-24 19:36:49Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13/*
14Old Value example now used just for valiadation testing
15*/
16// BEGIN C++
17
18# include <cppad/cppad.hpp>
19
20bool Value(void)
21{       bool ok = true;
22
23        using namespace CppAD;
24
25        // independent variable vector, indices, values, and declaration
26        CPPAD_TESTVECTOR(AD<double>) U(2);
27        size_t s = 0;
28        size_t t = 1;
29        U[s] = 3.;
30        U[t] = 4.;
31        Independent(U);
32
33        // cannot call Value after Independent (tape is recording)
34
35        // dependent variable vector and indices
36        CPPAD_TESTVECTOR(AD<double>) Z(1);
37        size_t x = 0;
38
39        // dependent variable values
40        Z[x] = - U[t];
41
42        // create f: U -> Z and vectors used for derivative calculations
43        ADFun<double> f(U, Z);
44        CPPAD_TESTVECTOR(double) v( f.Domain() );
45        CPPAD_TESTVECTOR(double) w( f.Range() );
46
47        // can call Value after ADFun constructor (tape is no longer recording)
48
49        // check value of s
50        double sValue = Value(U[s]);
51        ok &= ( sValue == 3. );
52
53        // check value of x
54        double xValue = Value(Z[x]);
55        ok &= ( xValue == -4. );
56
57        return ok;
58}
59// END C++
Note: See TracBrowser for help on using the repository browser.