Login  Register

Re: Compilation problems with SUN CC

Posted by Andreas Spengler-2 on Feb 20, 2009; 4:03pm
URL: http://quantlib.414.s1.nabble.com/Compilation-problems-with-SUN-CC-tp12581p12585.html

Hi Luigi,

I looked up "function pointer template" with google and ended up at
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.cpp/2004-03/3445.html,
which basically states "what do you need the function pointer template
for"?

;-)

So I tried passing the function pointers as arguments, which gets compiled
now:

*** alphafinder.cpp.orig        Fri Feb 20 15:57:37 2009
--- alphafinder.cpp     Fri Feb 20 16:56:25 2009
***************
*** 25,36 ****
  namespace
  {

!     template<class T, Real (T::*Value)(Real) >
      Real Bisection(Real target,
                     Real low,
                     Real high,
                     Real tolerance,
!                    T& theObject) {

          Real x=0.5*(low+high);
          Real y=(theObject.*Value)(x);
--- 25,37 ----
  namespace
  {

!     template<class T>
      Real Bisection(Real target,
                     Real low,
                     Real high,
                     Real tolerance,
!                    T& theObject,
!                    Real (T::*Value)(Real)) {

          Real x=0.5*(low+high);
          Real y=(theObject.*Value)(x);
***************
*** 41,56 ****

              x = 0.5*(low+high);
              y = (theObject.*Value)(x);
!         } while ((fabs(high-low) > tolerance));

          return x;
      }

!     template<class T, bool (T::*Value)(Real) >
      Real FindHighestOK(Real low,
                         Real high,
                         Real tolerance,
!                        T& theObject) {

          Real x=0.5*(low+high);
          bool ok=(theObject.*Value)(x);
--- 42,58 ----

              x = 0.5*(low+high);
              y = (theObject.*Value)(x);
!         } while ((std::fabs(high-low) > tolerance));

          return x;
      }

!     template<class T>
      Real FindHighestOK(Real low,
                         Real high,
                         Real tolerance,
!                        T& theObject,
!                        bool (T::*Value)(Real)) {

          Real x=0.5*(low+high);
          bool ok=(theObject.*Value)(x);
***************
*** 61,76 ****

              x = 0.5*(low+high);
              ok = (theObject.*Value)(x);
!         } while ((fabs(high-low) > tolerance));

          return x;
      }

!     template<class T, bool (T::*Value)(Real) >
      Real FindLowestOK(Real low,
                        Real high,
                        Real tolerance,
!                       T& theObject) {

          Real x=0.5*(low+high);
          bool ok=(theObject.*Value)(x);
--- 63,79 ----

              x = 0.5*(low+high);
              ok = (theObject.*Value)(x);
!         } while ((std::fabs(high-low) > tolerance));

          return x;
      }

!     template<class T>
      Real FindLowestOK(Real low,
                        Real high,
                        Real tolerance,
!                       T& theObject,
!                       bool (T::*Value)(Real)) {

          Real x=0.5*(low+high);
          bool ok=(theObject.*Value)(x);
***************
*** 81,102 ****

              x = 0.5*(low+high);
              ok = (theObject.*Value)(x);
!         } while ( (fabs(high-low) > tolerance) );

          return x;
      }


!     template<class T, Real (T::*Value)(Real),  bool (T::*Condition)(Real) >
      Real Minimize(Real low,
                    Real high,
                    Real tolerance,
                    T& theObject,
                    bool& failed) {

          Real leftValue = (theObject.*Value)(low);
          Real rightValue = (theObject.*Value)(high);
!         Real W = 0.5*(3.0-sqrt(5.0));
          Real x=W*low+(1-W)*high;
          Real midValue =  (theObject.*Value)(x);

--- 84,107 ----

              x = 0.5*(low+high);
              ok = (theObject.*Value)(x);
!         } while ( (std::fabs(high-low) > tolerance) );

          return x;
      }


!     template<class T>
      Real Minimize(Real low,
                    Real high,
                    Real tolerance,
                    T& theObject,
+                   Real (T::*Value)(Real),
+                   bool (T::*Condition)(Real),
                    bool& failed) {

          Real leftValue = (theObject.*Value)(low);
          Real rightValue = (theObject.*Value)(high);
!         Real W = 0.5*(3.0-std::sqrt(5.0));
          Real x=W*low+(1-W)*high;
          Real midValue =  (theObject.*Value)(x);

***************
*** 379,398 ****
          if (bottomValue <= targetVariance) {
              // then find root of increasing function
              // (or as if increasing function)
!             alpha = Bisection<AlphaFinder,
&AlphaFinder::valueAtTurningPoint>(
!                                                             targetVariance,
!                                                             bottomAlpha,
!                                                             bilimit,
!                                                             tolerance,
!                                                             *this);
          } else {
              // find root of decreasing function (or as if decreasing
function)
!             alpha=Bisection<AlphaFinder,
&AlphaFinder::minusValueAtTurningPoint>(
!                                                            
-targetVariance,
!                                                             bilimit,
!                                                             topAlpha,
!                                                             tolerance,
!                                                             *this);
          }
          finalPart(alpha,
                    stepindex,
--- 384,405 ----
          if (bottomValue <= targetVariance) {
              // then find root of increasing function
              // (or as if increasing function)
!             alpha = Bisection<AlphaFinder>(
!                                            targetVariance,
!                                            bottomAlpha,
!                                            bilimit,
!                                            tolerance,
!                                            *this,
!                                          
&AlphaFinder::valueAtTurningPoint);
          } else {
              // find root of decreasing function (or as if decreasing
function)
!             alpha=Bisection<AlphaFinder>(
!                                          -targetVariance,
!                                          bilimit,
!                                          topAlpha,
!                                          tolerance,
!                                          *this,
!                                        
&AlphaFinder::minusValueAtTurningPoint);
          }
          finalPart(alpha,
                    stepindex,
***************
*** 460,477 ****
                  // lower alpha is bad
                  if (alpha0OK) {
                      // must die somewhere in between
!                     alpha1 = FindLowestOK<AlphaFinder,
&AlphaFinder::testIfSolutionExists>(
                           alphaMin,
                           alpha0,
                           tolerance,
!                         *this);
                  } else {
                      // alphaMaxOK must be true to get here
!                     alpha1 = FindLowestOK<AlphaFinder,
&AlphaFinder::testIfSolutionExists>(
                           alpha0,
                           alphaMax,
                           tolerance,
!                         *this);
                  }
              }

--- 467,486 ----
                  // lower alpha is bad
                  if (alpha0OK) {
                      // must die somewhere in between
!                     alpha1 = FindLowestOK<AlphaFinder>(
                           alphaMin,
                           alpha0,
                           tolerance,
!                         *this,
!                          &AlphaFinder::testIfSolutionExists);
                  } else {
                      // alphaMaxOK must be true to get here
!                     alpha1 = FindLowestOK<AlphaFinder>(
                           alpha0,
                           alphaMax,
                           tolerance,
!                         *this,
!                          &AlphaFinder::testIfSolutionExists);
                  }
              }

***************
*** 478,488 ****

              if (!alphaMaxOK) {
                  // higher alpha is bad
!                 alpha2 = FindHighestOK<AlphaFinder,
&AlphaFinder::testIfSolutionExists>(
                       alpha1,
                       alphaMax,
                       tolerance,
!                      *this);
              } else
                  alpha2= alphaMax;
              }
--- 487,498 ----

              if (!alphaMaxOK) {
                  // higher alpha is bad
!                 alpha2 = FindHighestOK<AlphaFinder>(
                       alpha1,
                       alphaMax,
                       tolerance,
!                      *this,
!                      &AlphaFinder::testIfSolutionExists);
              } else
                  alpha2= alphaMax;
              }
***************
*** 507,524 ****

              if (foundUpOK) {
                  alpha1 = alphaUp;
!                 alpha2 = FindHighestOK<AlphaFinder,
&AlphaFinder::testIfSolutionExists>(
                       alpha1,
                       alphaMax,
                       tolerance,
!                      *this);
              } else {
                  alpha2 = alphaDown;
!                 alpha1 = FindLowestOK<AlphaFinder,
&AlphaFinder::testIfSolutionExists>(
                       alphaMin,
                       alpha2,
                       tolerance,
!                     *this);
              }
          }

--- 517,536 ----

              if (foundUpOK) {
                  alpha1 = alphaUp;
!                 alpha2 = FindHighestOK<AlphaFinder>(
                       alpha1,
                       alphaMax,
                       tolerance,
!                      *this,
!                      &AlphaFinder::testIfSolutionExists);
              } else {
                  alpha2 = alphaDown;
!                 alpha1 = FindLowestOK<AlphaFinder>(
                       alphaMin,
                       alpha2,
                       tolerance,
!                     *this,
!                      &AlphaFinder::testIfSolutionExists);
              }
          }

***************
*** 525,535 ****
          // we have now found alpha1, alpha2 such that solution exists
          // at endpoints. we now want to minimize within that interval
          bool failed;
!         alpha =  Minimize<AlphaFinder, &AlphaFinder::homogeneityfailure,
&AlphaFinder::testIfSolutionExists>(
                                          alpha1,
                                          alpha2,
                                          tolerance,
                                          *this,
                                          failed) ;

          finalPart(alpha,
--- 537,549 ----
          // we have now found alpha1, alpha2 such that solution exists
          // at endpoints. we now want to minimize within that interval
          bool failed;
!         alpha =  Minimize<AlphaFinder>(
                                          alpha1,
                                          alpha2,
                                          tolerance,
                                          *this,
+                                         &AlphaFinder::homogeneityfailure,
+                                         &AlphaFinder::testIfSolutionExists,
                                          failed) ;

          finalPart(alpha,
---------------------------------------------------------------------------

Rgds,

Andreas


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev