Changeset 3666 for trunk/test_more
- Timestamp:
- Feb 28, 2015 11:54:17 AM (5 years ago)
- Location:
- trunk/test_more
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test_more/CMakeLists.txt
r3519 r3666 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 6 # the terms of the 6 # the terms of the 7 7 # Eclipse Public License Version 1.0. 8 8 # … … 10 10 # Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 11 11 # ----------------------------------------------------------------------------- 12 # Build the test_more directory tests 12 # Build the test_more directory tests 13 13 # Inherit environment from ../CMakeList.txt 14 14 15 # Specifies build type for this directory. Possible values are 15 # Specifies build type for this directory. Possible values are 16 16 # empty, Debug, Release, RelWithDebInfo and MinSizeRel 17 17 SET(CMAKE_BUILD_TYPE DEBUG) … … 36 36 IF ( eigen_prefix ) 37 37 # compile eigen library separately so can use different compiler flags 38 ADD_LIBRARY(test_more_eigen_lib EXCLUDE_FROM_ALL 38 ADD_LIBRARY(test_more_eigen_lib EXCLUDE_FROM_ALL 39 39 cppad_eigen.cpp 40 40 ) 41 41 # Adds -D define flags to the compilation of source files. 42 42 ADD_DEFINITIONS("-DCPPAD_EIGEN_TEST") 43 # Add other compiler flags 44 add_cppad_cxx_flags(test_more_eigen_lib) 43 # Add other compiler flags 44 add_cppad_cxx_flags(test_more_eigen_lib) 45 45 # 46 46 # Add eigen to list of libraries … … 54 54 # configure_file(InputFile OutputFile [COPYONLY] [ESCAPE_QUOTES] [@ONLY]) 55 55 CONFIGURE_FILE( 56 ${CMAKE_CURRENT_SOURCE_DIR}/test_one.sh.in 56 ${CMAKE_CURRENT_SOURCE_DIR}/test_one.sh.in 57 57 ${CMAKE_CURRENT_SOURCE_DIR}/test_one.sh 58 58 ) … … 82 82 cond_exp.cpp 83 83 cond_exp_ad.cpp 84 cond_exp_rev.cpp 84 85 copy.cpp 85 86 cos.cpp … … 141 142 vec_ad.cpp 142 143 vec_ad_par.cpp 143 vec_unary.cpp 144 vec_unary.cpp 144 145 ) 145 146 … … 148 149 149 150 # List of libraries to be linked into the specified target 150 TARGET_LINK_LIBRARIES(test_more 151 TARGET_LINK_LIBRARIES(test_more 151 152 ${colpack_libs} 152 ${adolc_libs} 153 ${adolc_libs} 153 154 ${ipopt_libs} 154 155 ${eigen_libs} -
trunk/test_more/cond_exp.cpp
r2893 r3666 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 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 Comprehensive test built on 08/07 for new user interface to CondExp 14 Comprehensive test built on 08/07 for new user interface to CondExp 15 15 */ 16 16 // BEGIN C++ … … 33 33 34 34 // parameter value 35 AD<double> one = 1.; 36 37 // dependent variable vector 35 AD<double> one = 1.; 36 37 // dependent variable vector 38 38 CPPAD_TESTVECTOR(AD<double>) Y(5); 39 39 … … 45 45 Y[4] = CondExpGt(one, X[0], X[1], X[2]); 46 46 47 // create f: X -> Y 47 // create f: X -> Y 48 48 ADFun<double> f(X, Y); 49 49 … … 63 63 ok &= Y[4] == X[1]; 64 64 65 // function values 65 // function values 66 66 v[0] = 2.; 67 67 v[1] = 1.; … … 95 95 ok &= (dv[1] == dw[0] + dw[1] ); 96 96 ok &= (dv[2] == dw[2] + dw[3] + dw[4] ); 97 97 98 98 return ok; 99 99 } … … 111 111 112 112 // parameter value 113 AD<double> one = 1.; 114 115 // dependent variable vector 113 AD<double> one = 1.; 114 115 // dependent variable vector 116 116 CPPAD_TESTVECTOR(AD<double>) Y(5); 117 117 … … 123 123 Y[4] = CondExpGt(X[0], one, X[1], X[2]); 124 124 125 // create f: X -> Y 125 // create f: X -> Y 126 126 ADFun<double> f(X, Y); 127 127 … … 141 141 ok &= Y[4] == X[2]; 142 142 143 // function values 143 // function values 144 144 v[0] = 2.; 145 145 v[1] = 1.; … … 173 173 ok &= (dv[1] == dw[3] + dw[4] ); 174 174 ok &= (dv[2] == dw[0] + dw[1] + dw[2] ); 175 175 176 176 return ok; 177 177 } … … 189 189 190 190 // parameter value 191 AD<double> three = 3.; 192 193 // dependent variable vector 191 AD<double> three = 3.; 192 193 // dependent variable vector 194 194 CPPAD_TESTVECTOR(AD<double>) Y(5); 195 195 … … 201 201 Y[4] = CondExpGt(X[0], X[1], three, X[2]); 202 202 203 // create f: X -> Y 203 // create f: X -> Y 204 204 ADFun<double> f(X, Y); 205 205 … … 219 219 ok &= Y[4] == X[2]; 220 220 221 // function values 221 // function values 222 222 v[0] = 2.; 223 223 v[1] = 1.; … … 251 251 ok &= (dv[1] == 0.); 252 252 ok &= (dv[2] == dw[0] + dw[1] + dw[2] ); 253 253 254 254 return ok; 255 255 } … … 267 267 268 268 // parameter value 269 AD<double> three = 3.; 270 271 // dependent variable vector 269 AD<double> three = 3.; 270 271 // dependent variable vector 272 272 CPPAD_TESTVECTOR(AD<double>) Y(5); 273 273 … … 279 279 Y[4] = CondExpGt(X[0], X[1], X[2], three); 280 280 281 // create f: X -> Y 281 // create f: X -> Y 282 282 ADFun<double> f(X, Y); 283 283 … … 297 297 ok &= Y[4] == three; 298 298 299 // function values 299 // function values 300 300 v[0] = 2.; 301 301 v[1] = 1.; … … 329 329 ok &= (dv[1] == 0.); 330 330 ok &= (dv[2] == dw[3] + dw[4] ); 331 331 332 332 return ok; 333 333 } … … 335 335 # include <limits> 336 336 bool SecondOrderReverse(void) 337 { // Bradley M. Bell 2009-07-04 337 { // Bradley M. Bell 2009-07-04 338 338 // Reverse mode for CExpOp was only modifying the highest order partial 339 339 // This test demonstrated the bug … … 352 352 353 353 AD<double> left = X[0]; 354 AD<double> right = X[0] * X[0]; 354 AD<double> right = X[0] * X[0]; 355 355 AD<double> exp_if_true = left; 356 356 AD<double> exp_if_false = right; … … 366 366 Z = CondExpGt(left, right, exp_if_true, exp_if_false); 367 367 Y[1] = Z * Z; 368 368 369 369 CppAD::ADFun<double> f(X, Y); 370 370 … … 384 384 // check first derivative in dw 385 385 double check = 2. * Value( X[0] ); 386 ok &= NearEqual(dw[0], check, eps, eps); 386 ok &= NearEqual(dw[0], check, eps, eps); 387 387 388 388 // check second derivative in dw 389 389 check = 2.; 390 ok &= NearEqual(dw[1], check, eps, eps); 390 ok &= NearEqual(dw[1], check, eps, eps); 391 391 392 392 // test exp_if_false case … … 398 398 // check first derivative in dw 399 399 check = 2. * Value( X[0] ); 400 ok &= NearEqual(dw[0], check, eps, eps); 400 ok &= NearEqual(dw[0], check, eps, eps); 401 401 402 402 // check second derivative in dw 403 403 check = 2.; 404 ok &= NearEqual(dw[1], check, eps, eps); 404 ok &= NearEqual(dw[1], check, eps, eps); 405 405 406 406 return ok; … … 415 415 using CppAD::AD; 416 416 using CppAD::NearEqual; 417 using CppAD::log; 417 using CppAD::log; 418 418 using CppAD::abs; 419 419 double eps = 100. * std::numeric_limits<double>::epsilon(); … … 445 445 } 446 446 447 // range space vector 447 // range space vector 448 448 size_t m = 1; 449 449 CPPAD_TESTVECTOR(AD<double>) Y(m); … … 455 455 // vectors for arguments to the function object f 456 456 CPPAD_TESTVECTOR(double) x(n); // argument values 457 CPPAD_TESTVECTOR(double) y(m); // function values 458 CPPAD_TESTVECTOR(double) w(m); // function weights 457 CPPAD_TESTVECTOR(double) y(m); // function values 458 CPPAD_TESTVECTOR(double) w(m); // function weights 459 459 CPPAD_TESTVECTOR(double) dw(n); // derivative of weighted function 460 460 … … 464 464 for(j = 0; j < n; j++) 465 465 { sign *= -1.; 466 x[j] = sign * double(j + 1); 466 x[j] = sign * double(j + 1); 467 467 check += log( abs( x[j] ) ); 468 468 } 469 469 470 // function value 470 // function value 471 471 y = f.Forward(0, x); 472 472 ok &= ( y[0] == check ); … … 477 477 for(j = 0; j < n; j++) 478 478 { if( x[j] > 0. ) 479 ok &= NearEqual(dw[j], 1./abs( x[j] ), eps, eps); 480 else ok &= NearEqual(dw[j], -1./abs( x[j] ), eps, eps); 479 ok &= NearEqual(dw[j], 1./abs( x[j] ), eps, eps); 480 else ok &= NearEqual(dw[j], -1./abs( x[j] ), eps, eps); 481 481 } 482 482 … … 485 485 for(j = 0; j < n; j++) 486 486 { sign *= -1.; 487 x[j] = sign * double(j); 487 x[j] = sign * double(j); 488 488 } 489 489 490 // function value 490 // function value 491 491 y = f.Forward(0, x); 492 492 ok &= ( y[0] == -Infinity(0.) ); … … 498 498 for(j = 0; j < n; j++) 499 499 { if( x[j] > 0. ) 500 ok &= NearEqual(dw[j], 1./abs( x[j] ), eps, eps); 500 ok &= NearEqual(dw[j], 1./abs( x[j] ), eps, eps); 501 501 else if( x[j] < 0. ) 502 ok &= NearEqual(dw[j], -1./abs( x[j] ), eps, eps); 502 ok &= NearEqual(dw[j], -1./abs( x[j] ), eps, eps); 503 503 else 504 { // in this case computing dw[j] ends up multiplying 505 // -infinity * zero and hence results in Nan 506 ok &= CppAD::isnan(dw[j]); 507 } 504 ok &= NearEqual(dw[j], 0.0, eps, eps); 508 505 } 509 506 510 507 return ok; 511 508 } -
trunk/test_more/makefile.am
r3519 r3666 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 6 # the terms of the 6 # the terms of the 7 7 # Eclipse Public License Version 1.0. 8 8 # … … 17 17 # ------------------------------------------------------------------------- 18 18 if CppAD_OPENMP 19 OPENMP_SRC_FILES = alloc_openmp.cpp 19 OPENMP_SRC_FILES = alloc_openmp.cpp 20 20 else 21 21 OPENMP_SRC_FILES = … … 23 23 # ------------------------------------------------------------------------- 24 24 if CppAD_ADOLC 25 ADOLC_SRC_FILES = base_adolc.cpp 25 ADOLC_SRC_FILES = base_adolc.cpp 26 26 ADOLC_EXTRA_FILES = 27 27 ADOLC_LIB = -ladolc -lColPack -L$(ADOLC_DIR)/lib -L$(ADOLC_DIR)/lib64 28 ADOLC_FLAGS = -DCPPAD_ADOLC_TEST -I$(ADOLC_DIR)/include 28 ADOLC_FLAGS = -DCPPAD_ADOLC_TEST -I$(ADOLC_DIR)/include 29 29 else 30 30 ADOLC_EXTRA_FILES = base_adolc.cpp … … 35 35 # ------------------------------------------------------------------------- 36 36 if CppAD_IPOPT 37 IPOPT_SRC_FILES = ipopt_solve.cpp 37 IPOPT_SRC_FILES = ipopt_solve.cpp 38 38 IPOPT_EXTRA_FILES = 39 39 IPOPT_LIB = -lipopt \ 40 40 $(CPPAD_IPOPT_LIBS) $(FCLIBS) $(PTHREAD_LIB) $(DL_LIB) 41 IPOPT_FLAGS = -DCPPAD_IPOPT_TEST -I$(IPOPT_DIR)/include 41 IPOPT_FLAGS = -DCPPAD_IPOPT_TEST -I$(IPOPT_DIR)/include 42 42 else 43 43 IPOPT_EXTRA_FILES = ipopt_solve.cpp … … 57 57 $(CXX_FLAGS_EIGEN) \ 58 58 -DCPPAD_EIGEN_TEST \ 59 -I$(EIGEN_DIR)/include 59 -I$(EIGEN_DIR)/include 60 60 else 61 61 EIGEN_EXTRA_FILES = cppad_eigen.cpp … … 78 78 $(ADOLC_FLAGS) \ 79 79 $(IPOPT_FLAGS) \ 80 $(OPENMP_FLAGS) 80 $(OPENMP_FLAGS) 81 81 # 82 82 AM_CXXFLAGS = -g $(ADOLC_FLAGS) $(IPOPT_FLAGS) $(CXX_FLAGS) 83 83 # 84 AM_LDFLAGS = $(OPENMP_FLAGS) 85 LDADD = $(ADOLC_LIB) $(IPOPT_LIB) $(EIGEN_LIB) $(OPENMP_FLAGS) 84 AM_LDFLAGS = $(OPENMP_FLAGS) 85 LDADD = $(ADOLC_LIB) $(IPOPT_LIB) $(EIGEN_LIB) $(OPENMP_FLAGS) 86 86 # 87 87 test_more_SOURCES = \ … … 107 107 cond_exp.cpp \ 108 108 cond_exp_ad.cpp \ 109 cond_exp_rev.cpp \ 109 110 copy.cpp \ 110 111 cos.cpp \ … … 167 168 vec_ad.cpp \ 168 169 vec_ad_par.cpp \ 169 vec_unary.cpp 170 vec_unary.cpp 170 171 171 172 test: check -
trunk/test_more/makefile.in
r3650 r3666 107 107 atan2.cpp base_alloc.cpp check_simple_vector.cpp \ 108 108 checkpoint.cpp compare.cpp compare_change.cpp cond_exp.cpp \ 109 cond_exp_ad.cpp co py.cpp cos.cpp cosh.cpp dbl_epsilon.cpp \110 d iv.cpp div_eq.cpp div_zero_one.cpp erf.cpp exp.cpp \111 ex tern_value.cpp extern_value.hpp for_hess.cpp \109 cond_exp_ad.cpp cond_exp_rev.cpp copy.cpp cos.cpp cosh.cpp \ 110 dbl_epsilon.cpp div.cpp div_eq.cpp div_zero_one.cpp erf.cpp \ 111 exp.cpp extern_value.cpp extern_value.hpp for_hess.cpp \ 112 112 for_sparse_jac.cpp forward.cpp forward_dir.cpp \ 113 113 forward_order.cpp from_base.cpp fun_check.cpp jacobian.cpp \ … … 133 133 checkpoint.$(OBJEXT) compare.$(OBJEXT) \ 134 134 compare_change.$(OBJEXT) cond_exp.$(OBJEXT) \ 135 cond_exp_ad.$(OBJEXT) co py.$(OBJEXT) cos.$(OBJEXT) \136 cos h.$(OBJEXT) dbl_epsilon.$(OBJEXT) div.$(OBJEXT) \137 div _eq.$(OBJEXT) div_zero_one.$(OBJEXT) erf.$(OBJEXT) \138 e xp.$(OBJEXT) extern_value.$(OBJEXT) for_hess.$(OBJEXT) \139 for_ sparse_jac.$(OBJEXT) forward.$(OBJEXT) \135 cond_exp_ad.$(OBJEXT) cond_exp_rev.$(OBJEXT) copy.$(OBJEXT) \ 136 cos.$(OBJEXT) cosh.$(OBJEXT) dbl_epsilon.$(OBJEXT) \ 137 div.$(OBJEXT) div_eq.$(OBJEXT) div_zero_one.$(OBJEXT) \ 138 erf.$(OBJEXT) exp.$(OBJEXT) extern_value.$(OBJEXT) \ 139 for_hess.$(OBJEXT) for_sparse_jac.$(OBJEXT) forward.$(OBJEXT) \ 140 140 forward_dir.$(OBJEXT) forward_order.$(OBJEXT) \ 141 141 from_base.$(OBJEXT) fun_check.$(OBJEXT) jacobian.$(OBJEXT) \ … … 491 491 cond_exp.cpp \ 492 492 cond_exp_ad.cpp \ 493 cond_exp_rev.cpp \ 493 494 copy.cpp \ 494 495 cos.cpp \ … … 630 631 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cond_exp.Po@am__quote@ 631 632 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cond_exp_ad.Po@am__quote@ 633 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cond_exp_rev.Po@am__quote@ 632 634 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/copy.Po@am__quote@ 633 635 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cos.Po@am__quote@ -
trunk/test_more/test_more.cpp
r3646 r3666 37 37 extern bool CondExp(void); 38 38 extern bool CondExpAD(void); 39 extern bool cond_exp_rev(void); 39 40 extern bool copy(void); 40 41 extern bool Cos(void); … … 148 149 ok &= Run( CondExp, "CondExp" ); 149 150 ok &= Run( CondExpAD, "CondExpAD" ); 151 ok &= Run( cond_exp_rev, "cond_exp_rev" ); 150 152 ok &= Run( copy, "copy" ); 151 153 ok &= Run( Cos, "Cos" );
Note: See TracChangeset
for help on using the changeset viewer.