source: trunk/cppad/local/sinh_op.hpp @ 3320

Last change on this file since 3320 was 3320, checked in by bradbell, 6 years ago
  1. g++ 4.8.2 has shadow warnings by default, but eigen and fadbad do not

these warnings, so supress then in these cases.

  1. Move check that arguments come before result into on place,

CPPAD_ASSERT_ARG_BEFORE_RESULT (only one argument case so far).

main.cpp: fix shadowing of index variable.
CMakeLists.txt: adapt to change in teuchos library name.
sparse_jacobian.cpp: fix a shadowed variable.
check_svn_id.sh: ignore svn_commit.sh.
gpl_license.sh: ignore svn_commit.sh.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1/* $Id: sinh_op.hpp 3320 2014-09-11 23:06:21Z bradbell $ */
2# ifndef CPPAD_SINH_OP_INCLUDED
3# define CPPAD_SINH_OP_INCLUDED
4
5/* --------------------------------------------------------------------------
6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
7
8CppAD is distributed under multiple licenses. This distribution is under
9the terms of the
10                    Eclipse Public License Version 1.0.
11
12A copy of this license is included in the COPYING file of this distribution.
13Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14-------------------------------------------------------------------------- */
15
16
17namespace CppAD { // BEGIN_CPPAD_NAMESPACE
18/*!
19\file sinh_op.hpp
20Forward and reverse mode calculations for z = sinh(x).
21*/
22
23
24/*!
25Compute forward mode Taylor coefficient for result of op = SinhOp.
26
27The C++ source code corresponding to this operation is
28\verbatim
29        z = sinh(x)
30\endverbatim
31The auxillary result is
32\verbatim
33        y = cosh(x)
34\endverbatim
35The value of y, and its derivatives, are computed along with the value
36and derivatives of z.
37
38\copydetails forward_unary2_op
39*/
40template <class Base>
41inline void forward_sinh_op(
42        size_t p           ,
43        size_t q           ,
44        size_t i_z         ,
45        size_t i_x         ,
46        size_t cap_order   , 
47        Base*  taylor      )
48{       
49        // check assumptions
50        CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
51        CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
52        CPPAD_ASSERT_UNKNOWN( q < cap_order );
53        CPPAD_ASSERT_UNKNOWN( p <= q );
54
55        // Taylor coefficients corresponding to argument and result
56        Base* x = taylor + i_x * cap_order;
57        Base* s = taylor + i_z * cap_order;
58        Base* c = s      -       cap_order;
59
60
61        // rest of this routine is identical for the following cases:
62        // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
63        // (except that there is a sign difference for hyperbolic case).
64        size_t k;
65        if( p == 0 )
66        {       s[0] = sinh( x[0] );
67                c[0] = cosh( x[0] );
68                p++;
69        }
70        for(size_t j = p; j <= q; j++)
71        {
72                s[j] = Base(0);
73                c[j] = Base(0);
74                for(k = 1; k <= j; k++)
75                {       s[j] += Base(k) * x[k] * c[j-k];
76                        c[j] += Base(k) * x[k] * s[j-k];
77                }
78                s[j] /= Base(j);
79                c[j] /= Base(j);
80        }
81}
82/*!
83Compute forward mode Taylor coefficient for result of op = SinhOp.
84
85The C++ source code corresponding to this operation is
86\verbatim
87        z = sinh(x)
88\endverbatim
89The auxillary result is
90\verbatim
91        y = cosh(x)
92\endverbatim
93The value of y, and its derivatives, are computed along with the value
94and derivatives of z.
95
96\copydetails forward_unary2_op_dir
97*/
98template <class Base>
99inline void forward_sinh_op_dir(
100        size_t q           ,
101        size_t r           ,
102        size_t i_z         ,
103        size_t i_x         ,
104        size_t cap_order   , 
105        Base*  taylor      )
106{       
107        // check assumptions
108        CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
109        CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
110        CPPAD_ASSERT_UNKNOWN( 0 < q );
111        CPPAD_ASSERT_UNKNOWN( q < cap_order );
112
113        // Taylor coefficients corresponding to argument and result
114        size_t num_taylor_per_var = (cap_order-1) * r + 1;
115        Base* x = taylor + i_x * num_taylor_per_var;
116        Base* s = taylor + i_z * num_taylor_per_var;
117        Base* c = s      -       num_taylor_per_var;
118
119
120        // rest of this routine is identical for the following cases:
121        // forward_sin_op, forward_cos_op, forward_sinh_op, forward_cosh_op
122        // (except that there is a sign difference for the hyperbolic case).
123        size_t m = (q-1) * r + 1;
124        for(size_t ell = 0; ell < r; ell++)
125        {       s[m+ell] = Base(q) * x[m + ell] * c[0];
126                c[m+ell] = Base(q) * x[m + ell] * s[0];
127                for(size_t k = 1; k < q; k++)
128                {       s[m+ell] += Base(k) * x[(k-1)*r+1+ell] * c[(q-k-1)*r+1+ell];
129                        c[m+ell] += Base(k) * x[(k-1)*r+1+ell] * s[(q-k-1)*r+1+ell];
130                }
131                s[m+ell] /= Base(q);
132                c[m+ell] /= Base(q);
133        }
134}
135
136/*!
137Compute zero order forward mode Taylor coefficient for result of op = SinhOp.
138
139The C++ source code corresponding to this operation is
140\verbatim
141        z = sinh(x)
142\endverbatim
143The auxillary result is
144\verbatim
145        y = cosh(x)
146\endverbatim
147The value of y is computed along with the value of z.
148
149\copydetails forward_unary2_op_0
150*/
151template <class Base>
152inline void forward_sinh_op_0(
153        size_t i_z         ,
154        size_t i_x         ,
155        size_t cap_order   , 
156        Base*  taylor      )
157{
158        // check assumptions
159        CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
160        CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
161        CPPAD_ASSERT_UNKNOWN( 0 < cap_order );
162
163        // Taylor coefficients corresponding to argument and result
164        Base* x = taylor + i_x * cap_order;
165        Base* s = taylor + i_z * cap_order;  // called z in documentation
166        Base* c = s      -       cap_order;  // called y in documentation
167
168        s[0] = sinh( x[0] );
169        c[0] = cosh( x[0] );
170}
171/*!
172Compute reverse mode partial derivatives for result of op = SinhOp.
173
174The C++ source code corresponding to this operation is
175\verbatim
176        z = sinh(x)
177\endverbatim
178The auxillary result is
179\verbatim
180        y = cosh(x)
181\endverbatim
182The value of y is computed along with the value of z.
183
184\copydetails reverse_unary2_op
185*/
186
187template <class Base>
188inline void reverse_sinh_op(
189        size_t      d            ,
190        size_t      i_z          ,
191        size_t      i_x          ,
192        size_t      cap_order    , 
193        const Base* taylor       ,
194        size_t      nc_partial   ,
195        Base*       partial      )
196{
197        // check assumptions
198        CPPAD_ASSERT_UNKNOWN( NumArg(SinhOp) == 1 );
199        CPPAD_ASSERT_UNKNOWN( NumRes(SinhOp) == 2 );
200        CPPAD_ASSERT_UNKNOWN( d < cap_order );
201        CPPAD_ASSERT_UNKNOWN( d < nc_partial );
202
203        // Taylor coefficients and partials corresponding to argument
204        const Base* x  = taylor  + i_x * cap_order;
205        Base* px       = partial + i_x * nc_partial;
206
207        // Taylor coefficients and partials corresponding to first result
208        const Base* s  = taylor  + i_z * cap_order; // called z in doc
209        Base* ps       = partial + i_z * nc_partial;
210
211        // Taylor coefficients and partials corresponding to auxillary result
212        const Base* c  = s  - cap_order; // called y in documentation
213        Base* pc       = ps - nc_partial;
214
215        // rest of this routine is identical for the following cases:
216        // reverse_sin_op, reverse_cos_op, reverse_sinh_op, reverse_cosh_op.
217        size_t j = d;
218        size_t k;
219        while(j)
220        {
221                ps[j]   /= Base(j);
222                pc[j]   /= Base(j);
223                for(k = 1; k <= j; k++)
224                {
225                        px[k]   += ps[j] * Base(k) * c[j-k];
226                        px[k]   += pc[j] * Base(k) * s[j-k];
227       
228                        ps[j-k] += pc[j] * Base(k) * x[k];
229                        pc[j-k] += ps[j] * Base(k) * x[k];
230
231                }
232                --j;
233        }
234        px[0] += ps[0] * c[0];
235        px[0] += pc[0] * s[0];
236}
237
238} // END_CPPAD_NAMESPACE
239# endif
Note: See TracBrowser for help on using the repository browser.