CppAD: A C++ Algorithmic Differentiation Package  20171217
Go to the documentation of this file.
4
5 /* --------------------------------------------------------------------------
7
9 the terms of the
10  Eclipse Public License Version 1.0.
11
12 A copy of this license is included in the COPYING file of this distribution.
14 -------------------------------------------------------------------------- */
15
17 /*!
19 Forward and reverse mode calculations for z = x + y.
20 */
21
23 /*!
24 Compute forward mode Taylor coefficients for result of op = AddvvOp.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28  z = x + y
29 \endverbatim
30 In the documentation below,
31 this operations is for the case where both x and y are variables
32 and the argument \a parameter is not used.
33
35 */
36
37 template <class Base>
39  size_t p ,
40  size_t q ,
41  size_t i_z ,
43  const Base* parameter ,
44  size_t cap_order ,
45  Base* taylor )
46 {
47  // check assumptions
50  CPPAD_ASSERT_UNKNOWN( q < cap_order );
51  CPPAD_ASSERT_UNKNOWN( p <= q );
52
53  // Taylor coefficients corresponding to arguments and result
54  Base* x = taylor + arg[0] * cap_order;
55  Base* y = taylor + arg[1] * cap_order;
56  Base* z = taylor + i_z * cap_order;
57
58  for(size_t j = p; j <= q; j++)
59  z[j] = x[j] + y[j];
60 }
61 /*!
62 Multiple directions forward mode Taylor coefficients for op = AddvvOp.
63
64 The C++ source code corresponding to this operation is
65 \verbatim
66  z = x + y
67 \endverbatim
68 In the documentation below,
69 this operations is for the case where both x and y are variables
70 and the argument \a parameter is not used.
71
73 */
74
75 template <class Base>
77  size_t q ,
78  size_t r ,
79  size_t i_z ,
81  const Base* parameter ,
82  size_t cap_order ,
83  Base* taylor )
84 {
85  // check assumptions
88  CPPAD_ASSERT_UNKNOWN( q < cap_order );
89  CPPAD_ASSERT_UNKNOWN( 0 < q );
90
91  // Taylor coefficients corresponding to arguments and result
92  size_t num_taylor_per_var = (cap_order-1) * r + 1;
93  Base* x = taylor + arg[0] * num_taylor_per_var;
94  Base* y = taylor + arg[1] * num_taylor_per_var;
95  Base* z = taylor + i_z * num_taylor_per_var;
96
97  size_t m = (q-1)*r + 1 ;
98  for(size_t ell = 0; ell < r; ell++)
99  z[m+ell] = x[m+ell] + y[m+ell];
100 }
101
102 /*!
103 Compute zero order forward mode Taylor coefficients for result of op = AddvvOp.
104
105 The C++ source code corresponding to this operation is
106 \verbatim
107  z = x + y
108 \endverbatim
109 In the documentation below,
110 this operations is for the case where both x and y are variables
111 and the argument \a parameter is not used.
112
114 */
115
116 template <class Base>
118  size_t i_z ,
120  const Base* parameter ,
121  size_t cap_order ,
122  Base* taylor )
123 {
124  // check assumptions
127
128  // Taylor coefficients corresponding to arguments and result
129  Base* x = taylor + arg[0] * cap_order;
130  Base* y = taylor + arg[1] * cap_order;
131  Base* z = taylor + i_z * cap_order;
132
133  z[0] = x[0] + y[0];
134 }
135
136 /*!
137 Compute reverse mode partial derivatives for result of op = AddvvOp.
138
139 The C++ source code corresponding to this operation is
140 \verbatim
141  z = x + y
142 \endverbatim
143 In the documentation below,
144 this operations is for the case where both x and y are variables
145 and the argument \a parameter is not used.
146
148 */
149
150 template <class Base>
152  size_t d ,
153  size_t i_z ,
155  const Base* parameter ,
156  size_t cap_order ,
157  const Base* taylor ,
158  size_t nc_partial ,
159  Base* partial )
160 {
161  // check assumptions
164  CPPAD_ASSERT_UNKNOWN( d < cap_order );
165  CPPAD_ASSERT_UNKNOWN( d < nc_partial );
166
167  // Partial derivatives corresponding to arguments and result
168  Base* px = partial + arg[0] * nc_partial;
169  Base* py = partial + arg[1] * nc_partial;
170  Base* pz = partial + i_z * nc_partial;
171
172  // number of indices to access
173  size_t i = d + 1;
174  while(i)
175  { --i;
176  px[i] += pz[i];
177  py[i] += pz[i];
178  }
179 }
180
182 /*!
183 Compute forward mode Taylor coefficients for result of op = AddpvOp.
184
185 The C++ source code corresponding to this operation is
186 \verbatim
187  z = x + y
188 \endverbatim
189 In the documentation below,
190 this operations is for the case where x is a parameter and y is a variable.
191
193 */
194 template <class Base>
196  size_t p ,
197  size_t q ,
198  size_t i_z ,
200  const Base* parameter ,
201  size_t cap_order ,
202  Base* taylor )
203 {
204  // check assumptions
207  CPPAD_ASSERT_UNKNOWN( q < cap_order );
208  CPPAD_ASSERT_UNKNOWN( p <= q );
209
210  // Taylor coefficients corresponding to arguments and result
211  Base* y = taylor + arg[1] * cap_order;
212  Base* z = taylor + i_z * cap_order;
213
214  if( p == 0 )
215  { // Paraemter value
216  Base x = parameter[ arg[0] ];
217  z[0] = x + y[0];
218  p++;
219  }
220  for(size_t j = p; j <= q; j++)
221  z[j] = y[j];
222 }
223 /*!
224 Multiple directions forward mode Taylor coefficients for op = AddpvOp.
225
226 The C++ source code corresponding to this operation is
227 \verbatim
228  z = x + y
229 \endverbatim
230 In the documentation below,
231 this operations is for the case where x is a parameter and y is a variable.
232
234 */
235 template <class Base>
237  size_t q ,
238  size_t r ,
239  size_t i_z ,
241  const Base* parameter ,
242  size_t cap_order ,
243  Base* taylor )
244 {
245  // check assumptions
248  CPPAD_ASSERT_UNKNOWN( 0 < q );
249  CPPAD_ASSERT_UNKNOWN( q < cap_order );
250
251  // Taylor coefficients corresponding to arguments and result
252  size_t num_taylor_per_var = (cap_order-1) * r + 1;
253  size_t m = (q-1) * r + 1;
254  Base* y = taylor + arg[1] * num_taylor_per_var + m;
255  Base* z = taylor + i_z * num_taylor_per_var + m;
256
257  for(size_t ell = 0; ell < r; ell++)
258  z[ell] = y[ell];
259 }
260 /*!
261 Compute zero order forward mode Taylor coefficient for result of op = AddpvOp.
262
263 The C++ source code corresponding to this operation is
264 \verbatim
265  z = x + y
266 \endverbatim
267 In the documentation below,
268 this operations is for the case where x is a parameter and y is a variable.
269
271 */
272
273 template <class Base>
275  size_t i_z ,
277  const Base* parameter ,
278  size_t cap_order ,
279  Base* taylor )
280 {
281  // check assumptions
284
285  // Paraemter value
286  Base x = parameter[ arg[0] ];
287
288  // Taylor coefficients corresponding to arguments and result
289  Base* y = taylor + arg[1] * cap_order;
290  Base* z = taylor + i_z * cap_order;
291
292  z[0] = x + y[0];
293 }
294
295 /*!
296 Compute reverse mode partial derivative for result of op = AddpvOp.
297
298 The C++ source code corresponding to this operation is
299 \verbatim
300  z = x + y
301 \endverbatim
302 In the documentation below,
303 this operations is for the case where x is a parameter and y is a variable.
304
306 */
307
308 template <class Base>
310  size_t d ,
311  size_t i_z ,
313  const Base* parameter ,
314  size_t cap_order ,
315  const Base* taylor ,
316  size_t nc_partial ,
317  Base* partial )
318 {
319  // check assumptions
322  CPPAD_ASSERT_UNKNOWN( d < cap_order );
323  CPPAD_ASSERT_UNKNOWN( d < nc_partial );
324
325  // Partial derivatives corresponding to arguments and result
326  Base* py = partial + arg[1] * nc_partial;
327  Base* pz = partial + i_z * nc_partial;
328
329  // number of indices to access
330  size_t i = d + 1;
331  while(i)
332  { --i;
333  py[i] += pz[i];
334  }
335 }
336
337
339 # endif
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Definition: op_code.hpp:175
void forward_addpv_op_dir(size_t q, size_t r, size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, Base *taylor)
Multiple directions forward mode Taylor coefficients for op = AddpvOp.
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
void reverse_addpv_op(size_t d, size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, const Base *taylor, size_t nc_partial, Base *partial)
Compute reverse mode partial derivative for result of op = AddpvOp.
Check that exp is true, if not terminate execution.
void forward_addvv_op(size_t p, size_t q, size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, Base *taylor)
Compute forward mode Taylor coefficients for result of op = AddvvOp.
void forward_addvv_op_0(size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, Base *taylor)
Compute zero order forward mode Taylor coefficients for result of op = AddvvOp.
void reverse_addvv_op(size_t d, size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, const Base *taylor, size_t nc_partial, Base *partial)
Compute reverse mode partial derivatives for result of op = AddvvOp.
void forward_addpv_op(size_t p, size_t q, size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, Base *taylor)
Compute forward mode Taylor coefficients for result of op = AddpvOp.
void forward_addpv_op_0(size_t i_z, const addr_t *arg, const Base *parameter, size_t cap_order, Base *taylor)
Compute zero order forward mode Taylor coefficient for result of op = AddpvOp.