Changeset 1453 for trunk/test_more
 Timestamp:
 Jul 6, 2009 12:57:14 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/vec_ad.cpp
r1452 r1453 188 188 CppAD::Independent(X); 189 189 190 size_t m = 1;190 size_t m = 2; 191 191 CPPAD_TEST_VECTOR< AD<double> > Y(m); 192 192 193 193 // The LdpOp instruction corresponds to operations with VecAD vectors. 194 CppAD::VecAD<double> Z( 1);194 CppAD::VecAD<double> Z(2); 195 195 AD<double> zero = 0; 196 196 Z[zero] = X[0] + 1; 197 198 // The LdvOp instruction corresponds to the index being a variable. 199 AD<double> one = X[0]  1; // one in a variable here 200 Z[one] = X[0] + 1.; 201 197 202 198 203 // Compute a function where the second order partial for y … … 201 206 // access to z is the parameter zero. 202 207 Y[0] = Z[zero] * Z[zero]; 208 Y[1] = Z[one] * Z[one]; 203 209 204 210 CppAD::ADFun<double> f(X, Y); … … 210 216 f.Forward(p, dx); 211 217 218 // Test LdpOp 212 219 // second order reverse (test exp_if_true case) 213 220 CPPAD_TEST_VECTOR<double> w(m), dw(2 * n); 214 221 w[0] = 1.; 222 w[1] = 0.; 215 223 p = 2; 216 224 dw = f.Reverse(p, w); … … 218 226 // check first derivative in dw 219 227 double check = 2. * (Value( X[0] ) + 1.); 228 ok &= NearEqual(dw[0], check, eps, eps); 229 230 // check second derivative in dw 231 check = 2.; 232 ok &= NearEqual(dw[1], check, eps, eps); 233 234 // Test LdvOp 235 // second order reverse (test exp_if_true case) 236 w[0] = 0.; 237 w[1] = 1.; 238 p = 2; 239 dw = f.Reverse(p, w); 240 241 // check first derivative in dw 242 check = 2. * (Value( X[0] ) + 1.); 220 243 ok &= NearEqual(dw[0], check, eps, eps); 221 244
Note: See TracChangeset
for help on using the changeset viewer.