CppAD: A C++ Algorithmic Differentiation Package  20171217
discrete_op.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_DISCRETE_OP_HPP
2 # define CPPAD_LOCAL_DISCRETE_OP_HPP
3
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6
8 the terms of the
9  Eclipse Public License Version 1.0.
10
11 A copy of this license is included in the COPYING file of this distribution.
13 -------------------------------------------------------------------------- */
14
15
16 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
17 /*!
18 \file discrete_op.hpp
19 Forward mode for z = f(x) where f is piecewise constant.
20 */
21
22
23 /*!
24 forward mode Taylor coefficient for result of op = DisOp.
25
26 The C++ source code corresponding to this operation is
27 \verbatim
28  z = f(x)
29 \endverbatim
30 where f is a piecewise constant function (and it's derivative is always
31 calculated as zero).
32
33 \tparam Base
34 base type for the operator; i.e., this operation was recorded
35 using AD< \a Base > and computations by this routine are done using type
36 \a Base .
37
38 \param p
39 is the lowest order Taylor coefficient that will be calculated.
40
41 \param q
42 is the highest order Taylor coefficient that will be calculated.
43
44 \param r
45 is the number of directions, for each order,
46 that will be calculated (except for order zero wich only has one direction).
47
48 \param i_z
49 variable index corresponding to the result for this operation;
50 i.e. the row index in \a taylor corresponding to z.
51
52 \param arg
53 \a arg[0]
54 \n
55 is the index, in the order of the discrete functions defined by the user,
56 for this discrete function.
57 \n
58 \n
59 \a arg[1]
60 variable index corresponding to the argument for this operator;
61 i.e. the row index in \a taylor corresponding to x.
62
63 \param cap_order
64 maximum number of orders that will fit in the taylor array.
65
66 \par tpv
67 We use the notation
68 <code>tpv = (cap_order-1) * r + 1</code>
69 which is the number of Taylor coefficients per variable
70
71 \param taylor
72 \b Input: <code>taylor [ arg[1] * tpv + 0 ]</code>
73 is the zero order Taylor coefficient corresponding to x.
74 \n
75 \b Output: if <code>p == 0</code>
76 <code>taylor [ i_z * tpv + 0 ]</code>
77 is the zero order Taylor coefficient corresponding to z.
78 For k = max(p, 1), ... , q,
79 <code>taylor [ i_z * tpv + (k-1)*r + 1 + ell ]</code>
80 is the k-th order Taylor coefficient corresponding to z
81 (which is zero).
82
83 \par Checked Assertions where op is the unary operator with one result:
84 \li NumArg(op) == 2
85 \li NumRes(op) == 1
86 \li q < cap_order
87 \li 0 < r
88 */
89 template <class Base>
90 inline void forward_dis_op(
91  size_t p ,
92  size_t q ,
93  size_t r ,
94  size_t i_z ,
95  const addr_t* arg ,
96  size_t cap_order ,
97  Base* taylor )
98 {
99  // check assumptions
102  CPPAD_ASSERT_UNKNOWN( q < cap_order );
103  CPPAD_ASSERT_UNKNOWN( 0 < r );
104
105  // Taylor coefficients corresponding to argument and result
106  size_t num_taylor_per_var = (cap_order-1) * r + 1;
107  Base* x = taylor + arg[1] * num_taylor_per_var;
108  Base* z = taylor + i_z * num_taylor_per_var;
109
110  if( p == 0 )
111  { z[0] = discrete<Base>::eval(arg[0], x[0]);
112  p++;
113  }
114  for(size_t ell = 0; ell < r; ell++)
115  for(size_t k = p; k <= q; k++)
116  z[ (k-1) * r + 1 + ell ] = Base(0.0);
117 }
118
119
120 } } // END_CPPAD_LOCAL_NAMESPACE
121 # endif
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Definition: op_code.hpp:175
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
static Base eval(size_t index, const Base &x)
Link from forward mode sweep to users routine.
Definition: discrete.hpp:297
void forward_dis_op(size_t p, size_t q, size_t r, size_t i_z, const addr_t *arg, size_t cap_order, Base *taylor)
forward mode Taylor coefficient for result of op = DisOp.
Definition: discrete_op.hpp:90