Changeset 3744 for trunk/test_more
 Timestamp:
 Nov 6, 2015 10:33:15 AM (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test_more/forward.cpp
r2570 r3744 1 1 /* $Id$ */ 2 2 /*  3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 20031 2Bradley M. Bell3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 200315 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 … … 25 25 using namespace CppAD; 26 26 27 // independent variable vector 27 // independent variable vector 28 28 CPPAD_TESTVECTOR(AD<double>) X(2); 29 X[0] = 0.; 29 X[0] = 0.; 30 30 X[1] = 1.; 31 31 Independent(X); … … 38 38 ADFun<double> F(X, Y); 39 39 40 // use zero order to evaluate F[ (3, 4) ] 40 // use zero order to evaluate F[ (3, 4) ] 41 41 VectorDouble x0( F.Domain() ); 42 42 VectorDouble y0( F.Range() ); … … 94 94 using namespace CppAD; 95 95 96 // independent variable vector 96 // independent variable vector 97 97 CPPAD_TESTVECTOR(AD<double>) U(3); 98 98 U[0] = 0.; U[1] = 1.; U[2] = 2.; … … 108 108 } 109 109 110 // dependent variable vector 110 // dependent variable vector 111 111 CPPAD_TESTVECTOR(AD<double>) V(2); 112 112 V[0] = sum; … … 146 146 147 147 // compare values 148 ok &= NearEqual(v1[0] , 148 ok &= NearEqual(v1[0] , 149 149 g0[0]*u1[0] + g0[1]*u1[1] + g0[2]*u1[2] , 1e10, 1e10); 150 ok &= NearEqual(v1[1] , 150 ok &= NearEqual(v1[1] , 151 151 g1[0]*u1[0] + g1[1]*u1[1] + g1[2]*u1[2] , 1e10, 1e10); 152 152 … … 156 156 CPPAD_TESTVECTOR(double) v2( f.Range() ); 157 157 p = 2; 158 u2[0] = .5; u2[1] = .4; u2[2] = .3; 158 u2[0] = .5; u2[1] = .4; u2[2] = .3; 159 159 v2 = f.Forward(p, u2); 160 160 … … 167 167 168 168 // compare values 169 ok &= NearEqual(v2[0] , 169 ok &= NearEqual(v2[0] , 170 170 g0[0]*u2[0] + g0[1]*u2[1] + g0[2]*u2[2] , 1e10, 1e10); 171 171 … … 173 173 double v2_1 = 0.; 174 174 for(i = 0; i < 3; i++) 175 { v2_1 += g1[i] * u2[i]; 175 { v2_1 += g1[i] * u2[i]; 176 176 for(j = 0; j < 3; j++) 177 177 v2_1 += .5 * u1[i] * H1[i * 3 + j] * u1[j]; … … 190 190 const char *msg ) 191 191 { // error hander must not return, so throw an exception 192 throw std::string(msg); 192 std::string message = msg; 193 throw message; 193 194 } 194 195 195 196 bool forward_nan(void) 196 { 197 { 197 198 198 199 using CppAD::vector; … … 219 220 } 220 221 catch( std::string msg ) 221 { // check that the message contains "nan" 222 ok = msg.find("nan") != std::string::npos; 223 } 224 225 return ok; 226 } 227 } // END empty namespace 222 { // check that the message contains 223 // "vector_size = " and "file_name = " 224 ok = msg.find("vector_size = ") != std::string::npos; 225 ok = msg.find("file_name = ") != std::string::npos; 226 } 227 228 return ok; 229 } 230 } // END empty namespace 228 231 229 232 # include <vector>
Note: See TracChangeset
for help on using the changeset viewer.