Changeset 3607 for trunk/test_more
- Timestamp:
- Jan 20, 2015 11:20:41 AM (5 years ago)
- Location:
- trunk/test_more
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test_more/compare_change.cpp
r2570 r3607 1 1 /* $Id$ */ 2 2 /* -------------------------------------------------------------------------- 3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-1 2Bradley M. Bell3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell 4 4 5 5 CppAD is distributed under multiple licenses. This distribution is under 6 the terms of the 6 the terms of the 7 7 Eclipse Public License Version 1.0. 8 8 … … 12 12 13 13 /* 14 Old CompareChange example and test, now just used for validation testing14 Old CompareChange examples and tests, now just used for validation testing 15 15 */ 16 16 17 17 # include <cppad/cppad.hpp> 18 18 19 bool CompareChange(void) 20 { bool ok = true; 21 # ifndef NDEBUG 22 23 using namespace CppAD; 24 25 // ------------------------------- < ---------------------------- 26 27 // create independent variables 28 CPPAD_TESTVECTOR(AD<double>) X(2); 29 X[0] = 3.; 30 X[1] = 4.; 31 Independent(X); 32 33 // create dependent variables 34 CPPAD_TESTVECTOR(AD<double>) Y(6); 35 36 // CondExp would never require retaping 37 if( X[0] < X[1] ) // True variable < variable 38 Y[0] = X[0]; 39 else Y[0] = X[1]; 40 if( X[1] < X[0] ) // False variable < variable 41 Y[1] = X[0]; 42 else Y[1] = X[1]; 43 if( 3.5 < X[1] ) // True parameter < variable 44 Y[2] = X[0]; 45 else Y[2] = X[1]; 46 if( 3.5 < X[0] ) // False parameter < variable 47 Y[3] = X[0]; 48 else Y[3] = X[1]; 49 if( X[0] < 4. ) // True variable < parameter 50 Y[4] = X[0]; 51 else Y[4] = X[1]; 52 if( X[1] < 4. ) // False variable < parameter 53 Y[5] = X[0]; 54 else Y[5] = X[1]; 55 56 // f : X -> Y 57 ADFun<double> *f; 58 f = new ADFun<double>(X, Y); 59 60 // new argument value 61 CPPAD_TESTVECTOR(double) x( X.size() ); 62 x[0] = 4.; 63 x[1] = 3.; 64 65 // evaluate the function at new argument 66 CPPAD_TESTVECTOR(double) y( Y.size() ); 67 y = f->Forward(0, x); 68 69 // check results 70 ok &= (y[0] == x[0]); // this is what the was taped 71 ok &= (y[1] == x[1]); 72 ok &= (y[2] == x[0]); 73 ok &= (y[3] == x[1]); 74 ok &= (y[4] == x[0]); 75 ok &= (y[5] == x[1]); 76 ok &= (f->CompareChange() == 6); // all comparisions have changed 77 78 // done with this function 79 delete f; 80 81 // ------------------------------- > ---------------------------- 82 // create independent variables 83 Independent(X); 84 85 if( X[0] > X[1] ) // False variable > variable 86 Y[0] = X[0]; 87 else Y[0] = X[1]; 88 if( X[1] > X[0] ) // True variable > variable 89 Y[1] = X[0]; 90 else Y[1] = X[1]; 91 if( 3.5 > X[1] ) // False parameter > variable 92 Y[2] = X[0]; 93 else Y[2] = X[1]; 94 if( 3.5 > X[0] ) // True parameter > variable 95 Y[3] = X[0]; 96 else Y[3] = X[1]; 97 if( X[0] > 3. ) // False variable > parameter 98 Y[4] = X[0]; 99 else Y[4] = X[1]; 100 if( X[1] > 3. ) // True variable > parameter 101 Y[5] = X[0]; 102 else Y[5] = X[1]; 103 104 // f : X -> Y 105 f = new ADFun<double> (X, Y); 106 107 // evaluate the function at new argument 108 y = f->Forward(0, x); 109 110 // check results 111 ok &= (y[0] == x[1]); // this is what the was taped 112 ok &= (y[1] == x[0]); 113 ok &= (y[2] == x[1]); 114 ok &= (y[3] == x[0]); 115 ok &= (y[4] == x[1]); 116 ok &= (y[5] == x[0]); 117 ok &= (f->CompareChange() == 6); // all comparisions have changed 118 119 // done with this function 120 delete f; 121 122 // ------------------------------- <= ---------------------------- 123 // create independent variables 124 Independent(X); 125 126 if( X[0] <= X[1] ) // True variable <= variable 127 Y[0] = X[0]; 128 else Y[0] = X[1]; 129 if( X[1] <= X[0] ) // False variable <= variable 130 Y[1] = X[0]; 131 else Y[1] = X[1]; 132 if( 4. <= X[1] ) // True parameter <= variable 133 Y[2] = X[0]; 134 else Y[2] = X[1]; 135 if( 4. <= X[0] ) // False parameter <= variable 136 Y[3] = X[0]; 137 else Y[3] = X[1]; 138 if( X[0] <= 3.5 ) // True variable <= parameter 139 Y[4] = X[0]; 140 else Y[4] = X[1]; 141 if( X[1] <= 3.5 ) // False variable <= parameter 142 Y[5] = X[0]; 143 else Y[5] = X[1]; 144 145 // f : X -> Y 146 f = new ADFun<double> (X, Y); 147 148 // evaluate the function at new argument 149 y = f->Forward(0, x); 150 151 // check results 152 ok &= (y[0] == x[0]); // this is what the was taped 153 ok &= (y[1] == x[1]); 154 ok &= (y[2] == x[0]); 155 ok &= (y[3] == x[1]); 156 ok &= (y[4] == x[0]); 157 ok &= (y[5] == x[1]); 158 ok &= (f->CompareChange() == 6); // all comparisions have changed 159 160 // done with this function 161 delete f; 162 163 164 // ------------------------------- >= ---------------------------- 165 // create independent variables 166 Independent(X); 167 168 if( X[0] >= X[1] ) // False variable >= variable 169 Y[0] = X[0]; 170 else Y[0] = X[1]; 171 if( X[1] >= X[0] ) // True variable >= variable 172 Y[1] = X[0]; 173 else Y[1] = X[1]; 174 if( 3.5 >= X[1] ) // False parameter >= variable 175 Y[2] = X[0]; 176 else Y[2] = X[1]; 177 if( 3.5 >= X[0] ) // True parameter >= variable 178 Y[3] = X[0]; 179 else Y[3] = X[1]; 180 if( X[0] >= 4. ) // False variable >= parameter 181 Y[4] = X[0]; 182 else Y[4] = X[1]; 183 if( X[1] >= 4. ) // True variable >= parameter 184 Y[5] = X[0]; 185 else Y[5] = X[1]; 186 187 // f : X -> Y 188 f = new ADFun<double> (X, Y); 189 190 // evaluate the function at new argument 191 y = f->Forward(0, x); 192 193 // check results 194 ok &= (y[0] == x[1]); // this is what the was taped 195 ok &= (y[1] == x[0]); 196 ok &= (y[2] == x[1]); 197 ok &= (y[3] == x[0]); 198 ok &= (y[4] == x[1]); 199 ok &= (y[5] == x[0]); 200 ok &= (f->CompareChange() == 6); // all comparisions have changed 201 202 // done with this function 203 delete f; 204 205 // ------------------------------- == ---------------------------- 206 // create independent variables 207 Independent(X); 208 209 if( X[0] == X[1] ) // False variable == variable 210 Y[0] = X[0]; 211 else Y[0] = X[1]; 212 if( X[0] == X[0] ) // True variable == variable 213 Y[1] = X[0]; 214 else Y[1] = X[1]; 215 if( 3. == X[1] ) // False parameter == variable 216 Y[2] = X[0]; 217 else Y[2] = X[1]; 218 if( 3. == X[0] ) // True parameter == variable 219 Y[3] = X[0]; 220 else Y[3] = X[1]; 221 if( X[0] == 4. ) // False variable == parameter 222 Y[4] = X[0]; 223 else Y[4] = X[1]; 224 if( X[1] == 4. ) // True variable == parameter 225 Y[5] = X[0]; 226 else Y[5] = X[1]; 227 228 // f : X -> Y 229 f = new ADFun<double> (X, Y); 230 231 // evaluate the function at new argument 232 y = f->Forward(0, x); 233 234 // check results 235 ok &= (y[0] == x[1]); // this is what the was taped 236 ok &= (y[1] == x[0]); 237 ok &= (y[2] == x[1]); 238 ok &= (y[3] == x[0]); 239 ok &= (y[4] == x[1]); 240 ok &= (y[5] == x[0]); 241 // the first two comparisions do not change 242 ok &= (f->CompareChange() == 4); 243 244 // done with this function 245 delete f; 246 247 // ------------------------------- != ---------------------------- 248 // create independent variables 249 Independent(X); 250 251 if( X[0] != X[1] ) // True variable != variable 252 Y[0] = X[0]; 253 else Y[0] = X[1]; 254 if( X[0] != X[0] ) // False variable != variable 255 Y[1] = X[0]; 256 else Y[1] = X[1]; 257 if( 3. != X[1] ) // True parameter != variable 258 Y[2] = X[0]; 259 else Y[2] = X[1]; 260 if( 3. != X[0] ) // False parameter != variable 261 Y[3] = X[0]; 262 else Y[3] = X[1]; 263 if( X[0] != 4. ) // True variable != parameter 264 Y[4] = X[0]; 265 else Y[4] = X[1]; 266 if( X[1] != 4. ) // False variable != parameter 267 Y[5] = X[0]; 268 else Y[5] = X[1]; 269 270 // f : X -> Y 271 f = new ADFun<double> (X, Y); 272 273 // evaluate the function at new argument 274 y = f->Forward(0, x); 275 276 // check results 277 ok &= (y[0] == x[0]); // this is what the was taped 278 ok &= (y[1] == x[1]); 279 ok &= (y[2] == x[0]); 280 ok &= (y[3] == x[1]); 281 ok &= (y[4] == x[0]); 282 ok &= (y[5] == x[1]); 283 // the first two comparisions do not change 284 ok &= (f->CompareChange() == 4); 285 286 // done with this function 287 delete f; 288 289 # endif 19 namespace { 20 // ---------------------------------------------------------------------- 21 bool CompareChange_one(void) 22 { bool ok = true; 23 24 using namespace CppAD; 25 26 // ------------------------------- < ---------------------------- 27 28 // create independent variables 29 CPPAD_TESTVECTOR(AD<double>) X(2); 30 X[0] = 3.; 31 X[1] = 4.; 32 Independent(X); 33 34 // create dependent variables 35 CPPAD_TESTVECTOR(AD<double>) Y(6); 36 37 // CondExp would never require retaping 38 if( X[0] < X[1] ) // True variable < variable 39 Y[0] = X[0]; 40 else Y[0] = X[1]; 41 if( X[1] < X[0] ) // False variable < variable 42 Y[1] = X[0]; 43 else Y[1] = X[1]; 44 if( 3.5 < X[1] ) // True parameter < variable 45 Y[2] = X[0]; 46 else Y[2] = X[1]; 47 if( 3.5 < X[0] ) // False parameter < variable 48 Y[3] = X[0]; 49 else Y[3] = X[1]; 50 if( X[0] < 4. ) // True variable < parameter 51 Y[4] = X[0]; 52 else Y[4] = X[1]; 53 if( X[1] < 4. ) // False variable < parameter 54 Y[5] = X[0]; 55 else Y[5] = X[1]; 56 57 // f : X -> Y 58 ADFun<double> *f; 59 f = new ADFun<double>(X, Y); 60 61 // new argument value 62 CPPAD_TESTVECTOR(double) x( X.size() ); 63 x[0] = 4.; 64 x[1] = 3.; 65 66 // evaluate the function at new argument 67 CPPAD_TESTVECTOR(double) y( Y.size() ); 68 y = f->Forward(0, x); 69 70 // check results 71 ok &= (y[0] == x[0]); // this is what the was taped 72 ok &= (y[1] == x[1]); 73 ok &= (y[2] == x[0]); 74 ok &= (y[3] == x[1]); 75 ok &= (y[4] == x[0]); 76 ok &= (y[5] == x[1]); 77 ok &= (f->CompareChange() == 6); // all comparisions have changed 78 79 // done with this function 80 delete f; 81 82 // ------------------------------- > ---------------------------- 83 // create independent variables 84 Independent(X); 85 86 if( X[0] > X[1] ) // False variable > variable 87 Y[0] = X[0]; 88 else Y[0] = X[1]; 89 if( X[1] > X[0] ) // True variable > variable 90 Y[1] = X[0]; 91 else Y[1] = X[1]; 92 if( 3.5 > X[1] ) // False parameter > variable 93 Y[2] = X[0]; 94 else Y[2] = X[1]; 95 if( 3.5 > X[0] ) // True parameter > variable 96 Y[3] = X[0]; 97 else Y[3] = X[1]; 98 if( X[0] > 3. ) // False variable > parameter 99 Y[4] = X[0]; 100 else Y[4] = X[1]; 101 if( X[1] > 3. ) // True variable > parameter 102 Y[5] = X[0]; 103 else Y[5] = X[1]; 104 105 // f : X -> Y 106 f = new ADFun<double> (X, Y); 107 108 // evaluate the function at new argument 109 y = f->Forward(0, x); 110 111 // check results 112 ok &= (y[0] == x[1]); // this is what the was taped 113 ok &= (y[1] == x[0]); 114 ok &= (y[2] == x[1]); 115 ok &= (y[3] == x[0]); 116 ok &= (y[4] == x[1]); 117 ok &= (y[5] == x[0]); 118 ok &= (f->CompareChange() == 6); // all comparisions have changed 119 120 // done with this function 121 delete f; 122 123 // ------------------------------- <= ---------------------------- 124 // create independent variables 125 Independent(X); 126 127 if( X[0] <= X[1] ) // True variable <= variable 128 Y[0] = X[0]; 129 else Y[0] = X[1]; 130 if( X[1] <= X[0] ) // False variable <= variable 131 Y[1] = X[0]; 132 else Y[1] = X[1]; 133 if( 4. <= X[1] ) // True parameter <= variable 134 Y[2] = X[0]; 135 else Y[2] = X[1]; 136 if( 4. <= X[0] ) // False parameter <= variable 137 Y[3] = X[0]; 138 else Y[3] = X[1]; 139 if( X[0] <= 3.5 ) // True variable <= parameter 140 Y[4] = X[0]; 141 else Y[4] = X[1]; 142 if( X[1] <= 3.5 ) // False variable <= parameter 143 Y[5] = X[0]; 144 else Y[5] = X[1]; 145 146 // f : X -> Y 147 f = new ADFun<double> (X, Y); 148 149 // evaluate the function at new argument 150 y = f->Forward(0, x); 151 152 // check results 153 ok &= (y[0] == x[0]); // this is what the was taped 154 ok &= (y[1] == x[1]); 155 ok &= (y[2] == x[0]); 156 ok &= (y[3] == x[1]); 157 ok &= (y[4] == x[0]); 158 ok &= (y[5] == x[1]); 159 ok &= (f->CompareChange() == 6); // all comparisions have changed 160 161 // done with this function 162 delete f; 163 164 165 // ------------------------------- >= ---------------------------- 166 // create independent variables 167 Independent(X); 168 169 if( X[0] >= X[1] ) // False variable >= variable 170 Y[0] = X[0]; 171 else Y[0] = X[1]; 172 if( X[1] >= X[0] ) // True variable >= variable 173 Y[1] = X[0]; 174 else Y[1] = X[1]; 175 if( 3.5 >= X[1] ) // False parameter >= variable 176 Y[2] = X[0]; 177 else Y[2] = X[1]; 178 if( 3.5 >= X[0] ) // True parameter >= variable 179 Y[3] = X[0]; 180 else Y[3] = X[1]; 181 if( X[0] >= 4. ) // False variable >= parameter 182 Y[4] = X[0]; 183 else Y[4] = X[1]; 184 if( X[1] >= 4. ) // True variable >= parameter 185 Y[5] = X[0]; 186 else Y[5] = X[1]; 187 188 // f : X -> Y 189 f = new ADFun<double> (X, Y); 190 191 // evaluate the function at new argument 192 y = f->Forward(0, x); 193 194 // check results 195 ok &= (y[0] == x[1]); // this is what the was taped 196 ok &= (y[1] == x[0]); 197 ok &= (y[2] == x[1]); 198 ok &= (y[3] == x[0]); 199 ok &= (y[4] == x[1]); 200 ok &= (y[5] == x[0]); 201 ok &= (f->CompareChange() == 6); // all comparisions have changed 202 203 // done with this function 204 delete f; 205 206 // ------------------------------- == ---------------------------- 207 // create independent variables 208 Independent(X); 209 210 if( X[0] == X[1] ) // False variable == variable 211 Y[0] = X[0]; 212 else Y[0] = X[1]; 213 if( X[0] == X[0] ) // True variable == variable 214 Y[1] = X[0]; 215 else Y[1] = X[1]; 216 if( 3. == X[1] ) // False parameter == variable 217 Y[2] = X[0]; 218 else Y[2] = X[1]; 219 if( 3. == X[0] ) // True parameter == variable 220 Y[3] = X[0]; 221 else Y[3] = X[1]; 222 if( X[0] == 4. ) // False variable == parameter 223 Y[4] = X[0]; 224 else Y[4] = X[1]; 225 if( X[1] == 4. ) // True variable == parameter 226 Y[5] = X[0]; 227 else Y[5] = X[1]; 228 229 // f : X -> Y 230 f = new ADFun<double> (X, Y); 231 232 // evaluate the function at new argument 233 y = f->Forward(0, x); 234 235 // check results 236 ok &= (y[0] == x[1]); // this is what the was taped 237 ok &= (y[1] == x[0]); 238 ok &= (y[2] == x[1]); 239 ok &= (y[3] == x[0]); 240 ok &= (y[4] == x[1]); 241 ok &= (y[5] == x[0]); 242 // the first two comparisions do not change 243 ok &= (f->CompareChange() == 4); 244 245 // done with this function 246 delete f; 247 248 // ------------------------------- != ---------------------------- 249 // create independent variables 250 Independent(X); 251 252 if( X[0] != X[1] ) // True variable != variable 253 Y[0] = X[0]; 254 else Y[0] = X[1]; 255 if( X[0] != X[0] ) // False variable != variable 256 Y[1] = X[0]; 257 else Y[1] = X[1]; 258 if( 3. != X[1] ) // True parameter != variable 259 Y[2] = X[0]; 260 else Y[2] = X[1]; 261 if( 3. != X[0] ) // False parameter != variable 262 Y[3] = X[0]; 263 else Y[3] = X[1]; 264 if( X[0] != 4. ) // True variable != parameter 265 Y[4] = X[0]; 266 else Y[4] = X[1]; 267 if( X[1] != 4. ) // False variable != parameter 268 Y[5] = X[0]; 269 else Y[5] = X[1]; 270 271 // f : X -> Y 272 f = new ADFun<double> (X, Y); 273 274 // evaluate the function at new argument 275 y = f->Forward(0, x); 276 277 // check results 278 ok &= (y[0] == x[0]); // this is what the was taped 279 ok &= (y[1] == x[1]); 280 ok &= (y[2] == x[0]); 281 ok &= (y[3] == x[1]); 282 ok &= (y[4] == x[0]); 283 ok &= (y[5] == x[1]); 284 // the first two comparisions do not change 285 ok &= (f->CompareChange() == 4); 286 287 // done with this function 288 delete f; 289 290 return ok; 291 } 292 // ---------------------------------------------------------------------- 293 template <typename Type> 294 Type Minimum(const Type &x, const Type &y) 295 { // Use a comparision to compute the min(x, y) 296 // (note that CondExp would never require retaping). 297 if( x < y ) 298 return x; 299 return y; 300 } 301 302 bool CompareChange_two(void) 303 { bool ok = true; 304 305 using CppAD::AD; 306 using CppAD::ADFun; 307 using CppAD::Independent; 308 309 // domain space vector 310 size_t n = 2; 311 CPPAD_TESTVECTOR(AD<double>) X(n); 312 X[0] = 3.; 313 X[1] = 4.; 314 315 // declare independent variables and start tape recording 316 CppAD::Independent(X); 317 318 // range space vector 319 size_t m = 1; 320 CPPAD_TESTVECTOR(AD<double>) Y(m); 321 Y[0] = Minimum(X[0], X[1]); 322 323 // create f: x -> y and stop tape recording 324 ADFun<double> f(X, Y); 325 326 // evaluate zero mode Forward where conditional has the same result 327 // note that f.CompareChange is not defined when NDEBUG is true 328 CPPAD_TESTVECTOR(double) x(n); 329 CPPAD_TESTVECTOR(double) y(m); 330 x[0] = 3.5; 331 x[1] = 4.; 332 y = f.Forward(0, x); 333 ok &= (y[0] == x[0]); 334 ok &= (y[0] == Minimum(x[0], x[1])); 335 ok &= (f.CompareChange() == 0); 336 337 // evaluate zero mode Forward where conditional has different result 338 x[0] = 4.; 339 x[1] = 3.; 340 y = f.Forward(0, x); 341 ok &= (y[0] == x[0]); 342 ok &= (y[0] != Minimum(x[0], x[1])); 343 ok &= (f.CompareChange() == 1); 344 345 // re-tape to obtain the new AD operation sequence 346 X[0] = 4.; 347 X[1] = 3.; 348 Independent(X); 349 Y[0] = Minimum(X[0], X[1]); 350 351 // stop tape and store result in f 352 f.Dependent(Y); 353 354 // evaluate the function at new argument values 355 y = f.Forward(0, x); 356 ok &= (y[0] == x[1]); 357 ok &= (y[0] == Minimum(x[0], x[1])); 358 ok &= (f.CompareChange() == 0); 359 360 return ok; 361 } 362 } 363 364 bool compare_change(void) 365 { bool ok = true; 366 ok &= CompareChange_one(); 367 ok &= CompareChange_two(); 290 368 return ok; 291 369 } 370 371 // END C++ -
trunk/test_more/optimize.cpp
r3507 r3607 1 1 /* $Id$ */ 2 2 /* -------------------------------------------------------------------------- 3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-1 3Bradley M. Bell3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell 4 4 5 5 CppAD is distributed under multiple licenses. This distribution is under … … 311 311 (const Vector& x, Vector& y, size_t& original, size_t& opt) 312 312 { typedef typename Vector::value_type Scalar; 313 Scalar a;313 Scalar not_used; 314 314 Scalar one(1), two(2), three(3), four(4); 315 original = 0; 316 opt = 0; 315 316 // independent variable and phantom at beginning 317 original = 1 + x.size(); 318 opt = 1 + x.size(); 317 319 318 320 // unary operator where operand is arg[0] 319 a = CppAD::abs(x[0]); 320 if( a < 1. ) 321 y[0] = sin(x[0]); 322 else y[0] = cos(x[0]); 321 // (note that sin corresponds to two tape variables) 322 not_used = CppAD::abs(x[0]); 323 y[0] = sin(x[0]); 323 324 original += 3; 324 325 opt += 2; … … 326 327 // binary operator where left operand is a variable 327 328 // and right operand is a parameter 328 a = x[1] + 2.; 329 if( a < 3. ) 330 y[1] = x[1] * 3.; 331 else y[1] = x[1] / 2.; 329 not_used = not_used + 2.; 330 y[1] = x[1] * 3.; 332 331 original += 2; 333 332 opt += 1; … … 335 334 // binary operator where left operand is a parameter 336 335 // and right operation is a variable 337 a = 2. - x[2]; 338 if( a < 4. ) 339 y[2] = 3. / x[2]; 340 else y[2] = 4. + x[2]; 336 not_used = 2. - not_used; 337 y[2] = 3. / x[2]; 341 338 original += 2; 342 339 opt += 1; 343 340 344 341 // binary operator where both operands are variables 345 a = x[3] - x[2]; 346 if( a < 4. ) 347 y[3] = x[3] / x[2]; 348 else y[3] = x[3] + x[2]; 342 not_used = x[3] - not_used; 343 y[3] = x[3] / x[2]; 349 344 original += 2; 350 345 opt += 1; 351 346 352 // this conditional expression that will be optimized out 353 a = CppAD::CondExpLt(x[0], x[1], x[2], x[3]); 354 // 1 of the following 2 conditional expressions will be kept 355 if( a < 5. ) 356 y[4] = CppAD::CondExpLt(x[4], one, two, three); 357 else y[4] = CppAD::CondExpLt(x[4], two, three, four); 358 original += 2; 347 // conditional expression that will be optimized out 348 not_used = CppAD::CondExpLt(x[0], x[1], x[2], x[3]) + not_used; 349 y[4] = CppAD::CondExpLt(x[4], one, two, three); 350 original += 3; 359 351 opt += 1; 360 352 361 // Make sure that a parameter dependent variable 353 // y[5] does not depend on the value of not_used. 354 // Make sure a parameter, corresponding to a dependent variable, 362 355 // is not optimized out of the operation sequence. 363 // In addition, we do not use the argument x[5], to 364 // make sure it is not optimized out. 365 y[5] = 1.; 356 y[5] = 0.0 * not_used; 366 357 original += 1; 367 358 opt += 1; 359 360 // Wwe do not use the argument x[5], to 361 // make sure it is not optimized out. 368 362 369 363 return; … … 405 399 406 400 // Check size before optimization 407 ok &= F.size_var() == (n + 1 + original);401 ok &= F.size_var() == original; 408 402 409 403 // Optimize the operation sequence … … 411 405 412 406 // Check size after optimization 413 ok &= F.size_var() == (n + 1 + opt);407 ok &= F.size_var() == opt; 414 408 415 409 // check result now -
trunk/test_more/test_more.cpp
r3520 r3607 1 1 /* $Id$ */ 2 2 /* -------------------------------------------------------------------------- 3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-1 4Bradley M. Bell3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell 4 4 5 5 CppAD is distributed under multiple licenses. This distribution is under … … 34 34 extern bool checkpoint(void); 35 35 extern bool Compare(void); 36 extern bool CompareChange(void);36 extern bool compare_change(void); 37 37 extern bool CondExp(void); 38 38 extern bool CondExpAD(void); … … 145 145 ok &= Run( checkpoint, "checkpoint" ); 146 146 ok &= Run( Compare, "Compare" ); 147 ok &= Run( CompareChange, "CompareChange");147 ok &= Run( compare_change, "compare_change" ); 148 148 ok &= Run( CondExp, "CondExp" ); 149 149 ok &= Run( CondExpAD, "CondExpAD" );
Note: See TracChangeset
for help on using the changeset viewer.