Sacado Package Browser (Single Doxygen Collection) Version of the Day
tradoptest_46.cpp
Go to the documentation of this file.
00001 
00002 
00003 /* Try to test all combinations of types and operations */
00004 
00005 
00006 
00007 #define ADT_RAD Sacado::Rad::
00008 
00009 
00010 
00011 #include "Sacado_trad.hpp"
00012 
00013 #include <cstdio>
00014 
00015 using std::printf;
00016 
00017 
00018 
00019 typedef ADT_RAD IndepADvar<double> AI;
00020 
00021 typedef ADT_RAD ADvar<double> A;
00022 
00023 typedef ADT_RAD ConstADvar<double> C;
00024 
00025 typedef ADT_RAD ADvari<double> Ai;
00026 
00027 typedef const ADT_RAD IndepADvar<double> cAI;
00028 
00029 typedef const ADT_RAD ADvar<double> cA;
00030 
00031 typedef const ADT_RAD ConstADvar<double> cC;
00032 
00033 typedef const ADT_RAD ADvari<double> cAi;
00034 
00035 static int rc;
00036 
00037 
00038 
00039 /* This is to be run through an awk program that changes lines */
00040 
00041 /* with "BINTEST" or "UNOPTEST" at the beginning of the line into */
00042 
00043 /* a the desired C++ (which we can then inspect). */
00044 
00045 
00046 
00047  void
00048 
00049 botch(const char *what, double wanted, double got)
00050 
00051 {
00052 
00053   printf("%s: expected %g, got %g, diff = %.2g\n", what, wanted, got, wanted-got);
00054 
00055   rc = 1;
00056 
00057   }
00058 
00059 
00060 
00061  const double tol = 5e-16;
00062 
00063 
00064 
00065  int
00066 
00067 differ(double a, double b)
00068 
00069 {
00070 
00071   double d = a - b;
00072 
00073   if (d < 0.)
00074 
00075     d = -d;
00076 
00077   if (a < 0.)
00078 
00079     a = -a;
00080 
00081   if (b < 0.)
00082 
00083     b = -b;
00084 
00085   if (a < b)
00086 
00087     a = b;
00088 
00089   if (a > 0.)
00090 
00091     d /= a;
00092 
00093   return d > tol;
00094 
00095   }
00096 
00097 
00098 
00099 #ifndef RAD_EQ_ALIAS
00100 
00101 #define Plus_dx 1.
00102 
00103 #else
00104 
00105 #ifdef RAD_AUTO_AD_Const
00106 
00107 #define Plus_dx 1.
00108 
00109 #else
00110 
00111 #define Plus_dx 0.
00112 
00113 #endif
00114 
00115 #endif
00116 
00117 
00118 
00119  int
00120 
00121 main(void)
00122 
00123 {
00124 
00125   AI xAI, yAI;
00126 
00127   A fA, xA, yA;
00128 
00129   C xC, yC;
00130 
00131   double dx, dy, f, xd, yd;
00132 
00133   long xL, yL;
00134 
00135   int xi, yi;
00136 
00137 
00138 
00139   rc = 0;
00140 
00141 
00142   /**** Test of atan ****/
00143 
00144   xd = 2.; f = atan(2.); dx = 0.2;
00145   xAI = xd;
00146   fA = atan(xAI);
00147   A::Gradcomp();
00148   if (differ(fA.val(), f)) botch("fA = atan(xAI)", f, fA.val());
00149   else if (differ(xAI.adj(), dx)) botch("d atan(xAI)/dx", dx, xAI.adj());
00150   {
00151   A::aval_reset();
00152   cAI xcAI(xd);
00153   fA = atan(xcAI);
00154   A::Gradcomp();
00155   if (differ(fA.val(), f)) botch("fA = atan(xcAI)", f, fA.val());
00156   else if (differ(xcAI.adj(), dx)) botch("d atan(xcAI)/dx", dx, xcAI.adj());
00157   }
00158   xA = xd;
00159   fA = atan(xA);
00160   A::Gradcomp();
00161   if (differ(fA.val(), f)) botch("fA = atan(xA)", f, fA.val());
00162   else if (differ(xA.adj(), dx)) botch("d atan(xA)/dx", dx, xA.adj());
00163   {
00164   A::aval_reset();
00165   cA xcA(xd);
00166   fA = atan(xcA);
00167   A::Gradcomp();
00168   if (differ(fA.val(), f)) botch("fA = atan(xcA)", f, fA.val());
00169   else if (differ(xcA.adj(), dx)) botch("d atan(xcA)/dx", dx, xcA.adj());
00170   }
00171   xC = xd;
00172   fA = atan(xC);
00173   A::Gradcomp();
00174   if (differ(fA.val(), f)) botch("fA = atan(xC)", f, fA.val());
00175   else if (differ(xC.adj(), dx)) botch("d atan(xC)/dx", dx, xC.adj());
00176   {
00177   A::aval_reset();
00178   cC xcC(xd);
00179   fA = atan(xcC);
00180   A::Gradcomp();
00181   if (differ(fA.val(), f)) botch("fA = atan(xcC)", f, fA.val());
00182   else if (differ(xcC.adj(), dx)) botch("d atan(xcC)/dx", dx, xcC.adj());
00183   }
00184   {
00185   cAi xcAi(xd);
00186   fA = atan(xcAi);
00187   A::Gradcomp();
00188   if (differ(fA.val(), f)) botch("fA = atan(xcAi)", f, fA.val());
00189   else if (differ(xcAi.aval, dx)) botch("d atan(xcAi)/dx", dx, xcAi.aval);
00190   }
00191   {
00192   A::aval_reset();
00193   cAi xcAi(xd);
00194   fA = atan(xcAi);
00195   A::Gradcomp();
00196   if (differ(fA.val(), f)) botch("fA = atan(xcAi)", f, fA.val());
00197   else if (differ(xcAi.aval, dx)) botch("d atan(xcAi)/dx", dx, xcAi.aval);
00198   }
00199 
00200 
00201   if (!rc) // chatter for cppunit test, which cannot tolerate silence
00202 
00203     printf("OK\n");
00204 
00205   return rc;
00206 
00207   }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines