CppAD: A C++ Algorithmic Differentiation Package
20130918
|
00001 /* $Id$ */ 00002 /* -------------------------------------------------------------------------- 00003 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell 00004 00005 CppAD is distributed under multiple licenses. This distribution is under 00006 the terms of the 00007 Eclipse Public License Version 1.0. 00008 00009 A copy of this license is included in the COPYING file of this distribution. 00010 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00011 -------------------------------------------------------------------------- */ 00012 00013 /* 00014 $begin link_poly$$ 00015 $spell 00016 poly 00017 bool 00018 CppAD 00019 ddp 00020 $$ 00021 00022 $index link_poly$$ 00023 $index polynomial, speed test$$ 00024 $index speed, test polynomial$$ 00025 $index test, polynomial speed$$ 00026 00027 $section Speed Testing Second Derivative of a Polynomial$$ 00028 00029 $head Prototype$$ 00030 $codei%extern bool link_poly( 00031 size_t %size% , 00032 size_t %repeat% , 00033 CppAD::vector<double> &%a% , 00034 CppAD::vector<double> &%z% , 00035 CppAD::vector<double> &%ddp 00036 ); 00037 %$$ 00038 00039 $head Purpose$$ 00040 Each $cref/package/speed_main/package/$$ 00041 must define a version of this routine as specified below. 00042 This is used by the $cref speed_main$$ program 00043 to run the corresponding speed and correctness tests. 00044 00045 $head Method$$ 00046 The same template routine $cref Poly$$ is used 00047 by the different AD packages. 00048 00049 $head Return Value$$ 00050 If this speed test is not yet 00051 supported by a particular $icode package$$, 00052 the corresponding return value for $code link_poly$$ 00053 should be $code false$$. 00054 00055 $head size$$ 00056 The argument $icode size$$ is the order of the polynomial 00057 (the number of coefficients in the polynomial). 00058 00059 $head repeat$$ 00060 The argument $icode repeat$$ is the number of different argument values 00061 that the second derivative (or just the polynomial) will be computed at. 00062 00063 $head a$$ 00064 The argument $icode a$$ is a vector with $icode%size%$$ elements. 00065 The input value of its elements does not matter. 00066 The output value of its elements is the coefficients of the 00067 polynomial that is differentiated 00068 ($th i$$ element is coefficient of order $icode i$$). 00069 00070 $head z$$ 00071 The argument $icode z$$ is a vector with one element. 00072 The input value of the element does not matter. 00073 The output of its element is the polynomial argument value 00074 were the last second derivative (or polynomial value) was computed. 00075 00076 $head ddp$$ 00077 The argument $icode ddp$$ is a vector with one element. 00078 The input value of its element does not matter. 00079 The output value of its element is the 00080 second derivative of the polynomial with respect to it's argument value. 00081 00082 $subhead double$$ 00083 In the case where $icode package$$ is $code double$$, 00084 the output value of the element of $icode ddp$$ 00085 is the polynomial value (the second derivative is not computed). 00086 00087 $end 00088 ----------------------------------------------------------------------------- 00089 */ 00090 # include <cppad/vector.hpp> 00091 # include <cppad/poly.hpp> 00092 # include <cppad/near_equal.hpp> 00093 00094 extern bool link_poly( 00095 size_t size , 00096 size_t repeat , 00097 CppAD::vector<double> &a , 00098 CppAD::vector<double> &z , 00099 CppAD::vector<double> &ddp 00100 ); 00101 bool available_poly(void) 00102 { size_t size = 10; 00103 size_t repeat = 1; 00104 CppAD::vector<double> a(size), z(1), ddp(1); 00105 00106 return link_poly(size, repeat, a, z, ddp); 00107 } 00108 bool correct_poly(bool is_package_double) 00109 { size_t size = 10; 00110 size_t repeat = 1; 00111 CppAD::vector<double> a(size), z(1), ddp(1); 00112 00113 link_poly(size, repeat, a, z, ddp); 00114 00115 size_t k; 00116 double check; 00117 if( is_package_double ) 00118 k = 0; 00119 else k = 2; 00120 check = CppAD::Poly(k, a, z[0]); 00121 00122 bool ok = CppAD::NearEqual(check, ddp[0], 1e-10, 1e-10); 00123 return ok; 00124 } 00125 void speed_poly(size_t size, size_t repeat) 00126 { CppAD::vector<double> a(size), z(1), ddp(1); 00127 00128 link_poly(size, repeat, a, z, ddp); 00129 return; 00130 }