source: trunk/test_more/base_adolc.cpp @ 2354

Last change on this file since 2354 was 1613, checked in by bradbell, 10 years ago

trunk: Update makefile.in and fixes for g++ 4.4.2.

build.sh: move checking doxygen version into check_doxygen.sh.
ad_in_c.cpp: reference printf throught standard namespace.
optimize.cpp: add missing doxygen description of structure.
csum_op.cpp: remove mistake \ in doxygen documentation.

Special changes to avoid warnings with g++ 4.4.2.


mul_level_adolc.cpp, ode_taylor.cpp, ode_taylor_adolc.cpp, base_adolc.cpp,

Transfer changes from makefile.am to makefile.in in directories:


example, test_more, introduciton/exp_apx get_started, ./,
speed/adolc, speed/cppad, speed/sacado, speed/profile, speed/fadbad,
speed/double

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1/* $Id: base_adolc.cpp 1613 2009-12-23 06:33:11Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-09 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Common 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# include <adolc/adouble.h>
13# include <adolc/taping.h>
14# include <adolc/interfaces.h>
15
16// adouble definitions not in Adolc distribution and
17// required in order to use CppAD::AD<adouble>
18# include "../example/base_adolc.hpp"
19
20# include <cppad/cppad.hpp>
21
22bool base_adolc(void) 
23{       bool ok = true;                   // initialize test result
24
25        typedef adouble             ADdouble;  // for first level of taping
26        typedef CppAD::AD<ADdouble> ADDdouble; // for second level of taping
27        size_t n = 4;                          // number independent variables
28
29        CPPAD_TEST_VECTOR<ADdouble>   a_x(n);
30        CPPAD_TEST_VECTOR<ADDdouble> aa_x(n);
31
32        // value of the independent variables
33        int tag = 0;                         // Adolc setup
34        int keep = 1;
35        trace_on(tag, keep);
36        size_t j;
37        for(j = 0; j < n; j++)
38                a_x[j] <<= double(n - j);  // a_x is independent for ADdouble
39        for(j = 0; j < n; j++)
40                aa_x[j] = a_x[j];          // track how aa_x depends on a_x
41        CppAD::Independent(aa_x);          // aa_x is independent for ADDdouble
42         
43
44        // compute function
45        size_t m = 5;
46        CPPAD_TEST_VECTOR<ADDdouble> aa_f(m);    // dependent variables
47
48        // different cases of conditional expressions
49        aa_f[0] = CondExpLt(aa_x[0], aa_x[1], aa_x[2], aa_x[3]);
50        aa_f[1] = CondExpLe(aa_x[0], aa_x[1], aa_x[2], aa_x[3]);
51        aa_f[2] = CondExpEq(aa_x[0], aa_x[1], aa_x[2], aa_x[3]);
52        aa_f[3] = CondExpGe(aa_x[0], aa_x[1], aa_x[2], aa_x[3]);
53        aa_f[4] = CondExpGt(aa_x[0], aa_x[1], aa_x[2], aa_x[3]);
54
55        // declare inner function (just to stop inner taping)
56        CppAD::ADFun<ADdouble> a_F(aa_x, aa_f);
57
58        // set values for outer function same as inner function
59        // (corresponding to the tape of adobule operations)
60        double f_j;
61        for(j = 0; j < m; j++)
62                Value(aa_f[j]) >>= f_j;
63        trace_off();
64
65        // arrays for Adolc zos_forward
66        double *x = 0, *y = 0;
67        x = CPPAD_TRACK_NEW_VEC(n, x);
68        y = CPPAD_TRACK_NEW_VEC(m, y);
69
70        // switch order of arguments from when taping was done
71        for(j = 0; j < n; j++)
72                x[j] = double(j);
73        zos_forward(tag, int(m), int(n), keep, x, y);
74        // CondExpLt(0, 1, 2, 3)
75        ok &= (y[0] == double(2));
76        // CondExpLe(0, 1, 2, 3)
77        ok &= (y[1] == double(2));
78        // CondExpEq(0, 1, 2, 3)
79        ok &= (y[2] == double(3));
80        // CondExpGe(0, 1, 2, 3)
81        ok &= (y[3] == double(3));
82        // CondExpGt(0, 1, 2, 3)
83        ok &= (y[4] == double(3));
84
85        // set left = right and true < false
86        x[0] = x[1] = 1.;
87        x[2] = 2.;
88        x[3] = 3.;
89        zos_forward(tag, int(m), int(n), keep, x, y);
90        // CondExpLt(1, 1, 2, 3)
91        ok &= (y[0] == double(3));
92        // CondExpLe(1, 1, 2, 3)
93        ok &= (y[1] == double(2));
94        // CondExpEq(1, 1, 2, 3)
95        ok &= (y[2] == double(2));
96        // CondExpGe(1, 1, 2, 3)
97        ok &= (y[3] == double(2));
98        // CondExpGt(1, 1, 2, 3)
99        ok &= (y[4] == double(3));
100
101        CPPAD_TRACK_DEL_VEC(x);
102        CPPAD_TRACK_DEL_VEC(y);
103        return ok;
104}
105// END PROGRAM
Note: See TracBrowser for help on using the repository browser.