source: trunk/test_more/cond_exp_rev.cpp @ 3779

Last change on this file since 3779 was 3666, checked in by bradbell, 5 years ago

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: f81667ec9c0e3a005cf868c042f5d225b49b8a0c
end hash code: 9d68051c35a88aaabc1532f00e74e38eb6befff0

commit 9d68051c35a88aaabc1532f00e74e38eb6befff0
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 09:34:47 2015 -0700

Squashed commit of merge from local cond_exp_rev branch to master.
This implemented the feature change (bug fix) in whats new on 2015-02-28.


commit 7c67a66cf3576c7b4d7917efd7b77a0351ba41b8
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 08:47:14 2015 -0700


Remove trailing white space.


commit 35ff6eed1be671077704f2e705001f6e9f11997f
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 08:45:09 2015 -0700


cond_exp.cpp: change example to match new reverse mode feature.
whats_new_15.omh: user description of change in reverse mode.
cond_exp.cpp: check test to match new reverse mode feature .


commit 4fac1b7e3bd5fd8d6a27812cdb1cef0c975d9a5b
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:35:04 2015 -0700


Stop nan from propagating through unused option in reverse erf operator.
reverse_sweep.hpp: some white space edits.
tanh_op.hpp: remove trailing white space.
cond_exp_rev.cpp: note difference between pow and erf.


commit fb1ace29478101e98e1cef4da5cfbf8b485de73b
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:22:17 2015 -0700


Stop nan from propagating through unused option in reverse tanh operator.
tanh_op.hpp: remove trailing white space.


commit d03663ac2cd5f7d1fc21d2fefa9b9b3a2790c171
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:20:01 2015 -0700


Stop nan from propagating through unused option in reverse tan operator.


commit 079c4f75f447c3cb223ff82893fc86a754d2f982
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:17:14 2015 -0700


sqrt_op.hpp: remove trailing white space.
cond_exp_rev.cpp: check that subtraction does not need action.


commit b2b55bf409173d07085b675cc2bda0808bf63210
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:13:04 2015 -0700


Stop nan from propagating through unused option in reverse sqrt operator.
sinh_op.hpp: remove trailing white space.


commit c83231ce59f0d77cfc2f058a8e9ba785a2216e09
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:09:18 2015 -0700


Stop nan from propagating through unused option in reverse sinh operator.
sinh_op.hpp: remove trailing white space.


commit 596f7ebe6e014bf0c19c6b3b517cf020a972a943
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:06:57 2015 -0700


Stop nan from propagating through unused option in reverse sin operator.


commit 9e161155b55c299c5f9ab1fdb06e332d4cdd6bc4
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 07:04:11 2015 -0700


cond_exp_rev.cpp: test some more operations that need no further action.


commit 394d552933c8033fda66f1e9977e558506cba90f
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:55:37 2015 -0700


Stop nan from propagating through unused option in reverse mulvv operator.
log_op.hpp: remove trailing white space.


commit 6ed9754950e49df4246c0937d763686e07f0a14c
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:48:08 2015 -0700


Stop nan from propagating through unused option in reverse log operator.


commit 43791ad41011aa56865135418f1620c6ea5a00c6
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:41:31 2015 -0700


exp_op.hpp: remove traling white space.
cond_exp_rev.cpp: check reverse divvp operator doesn't propagate nans.


commit f2ba8c592073c0318367440fe22f491945f7af8a
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:35:42 2015 -0700


Stop nan from propagating through unused option in reverse exp operator.


commit 5a0ee67c3869465bdd39cddbe26c966fc09f8113
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:30:25 2015 -0700


cond_exp_rev.cpp: white space edit and skip some cases for now.


commit 5cb70435dfb14e7f67728003395f68f6f6201798
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:15:32 2015 -0700


Stop nan from propagating through unused option in reverse divpv operator.


commit dcd072898764ffac2434950c77037475788ffe79
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:11:01 2015 -0700


Stop nan from propagating through unused option in reverse divvv operator.
cosh_op.hpp: remove trailing white space.


commit eb43bfc9e9f0fc3bb28c6f6d686473ac6d1114c7
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:07:06 2015 -0700


Stop nan from propagating through unused option in reverse cosh operator.
cos_op.hpp: remove trailing white space.


commit 21a1adb8b3acad7cccf470a62248aeb28de34be3
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 06:03:23 2015 -0700


Stop nan from propagating through unused option in reverse cos operator.
atan_op.hpp: remove trailing white space.


commit 8b7f2ddaaad129bdabdf2df213f3f3161d25d073
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 05:57:17 2015 -0700


Stop nan from propagating through unused option in reverse atan operator.
asin_op.hpp: remove trailing white space.


commit b23cc3a860f6a5818f544fc2b601ccad3900b709
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 05:52:53 2015 -0700


Stop nan from propagating through unused option in reverse asin operator.
acos_op.hpp: fix spelling in comment.


commit 07b5395ba34def704deb56bbc834dfba5e616014
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 05:49:15 2015 -0700


acos_op.hpp: remove traliing white space.
cond_exp_rev.cpp: check add operators.


commit 7391e9b74f8350d5a210a21cd0fe16577a16824a
Author: Brad Bell <bradbell@…>
Date: Sat Feb 28 05:42:50 2015 -0700


Stop nan from propagating through unused option in reverse acos operator.

commit 9619d407996da03fd287cd24fa9f8604bcd92ef5
Author: Brad Bell <bradbell@…>
Date: Fri Feb 27 22:14:32 2015 -0700

Remove trailing white space.

commit 70a04a4c19a02624f5defb7ec0ce213d58d6e0cd
Author: Brad Bell <bradbell@…>
Date: Fri Feb 27 22:13:33 2015 -0700

Add a test for reverse mode of conditional expressions.
This will test that nans and infinities do not propagate though the
conditional case that is not used.


reverse_sweep.hpp: Fix alphabetical order of operators.

commit 957bc6090d454642d72b7d47d591a6f9f6b74f82
Author: Brad Bell <bradbell@…>
Date: Fri Feb 27 06:34:49 2015 -0700

template.sh: remove trailing white space.

commit f3c75db95aa06ab0e0f48872ed3e6518e61f3dec
Author: Brad Bell <bradbell@…>
Date: Fri Feb 27 06:23:24 2015 -0700

Split cond_exp.sh into cond_exp_1.sh, cond_exp_2.sh because they have very
different causes.


template.sh: imporve message at end.

commit bee51f2cf231a714f7736b09f39bc5e366d04e2c
Author: Brad Bell <bradbell@…>
Date: Wed Feb 25 22:58:05 2015 -0700

cond_exp.sh: Better names for AD variables.

commit 82229bcfc244540a9bb5e679296c0b9e5846871e
Author: Brad Bell <bradbell@…>
Date: Wed Feb 25 22:02:18 2015 -0700

push_git2svn.py: remove trailing white space.

commit 69c85cf7842b344b046ed5325897b2748485358e
Author: Brad Bell <bradbell@…>
Date: Wed Feb 25 22:01:06 2015 -0700

push_git2svn.py: Handle trailing white space deleted and directory created.

File size: 3.5 KB
Line 
1// $Id$
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 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// Test that reverse mode handles conditional expressions properly
14// in that infinity and nans do not propagate thouh un-used case.
15
16# include <cppad/cppad.hpp>
17
18bool cond_exp_rev(void)
19{       bool ok = true;
20        using CppAD::vector;
21        using CppAD::AD;
22
23        AD<double> anan  = std::numeric_limits<double>::quiet_NaN();
24        AD<double> azero = 0.0;
25
26
27        size_t n = 2;
28        vector< AD<double> > ax(n), ay;
29        ax[0] = 1.0;
30        ax[1] = anan;
31        Independent(ax);
32
33        // AbsOp
34        ay.push_back( CondExpGt(ax[0], azero, ax[0], abs(ax[1]) ));
35
36        // AcosOp
37        ay.push_back( CondExpGt(ax[0], azero, ax[0], acos(ax[1]) ));
38
39        // AddvvOp
40        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[0] + ax[1] ));
41
42        // AddpvOp
43        ay.push_back( CondExpGt(ax[0], azero, ax[0], 1.0 + ax[1] ));
44
45        // AsinOp
46        ay.push_back( CondExpGt(ax[0], azero, ax[0], asin(ax[1]) ));
47
48        // AtanOp
49        ay.push_back( CondExpGt(ax[0], azero, ax[0], atan(ax[1]) ));
50
51        // CosOp
52        ay.push_back( CondExpGt(ax[0], azero, ax[0], cos(ax[1]) ));
53
54        // CoshOp
55        ay.push_back( CondExpGt(ax[0], azero, ax[0], cosh(ax[1]) ));
56
57        // DivvvOp
58        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[0] / ax[1] ));
59
60        // DivpvOp
61        ay.push_back( CondExpGt(ax[0], azero, ax[0], 1.0 / ax[1] ));
62
63        // DivvpOp
64        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[1] / 2.0 ));
65
66        // ErfOp
67        ay.push_back( CondExpGt(ax[0], azero, ax[0], erf(ax[1]) ));
68
69        // ExpOp
70        ay.push_back( CondExpGt(ax[0], azero, ax[0], exp(ax[1]) ));
71
72        // LogOp
73        ay.push_back( CondExpGt(ax[0], azero, ax[0], log(ax[1]) ));
74
75        // MulvvOp
76        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[0] * ax[1] ));
77
78        // MulpvOp
79        ay.push_back( CondExpGt(ax[0], azero, ax[0], 2.0 * ax[1] ));
80
81        // PowvvOP
82        // uses check in log, mul, and exp
83        ay.push_back( CondExpGt(ax[0], azero, ax[0], pow(ax[1], ax[1]) ));
84
85        // PowvpOP
86        // uses check in log, mul, and exp
87        ay.push_back( CondExpGt(ax[0], azero, ax[0], pow(ax[1], 2.0) ));
88
89        // PowpvOP
90        // uses check in log, mul, and exp
91        ay.push_back( CondExpGt(ax[0], azero, ax[0], pow(2.0, ax[1]) ));
92
93        // SignOp
94        ay.push_back( CondExpGt(ax[0], azero, ax[0], sign(ax[1]) ));
95
96        // SinOp
97        ay.push_back( CondExpGt(ax[0], azero, ax[0], sin(ax[1]) ));
98
99        // SinhOp
100        ay.push_back( CondExpGt(ax[0], azero, ax[0], sinh(ax[1]) ));
101
102        // SqrtOp
103        ay.push_back( CondExpGt(ax[0], azero, ax[0], sqrt(ax[1]) ));
104
105        // SubvvOp
106        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[0] - ax[1] ));
107
108        // SubpvOp
109        ay.push_back( CondExpGt(ax[0], azero, ax[0], 1.0 - ax[1] ));
110
111        // SubvpOp
112        ay.push_back( CondExpGt(ax[0], azero, ax[0], ax[1] - 1.0 ));
113
114        // TanOp
115        ay.push_back( CondExpGt(ax[0], azero, ax[0], tan(ax[1]) ));
116
117        // TanhOp
118        ay.push_back( CondExpGt(ax[0], azero, ax[0], tanh(ax[1]) ));
119
120        // create f : x -> y
121        size_t m = ay.size();
122        CppAD::ADFun<double> f(ax, ay);
123
124        // weighting vector and reverse mode derivative
125        vector<double> w(m), dw(n);
126        for(size_t i = 0; i < m; i++)
127                w[i] = 0.0;
128
129        // check DivvOp
130        for(size_t i = 0; i < m; i++)
131        {       w[i] = 1.0;
132                dw = f.Reverse(1, w);
133                ok &= dw[0] == 1.0;
134                ok &= dw[1] == 0.0;
135                w[i] = 0.0;
136        }
137
138        return ok;
139}
Note: See TracBrowser for help on using the repository browser.