source: trunk/test_more/vec_ad_par.cpp @ 3008

Last change on this file since 3008 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.8 KB
Line 
1/* $Id: vec_ad_par.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/*
14Test the use of the parameters in VecAD element assignments
15*/
16
17# include <cppad/cppad.hpp>
18
19typedef CppAD::AD<double>      ADdouble;
20typedef CppAD::AD< ADdouble > ADDdouble;
21
22bool VecADPar(void)
23{       
24        using namespace CppAD;
25
26        bool ok = true;
27
28        CPPAD_TESTVECTOR( ADdouble ) x(2);
29        x[0] = 0;
30        x[1] = 0;
31        Independent(x);
32
33        CPPAD_TESTVECTOR( ADDdouble ) y(1);
34        y[0] = 1;
35        Independent(y);
36
37        VecAD< ADdouble > v(2);
38        ADDdouble zero(0);
39        ADDdouble one(1);
40        v[zero] = x[0]; // these two parameter values are equal,
41        v[one]  = x[1]; // but they are not identically equal
42
43        CPPAD_TESTVECTOR( ADDdouble ) z(1);
44        z[0] = v[zero] + v[one];
45
46        // f(y) = x[0] + x[1]
47        ADFun< ADdouble > f(y, z);
48        CPPAD_TESTVECTOR( ADdouble ) a( f.Domain() );
49        CPPAD_TESTVECTOR( ADdouble ) b( f.Range() );
50
51        // fy = f(y) = x[0] + x[1]
52        a[0]  = 0.;
53        b     = f.Forward(0, a);
54
55        // check value of f
56        ok &= b[0] == (x[0] + x[1]);
57
58        // g(x) = x[0] + x[1];
59        ADFun<double> g(x, b);
60        CPPAD_TESTVECTOR( double ) c( g.Domain() );
61        CPPAD_TESTVECTOR( double ) d( g.Range() );
62
63        // d = g(1, 2)
64        c[0] = 1.;   // these tow values are not equal and correspond
65        c[1] = 2.;   // to replacements for the equal parameter values above
66        d = g.Forward(0, c);
67
68        // check function value
69        ok &= (d[0] == c[0] + c[1]);
70
71        return ok;
72}
Note: See TracBrowser for help on using the repository browser.