CppAD: A C++ Algorithmic Differentiation Package 20110419
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_STORE_OP_INCLUDED 00003 # define CPPAD_STORE_OP_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-10 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Common Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 00016 CPPAD_BEGIN_NAMESPACE 00017 /*! 00018 \file store_op.hpp 00019 Changing the current value of a VecAD element. 00020 */ 00021 00022 /*! 00023 Zero order forward mode implementation of op = StppOp. 00024 00025 \copydetails forward_store_op_0 00026 */ 00027 template <class Base> 00028 inline void forward_store_pp_op_0( 00029 size_t i_z , 00030 const size_t* arg , 00031 size_t num_par , 00032 size_t nc_taylor , 00033 Base* taylor , 00034 size_t nc_combined , 00035 bool* variable , 00036 size_t* combined ) 00037 { size_t i_vec = arg[1]; 00038 00039 // Because the index is a parameter, this indexing error should be 00040 // caught and reported to the user when the tape is recording. 00041 CPPAD_ASSERT_UNKNOWN( i_vec < combined[ arg[0] - 1 ] ); 00042 00043 CPPAD_ASSERT_UNKNOWN( variable != CPPAD_NULL ); 00044 CPPAD_ASSERT_UNKNOWN( combined != CPPAD_NULL ); 00045 CPPAD_ASSERT_UNKNOWN( NumArg(StppOp) == 3 ); 00046 CPPAD_ASSERT_UNKNOWN( NumRes(StppOp) == 0 ); 00047 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00048 CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined ); 00049 CPPAD_ASSERT_UNKNOWN( arg[2] < num_par ); 00050 00051 variable[ arg[0] + i_vec ] = false; 00052 combined[ arg[0] + i_vec ] = arg[2]; 00053 } 00054 00055 /*! 00056 Zero order forward mode implementation of op = StpvOp. 00057 00058 \copydetails forward_store_op_0 00059 */ 00060 template <class Base> 00061 inline void forward_store_pv_op_0( 00062 size_t i_z , 00063 const size_t* arg , 00064 size_t num_par , 00065 size_t nc_taylor , 00066 Base* taylor , 00067 size_t nc_combined , 00068 bool* variable , 00069 size_t* combined ) 00070 { size_t i_vec = arg[1]; 00071 00072 // Because the index is a parameter, this indexing error should be 00073 // caught and reported to the user when the tape is recording. 00074 CPPAD_ASSERT_UNKNOWN( i_vec < combined[ arg[0] - 1 ] ); 00075 00076 CPPAD_ASSERT_UNKNOWN( variable != CPPAD_NULL ); 00077 CPPAD_ASSERT_UNKNOWN( combined != CPPAD_NULL ); 00078 CPPAD_ASSERT_UNKNOWN( NumArg(StpvOp) == 3 ); 00079 CPPAD_ASSERT_UNKNOWN( NumRes(StpvOp) == 0 ); 00080 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00081 CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined ); 00082 CPPAD_ASSERT_UNKNOWN( arg[2] <= i_z ); 00083 00084 variable[ arg[0] + i_vec ] = true; 00085 combined[ arg[0] + i_vec ] = arg[2]; 00086 } 00087 00088 /*! 00089 Zero order forward mode implementation of op = StvpOp. 00090 00091 \copydetails forward_store_op_0 00092 */ 00093 template <class Base> 00094 inline void forward_store_vp_op_0( 00095 size_t i_z , 00096 const size_t* arg , 00097 size_t num_par , 00098 size_t nc_taylor , 00099 Base* taylor , 00100 size_t nc_combined , 00101 bool* variable , 00102 size_t* combined ) 00103 { 00104 CPPAD_ASSERT_UNKNOWN( arg[1] <= i_z ); 00105 size_t i_vec = Integer( taylor[ arg[1] * nc_taylor + 0 ] ); 00106 CPPAD_ASSERT_KNOWN( 00107 i_vec < combined[ arg[0] - 1 ] , 00108 "VecAD: index during zero order forward sweep is out of range" 00109 ); 00110 00111 CPPAD_ASSERT_UNKNOWN( variable != CPPAD_NULL ); 00112 CPPAD_ASSERT_UNKNOWN( combined != CPPAD_NULL ); 00113 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 ); 00114 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 ); 00115 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00116 CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined ); 00117 CPPAD_ASSERT_UNKNOWN( arg[2] < num_par ); 00118 00119 variable[ arg[0] + i_vec ] = false; 00120 combined[ arg[0] + i_vec ] = arg[2]; 00121 } 00122 00123 /*! 00124 Zero order forward mode implementation of op = StvvOp. 00125 00126 \copydetails forward_store_op_0 00127 */ 00128 template <class Base> 00129 inline void forward_store_vv_op_0( 00130 size_t i_z , 00131 const size_t* arg , 00132 size_t num_par , 00133 size_t nc_taylor , 00134 Base* taylor , 00135 size_t nc_combined , 00136 bool* variable , 00137 size_t* combined ) 00138 { 00139 CPPAD_ASSERT_UNKNOWN( arg[1] <= i_z ); 00140 size_t i_vec = Integer( taylor[ arg[1] * nc_taylor + 0 ] ); 00141 CPPAD_ASSERT_KNOWN( 00142 i_vec < combined[ arg[0] - 1 ] , 00143 "VecAD: index during zero order forward sweep is out of range" 00144 ); 00145 00146 CPPAD_ASSERT_UNKNOWN( variable != CPPAD_NULL ); 00147 CPPAD_ASSERT_UNKNOWN( combined != CPPAD_NULL ); 00148 CPPAD_ASSERT_UNKNOWN( NumArg(StvpOp) == 3 ); 00149 CPPAD_ASSERT_UNKNOWN( NumRes(StvpOp) == 0 ); 00150 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00151 CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined ); 00152 CPPAD_ASSERT_UNKNOWN( arg[2] <= i_z ); 00153 00154 variable[ arg[0] + i_vec ] = true; 00155 combined[ arg[0] + i_vec ] = arg[2]; 00156 } 00157 00158 /*! 00159 Forward mode sparsity operations for StpvOp and StvvOp 00160 00161 \copydetails sparse_store_op 00162 */ 00163 template <class Vector_set> 00164 inline void forward_sparse_store_op( 00165 OpCode op , 00166 const size_t* arg , 00167 size_t num_combined , 00168 const size_t* combined , 00169 Vector_set& var_sparsity , 00170 Vector_set& vecad_sparsity ) 00171 { 00172 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); 00173 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); 00174 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00175 CPPAD_ASSERT_UNKNOWN( arg[0] < num_combined ); 00176 size_t i_v = combined[ arg[0] - 1 ]; 00177 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); 00178 CPPAD_ASSERT_UNKNOWN( arg[2] < var_sparsity.n_set() ); 00179 00180 vecad_sparsity.binary_union(i_v, i_v, arg[2], var_sparsity); 00181 00182 return; 00183 } 00184 00185 /*! 00186 Reverse mode sparsity operations for StpvOp and StvvOp 00187 00188 This routine is given the sparsity patterns for 00189 G(v[x], y , w , u ... ) and it uses them to compute the 00190 sparsity patterns for 00191 \verbatim 00192 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ] 00193 \endverbatim 00194 00195 \copydetails sparse_store_op 00196 */ 00197 template <class Vector_set> 00198 inline void reverse_sparse_jacobian_store_op( 00199 OpCode op , 00200 const size_t* arg , 00201 size_t num_combined , 00202 const size_t* combined , 00203 Vector_set& var_sparsity , 00204 Vector_set& vecad_sparsity ) 00205 { 00206 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); 00207 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); 00208 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00209 CPPAD_ASSERT_UNKNOWN( arg[0] < num_combined ); 00210 size_t i_v = combined[ arg[0] - 1 ]; 00211 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); 00212 CPPAD_ASSERT_UNKNOWN( arg[2] < var_sparsity.n_set() ); 00213 00214 var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity); 00215 00216 return; 00217 } 00218 00219 /*! 00220 Reverse mode sparsity operations for StpvOp and StvvOp 00221 00222 This routine is given the sparsity patterns for 00223 G(v[x], y , w , u ... ) 00224 and it uses them to compute the sparsity patterns for 00225 \verbatim 00226 H(y , w , u , ... ) = G[ v[x], y , w , u , ... ] 00227 \endverbatim 00228 00229 \copydetails sparse_store_op 00230 00231 \param var_jacobian 00232 \a var_jacobian[ \a arg[2] ] 00233 is false (true) if the Jacobian of G with respect to y is always zero 00234 (may be non-zero). 00235 00236 \param vecad_jacobian 00237 \a vecad_jacobian[i_v] 00238 is false (true) if the Jacobian with respect to x is always zero 00239 (may be non-zero). 00240 On input, it corresponds to the function G, 00241 and on output it corresponds to the function H. 00242 */ 00243 template <class Vector_set> 00244 inline void reverse_sparse_hessian_store_op( 00245 OpCode op , 00246 const size_t* arg , 00247 size_t num_combined , 00248 const size_t* combined , 00249 Vector_set& var_sparsity , 00250 Vector_set& vecad_sparsity , 00251 bool* var_jacobian , 00252 bool* vecad_jacobian ) 00253 { 00254 CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 ); 00255 CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 ); 00256 CPPAD_ASSERT_UNKNOWN( 0 < arg[0] ); 00257 CPPAD_ASSERT_UNKNOWN( arg[0] < num_combined ); 00258 size_t i_v = combined[ arg[0] - 1 ]; 00259 CPPAD_ASSERT_UNKNOWN( i_v < vecad_sparsity.n_set() ); 00260 CPPAD_ASSERT_UNKNOWN( arg[2] < var_sparsity.n_set() ); 00261 00262 var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity); 00263 00264 var_jacobian[ arg[2] ] |= vecad_jacobian[i_v]; 00265 00266 return; 00267 } 00268 00269 CPPAD_END_NAMESPACE 00270 # endif