source: trunk/cppad/example/base_adolc.hpp @ 3680

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

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 071875a4beba3363e5fa9752426aec4762cd1caa
end hash code: 0bef506513a519e1073c6279d5c4cba9e5c3b180

commit 0bef506513a519e1073c6279d5c4cba9e5c3b180
Author: Brad Bell <bradbell@…>
Date: Thu May 7 12:14:32 2015 -0700

Add the acosh function (as an atomic operation when defined by compiler).

commit b3264fa17b2f65b65800423a0e243c9c3ccfe06a
Author: Brad Bell <bradbell@…>
Date: Wed May 6 20:25:38 2015 -0700

CMakeLists.txt: Change so test only check for compliation.

commit dcbac4d4f20cc383f2bd9edb02036659df40b791
Author: Brad Bell <bradbell@…>
Date: Wed May 6 15:06:28 2015 -0700

asinh.cpp: check higher orders, relax accuracy on test.

commit 5f8881993fedd18cccc3c74831133a8f8a9d17b0
Author: Brad Bell <bradbell@…>
Date: Wed May 6 14:36:18 2015 -0700

Change Acos to acos.
acos.cpp: remove trailing white space.

commit e828fa1f7c4c3848c727f14b1b7a8030071ee705
Author: Brad Bell <bradbell@…>
Date: Wed May 6 12:07:35 2015 -0700

Change Acos to acos.
acos.cpp: remove redundant index commands, remove trailing with space.

commit 3d16e5b9fe1bdafa4ad01d1d466bb72b792650fa
Author: Brad Bell <bradbell@…>
Date: Wed May 6 11:30:49 2015 -0700

op_code.hpp: Minor edits to AcosOp? commnets.

commit 58beaaad149b4ac29fae44589d7f8900bf8f4c40
Author: Brad Bell <bradbell@…>
Date: Wed May 6 10:51:43 2015 -0700

for_jac_sweep.hpp: Add missing AsinhOp? case.

commit 623c134870c522ae5e80bcf0f89d230902594c80
Author: Brad Bell <bradbell@…>
Date: Wed May 6 10:27:39 2015 -0700

Fix comment about AsinhOp? operator.

commit 226b14f6f4810f5abf1ca247aae541963efaf4d6
Author: Brad Bell <bradbell@…>
Date: Wed May 6 10:14:08 2015 -0700

Add derivative of F to make order zero case clearer.
acos_reverse.omh: Fix some sign errors.
asin_reverse.omh: Fix typo.
acos_forward.omh: Simplify by distributing minus sign.

commit 4682f4ee73e33b600b180086576e986f636a24dc
Author: Brad Bell <bradbell@…>
Date: Wed May 6 08:15:50 2015 -0700

acos_forward.omh: fix sign that depends on acos versus acosh.

commit 906ae10adf019ddda7f57dd165aab08fc55289c4
Author: Brad Bell <bradbell@…>
Date: Wed May 6 07:09:47 2015 -0700

  1. Fix inclusion of some temporary files in package (e.g., git_commit.sh).
  2. Simplify and improve using git ls-files and ls bin/check_*.
  3. Remove trailing white space.

commit 5096f4706a547bd76caa3766aa2c62802ef7f0bf
Author: Brad Bell <bradbell@…>
Date: Wed May 6 06:41:20 2015 -0700

Combine base type documentation for erf, asinh
(will add more functions to this list list).

commit b3535db5ad95bee90672abcaa686032d23bce2fc
Author: Brad Bell <bradbell@…>
Date: Tue May 5 18:01:11 2015 -0700

  1. Change Arc Cosine/Sine? to Inverse Cosine/Sine?.
  2. Change arcsin-> asin and arccos->acos.
  3. Remove index commands that are duplicates of words in titles.


acos_reverse.omh: Add acosh case to this page.

  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1/* $Id: base_adolc.hpp 3680 2015-05-07 19:17:37Z bradbell $ */
2# ifndef CPPAD_BASE_ADOLC_INCLUDED
3# define CPPAD_BASE_ADOLC_INCLUDED
4/* --------------------------------------------------------------------------
5CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
6
7CppAD is distributed under multiple licenses. This distribution is under
8the terms of the
9                    Eclipse Public License Version 1.0.
10
11A copy of this license is included in the COPYING file of this distribution.
12Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13-------------------------------------------------------------------------- */
14/*
15$begin base_adolc.hpp$$
16$spell
17        acosh
18        asinh
19        erf
20        ifndef
21        define
22        endif
23        Rel
24        codassign
25        eps
26        std
27        abs_geq
28        fabs
29        cppad.hpp
30        undef
31        Lt
32        Le
33        Eq
34        Ge
35        Gt
36        namespace
37        cassert
38        condassign
39        hpp
40        bool
41        const
42        Adolc
43        adouble
44        CondExpOp
45        inline
46        enum
47        CppAD
48        pow
49        acos
50        asin
51        atan
52        cos
53        cosh
54        exp
55        sqrt
56$$
57
58$index Adolc, adouble as Base$$
59$index Base, Adolc's adouble$$
60$index adouble, as Base$$
61
62$section Enable use of AD<Base> where Base is Adolc's adouble Type$$
63
64$head Syntax$$
65$codei%# include <cppad/example/base_adolc.hpp>
66%$$
67$children%
68        example/mul_level_adolc.cpp
69%$$
70
71$head Example$$
72The file $cref mul_level_adolc.cpp$$ contains an example use of
73Adolc's $code adouble$$ type for a CppAD $icode Base$$ type.
74It returns true if it succeeds and false otherwise.
75The file $cref mul_level_adolc_ode.cpp$$ contains a more realistic
76(and complex) example.
77
78$head Include Files$$
79This file $code base_adolc.hpp$$ requires $code adouble$$ to be defined.
80In addition, it is included before $code <cppad/cppad.hpp>$$,
81but it needs to include parts of CppAD that are used by this file.
82This is done with the following include commands:
83$codep */
84# include <adolc/adolc.h>
85# include <cppad/base_require.hpp>
86/* $$
87
88$head CondExpOp$$
89The type $code adouble$$ supports a conditional assignment function
90with the syntax
91$codei%
92        condassign(%a%, %b%, %c%, %d%)
93%$$
94which evaluates to
95$codei%
96        %a% = (%b% > 0) ? %c% : %d%;
97%$$
98This enables one to include conditionals in the recording of
99$code adouble$$ operations and later evaluation for different
100values of the independent variables
101(in the same spirit as the CppAD $cref CondExp$$ function).
102$codep */
103namespace CppAD {
104        inline adouble CondExpOp(
105                enum  CppAD::CompareOp     cop ,
106                const adouble            &left ,
107                const adouble           &right ,
108                const adouble        &trueCase ,
109                const adouble       &falseCase )
110        {       adouble result;
111                switch( cop )
112                {
113                        case CompareLt: // left < right
114                        condassign(result, right - left, trueCase, falseCase);
115                        break;
116
117                        case CompareLe: // left <= right
118                        condassign(result, left - right, falseCase, trueCase);
119                        break;
120
121                        case CompareEq: // left == right
122                        condassign(result, left - right, falseCase, trueCase);
123                        condassign(result, right - left, falseCase, result);
124                        break;
125
126                        case CompareGe: // left >= right
127                        condassign(result, right - left, falseCase, trueCase);
128                        break;
129
130                        case CompareGt: // left > right
131                        condassign(result, left - right, trueCase, falseCase);
132                        break;
133                        default:
134                        CppAD::ErrorHandler::Call(
135                                true     , __LINE__ , __FILE__ ,
136                                "CppAD::CondExp",
137                                "Error: for unknown reason."
138                        );
139                        result = trueCase;
140                }
141                return result;
142        }
143}
144/* $$
145
146$head EqualOpSeq$$
147The Adolc user interface does not specify a way to determine if
148two $code adouble$$ variables correspond to the same operations sequence.
149Make $code EqualOpSeq$$ an error if it gets used:
150$codep */
151namespace CppAD {
152        inline bool EqualOpSeq(const adouble &x, const adouble &y)
153        {       CppAD::ErrorHandler::Call(
154                        true     , __LINE__ , __FILE__ ,
155                        "CppAD::EqualOpSeq(x, y)",
156                        "Error: adouble does not support EqualOpSeq."
157                );
158                return false;
159        }
160}
161/* $$
162
163$head Identical$$
164The Adolc user interface does not specify a way to determine if an
165$code adouble$$ depends on the independent variables.
166To be safe (but slow) return $code false$$ in all the cases below.
167$codep */
168namespace CppAD {
169        inline bool IdenticalPar(const adouble &x)
170        {       return false; }
171        inline bool IdenticalZero(const adouble &x)
172        {       return false; }
173        inline bool IdenticalOne(const adouble &x)
174        {       return false; }
175        inline bool IdenticalEqualPar(const adouble &x, const adouble &y)
176        {       return false; }
177}
178/* $$
179
180$head Integer$$
181$codep */
182        inline int Integer(const adouble &x)
183        {    return static_cast<int>( x.getValue() ); }
184/* $$
185
186$head Ordered$$
187$codep */
188namespace CppAD {
189        inline bool GreaterThanZero(const adouble &x)
190        {    return (x > 0); }
191        inline bool GreaterThanOrZero(const adouble &x)
192        {    return (x >= 0); }
193        inline bool LessThanZero(const adouble &x)
194        {    return (x < 0); }
195        inline bool LessThanOrZero(const adouble &x)
196        {    return (x <= 0); }
197        inline bool abs_geq(const adouble& x, const adouble& y)
198        {       return fabs(x) >= fabs(y); }
199}
200/* $$
201
202$head Unary Standard Math$$
203The following $cref/required/base_require/$$ functions
204are defined by the Adolc package for the $code adouble$$ base case:
205$pre
206$$
207$code acos$$,
208$code asin$$,
209$code atan$$,
210$code cos$$,
211$code cosh$$,
212$code exp$$,
213$code fabs$$,
214$code log$$,
215$code sin$$,
216$code sinh$$,
217$code sqrt$$,
218$code tan$$.
219
220$head erf, asin$$
221If the
222$cref/erf, asinh, acosh/base_std_math/erf, asinh, acosh/$$,
223functions are supported by the compiler,
224they must also be supported by a $icode Base$$ type;
225The adolc package does not support these functions so make
226their use an error:
227$codep */
228namespace CppAD {
229# define CPPAD_BASE_ADOLC_NO_SUPPORT(fun)                         \
230    inline adouble fun(const adouble& x)                          \
231    {   CPPAD_ASSERT_KNOWN(                                       \
232            false,                                                \
233            #fun ": adolc does not support this function"         \
234        );                                                        \
235        return 0.0;                                               \
236    }
237# if CPPAD_COMPILER_HAS_ERF
238        CPPAD_BASE_ADOLC_NO_SUPPORT(erf)
239# endif
240# if CPPAD_COMPILER_HAS_ACOSH
241        CPPAD_BASE_ADOLC_NO_SUPPORT(acosh)
242# endif
243# if CPPAD_COMPILER_HAS_ASINH
244        CPPAD_BASE_ADOLC_NO_SUPPORT(asinh)
245# endif
246# undef CPPAD_BASE_ADOLC_NO_SUPPORT
247}
248/* $$
249
250$head sign$$
251This $cref/required/base_require/$$ function is defined using the
252$code codassign$$ function so that its $code adouble$$ operation sequence
253does not depend on the value of $icode x$$.
254$codep */
255namespace CppAD {
256        inline adouble sign(const adouble& x)
257        {       adouble s_plus, s_minus, half(.5);
258                // set s_plus to sign(x)/2,  except for case x == 0, s_plus = -.5
259                condassign(s_plus,  +x, -half, +half);
260                // set s_minus to -sign(x)/2, except for case x == 0, s_minus = -.5
261                condassign(s_minus, -x, -half, +half);
262                // set s to sign(x)
263                return s_plus - s_minus;
264        }
265}
266/* $$
267
268$head abs$$
269This $cref/required/base_require/$$ function uses the adolc $code fabs$$
270function:
271$codep */
272namespace CppAD {
273        inline adouble abs(const adouble& x)
274        {       return fabs(x); }
275}
276/* $$
277
278$head pow$$
279This $cref/required/base_require/$$ function
280is defined by the Adolc package for the $code adouble$$ base case.
281
282$head limits$$
283The following defines the numeric limits functions
284$code epsilon$$, $code min$$, and $code max$$ for the type
285$code adouble$$.
286It also defines the deprecated $code epsilon$$ function:
287$codep */
288namespace CppAD {
289        template <>
290        class numeric_limits<adouble> {
291        public:
292                // machine epsilon
293                static adouble epsilon(void)
294                {       return adouble( std::numeric_limits<double>::epsilon() ); }
295                // minimum positive normalized value
296                static adouble min(void)
297                {       return adouble( std::numeric_limits<float>::min() ); }
298                // maximum finite value
299                static adouble max(void)
300                {       return adouble( std::numeric_limits<float>::max() ); }
301        };
302        // deprecated machine epsilon
303        template <> inline adouble epsilon<adouble>(void)
304        {       return numeric_limits<adouble>::epsilon(); }
305}
306/* $$
307$end
308*/
309# endif
310
Note: See TracBrowser for help on using the repository browser.