1 | // $Id: cskip_op.hpp 2968 2013-10-18 19:41:48Z bradbell $ |
---|
2 | # ifndef CPPAD_CSKIP_OP_INCLUDED |
---|
3 | # define CPPAD_CSKIP_OP_INCLUDED |
---|
4 | |
---|
5 | /* -------------------------------------------------------------------------- |
---|
6 | CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell |
---|
7 | |
---|
8 | CppAD is distributed under multiple licenses. This distribution is under |
---|
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. |
---|
13 | Please visit http://www.coin-or.org/CppAD/ for information on other licenses. |
---|
14 | -------------------------------------------------------------------------- */ |
---|
15 | |
---|
16 | namespace CppAD { // BEGIN_CPPAD_NAMESPACE |
---|
17 | /*! |
---|
18 | \defgroup cskip_op_hpp cskip_op.hpp |
---|
19 | \{ |
---|
20 | \file cskip_op.hpp |
---|
21 | Zero order forward mode set which operations to skip. |
---|
22 | */ |
---|
23 | |
---|
24 | /*! |
---|
25 | Zero order forward mode execution of op = CSkipOp. |
---|
26 | |
---|
27 | \tparam Base |
---|
28 | base type for the operator; i.e., this operation was recorded |
---|
29 | using AD< \a Base > and computations by this routine are done using type |
---|
30 | \a Base. |
---|
31 | |
---|
32 | \param i_z |
---|
33 | variable index corresponding to the result of the previous operation. |
---|
34 | This is used for error checking. To be specific, |
---|
35 | the left and right operands for the CExpOp operation must have indexes |
---|
36 | less than or equal this value. |
---|
37 | |
---|
38 | \param arg [in] |
---|
39 | \n |
---|
40 | \a arg[0] |
---|
41 | is static cast to size_t from the enum type |
---|
42 | \verbatim |
---|
43 | enum CompareOp { |
---|
44 | CompareLt, |
---|
45 | CompareLe, |
---|
46 | CompareEq, |
---|
47 | CompareGe, |
---|
48 | CompareGt, |
---|
49 | CompareNe |
---|
50 | } |
---|
51 | \endverbatim |
---|
52 | for this operation. |
---|
53 | Note that arg[0] cannot be equal to CompareNe. |
---|
54 | \n |
---|
55 | \n |
---|
56 | \a arg[1] & 1 |
---|
57 | \n |
---|
58 | If this is zero, left is a a parameter. Otherwise it is a variable. |
---|
59 | \n |
---|
60 | \n |
---|
61 | \a arg[1] & 2 |
---|
62 | \n |
---|
63 | If this is zero, right is a parameter. Otherwise it is a variable. |
---|
64 | \n |
---|
65 | \a arg[2] |
---|
66 | is the index corresponding to left in comparision. |
---|
67 | \n |
---|
68 | \a arg[3] |
---|
69 | is the index corresponding to right in comparision. |
---|
70 | \n |
---|
71 | \a arg[4] |
---|
72 | is the number of operations to skip if the comparision result is true. |
---|
73 | \n |
---|
74 | \a arg[5] |
---|
75 | is the number of operations to skip if the comparision result is false. |
---|
76 | \n |
---|
77 | <tt>arg[5+i]</tt> |
---|
78 | for <tt>i = 1 , ... , arg[4]</tt> are the operations to skip if the |
---|
79 | comparision result is true. |
---|
80 | \n |
---|
81 | <tt>arg[5+arg[4]+i]</tt> |
---|
82 | for <tt>i = 1 , ... , arg[5]</tt> are the operations to skip if the |
---|
83 | comparision result is false. |
---|
84 | |
---|
85 | \param num_par [in] |
---|
86 | is the total number of values in the vector \a parameter. |
---|
87 | |
---|
88 | \param parameter [in] |
---|
89 | If left is a parameter, |
---|
90 | <code>parameter [ arg[2] ]</code> is its value. |
---|
91 | If right is a parameter, |
---|
92 | <code>parameter [ arg[3] ]</code> is its value. |
---|
93 | |
---|
94 | \param nc_taylor [in] |
---|
95 | number of columns in the matrix containing the Taylor coefficients. |
---|
96 | |
---|
97 | \param taylor [in] |
---|
98 | If left is a variable, |
---|
99 | <code>taylor [ arg[2] * nc_taylor + 0 ]</code> |
---|
100 | is the zeroth order Taylor coefficient corresponding to left. |
---|
101 | If right is a variable, |
---|
102 | <code>taylor [ arg[3] * nc_taylor + 0 ]</code> |
---|
103 | is the zeroth order Taylor coefficient corresponding to right. |
---|
104 | |
---|
105 | \param \cskip_var [in,out] |
---|
106 | is vector specifying which operations are at this point are know to be |
---|
107 | unecessary and can be skipped. |
---|
108 | This is both an input and an output. |
---|
109 | */ |
---|
110 | template <class Base> |
---|
111 | inline void forward_cskip_op_0( |
---|
112 | size_t i_z , |
---|
113 | const addr_t* arg , |
---|
114 | size_t num_par , |
---|
115 | const Base* parameter , |
---|
116 | size_t nc_taylor , |
---|
117 | Base* taylor , |
---|
118 | CppAD::vector<bool>& cskip_var ) |
---|
119 | { |
---|
120 | CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < size_t(CompareNe) ); |
---|
121 | CPPAD_ASSERT_UNKNOWN( arg[1] != 0 ); |
---|
122 | |
---|
123 | Base left, right; |
---|
124 | if( arg[1] & 1 ) |
---|
125 | { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < i_z ); |
---|
126 | left = taylor[ arg[2] * nc_taylor + 0 ]; |
---|
127 | CPPAD_ASSERT_UNKNOWN( IdenticalPar(left) ); |
---|
128 | } |
---|
129 | else |
---|
130 | { CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < num_par ); |
---|
131 | left = parameter[ arg[2] ]; |
---|
132 | CPPAD_ASSERT_UNKNOWN( IdenticalPar(left) ); |
---|
133 | } |
---|
134 | if( arg[1] & 2 ) |
---|
135 | { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < i_z ); |
---|
136 | right = taylor[ arg[3] * nc_taylor + 0 ]; |
---|
137 | CPPAD_ASSERT_UNKNOWN( IdenticalPar(right) ); |
---|
138 | } |
---|
139 | else |
---|
140 | { CPPAD_ASSERT_UNKNOWN( size_t(arg[3]) < num_par ); |
---|
141 | right = parameter[ arg[3] ]; |
---|
142 | CPPAD_ASSERT_UNKNOWN( IdenticalPar(right) ); |
---|
143 | } |
---|
144 | |
---|
145 | // initialize to avoid compiler warning |
---|
146 | bool true_case = false; |
---|
147 | Base diff = left - right; |
---|
148 | switch( CompareOp( arg[0] ) ) |
---|
149 | { |
---|
150 | case CompareLt: |
---|
151 | true_case = LessThanZero(diff); |
---|
152 | break; |
---|
153 | |
---|
154 | case CompareLe: |
---|
155 | true_case = LessThanOrZero(diff); |
---|
156 | break; |
---|
157 | |
---|
158 | case CompareEq: |
---|
159 | true_case = IdenticalZero(diff); |
---|
160 | break; |
---|
161 | |
---|
162 | case CompareGe: |
---|
163 | true_case = GreaterThanOrZero(diff); |
---|
164 | break; |
---|
165 | |
---|
166 | case CompareGt: |
---|
167 | true_case = GreaterThanZero(diff); |
---|
168 | break; |
---|
169 | |
---|
170 | case CompareNe: |
---|
171 | true_case = ! IdenticalZero(diff); |
---|
172 | break; |
---|
173 | |
---|
174 | default: |
---|
175 | CPPAD_ASSERT_UNKNOWN(false); |
---|
176 | } |
---|
177 | if( true_case ) |
---|
178 | { for(size_t i = 0; i < size_t(arg[4]); i++) |
---|
179 | cskip_var[ arg[5+i] ] = true; |
---|
180 | } |
---|
181 | else |
---|
182 | { for(size_t i = 0; i < size_t(arg[5]); i++) |
---|
183 | cskip_var[ arg[5+arg[4]+i] ] = true; |
---|
184 | } |
---|
185 | return; |
---|
186 | } |
---|
187 | /*! \} */ |
---|
188 | } // END_CPPAD_NAMESPACE |
---|
189 | # endif |
---|
190 | |
---|