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

Generated on Wed May 12 21:39:42 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7