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

Last change on this file since 2354 was 2240, checked in by bradbell, 8 years ago
2. Define derivative of abs as sign function.

check_op_code.sh: porper alphabetic order drops Op from SinOp? and SinhOp?...
abs.cpp: change example to new derivative specification.

• Property svn:keywords set to `Id`
File size: 1.9 KB
Line
1/* \$Id: abs.cpp 2240 2011-12-31 05:33:55Z bradbell \$ */
2/* --------------------------------------------------------------------------
4
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.
11-------------------------------------------------------------------------- */
12
13/*
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|
35
36        // f(x) = |x|
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);
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);
56        ok    &= (ady[0] == 0.);
57
58        // compute derivative of f at zero argument
59        CPPAD_TEST_VECTOR<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.