# source:trunk/test_more/abs.cpp@3688

Last change on this file since 3688 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.9 KB
Line
1/* \$Id: abs.cpp 2506 2012-10-24 19:36:49Z bradbell \$ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
4
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.
11-------------------------------------------------------------------------- */
12
13/*
14Test of directional derivative in AD< AD< double > > case.
15*/
16
18
19
20bool abs(void)
21{       // test if CppAD::abs uses if statement during forward computations
22        bool ok = true;
23
28
29        // af(x) = |x|
31        aax[0] = ADDdouble(0.);
33        aay[0] = CppAD::abs(aax[0]);
35
36        // f(x) = |x|
38        ax[0] = ADdouble(0.);
40        ay    = af.Forward(0, ax);
42
43        // compute derivative of af at a positive argument
45        ax[0]  = 1.;
46        ay     = af.Forward(0, ax);
47        adx[0] = 1;
49        ok    &= (ady[0] == 1.);
50
51        // compute derivative of af at a zero argument
52        ax[0]  = 0.;
53        ay     = af.Forward(0, ax);
54        adx[0] = 1;
56        ok    &= (ady[0] == 0.);
57
58        // compute derivative of f at zero argument
59        CPPAD_TESTVECTOR(double) x(1), y(1), dx(1), dy(1);
60        x[0]  = 0.;
61        y     = f.Forward(0, x);
62        dx[0] = 1;
63        dy    = f.Forward(1, dx);
64        ok    &= (dy[0] == 0.);
65
66        // compute derivative of af at a negative argument
67        x[0]  = -1.;
68        y     = f.Forward(0, x);
69        dx[0] = 1;
70        dy    = f.Forward(1, dx);
71        ok    &= (dy[0] == -1.);
72
73        return ok;
74}
Note: See TracBrowser for help on using the repository browser.