From a1823d673d5e9a366dfa6af855f3cb43160a90fb Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 7 Sep 2011 16:21:16 +0200
Subject: [PATCH] Use the pseudo directional derivative

In most cases (x != 0) this is a lot faster than normalising the direction and computing the actual directional derivative
---
 src/bisection-example-flexible.cc | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/bisection-example-flexible.cc b/src/bisection-example-flexible.cc
index a3d06cdf..75847a33 100644
--- a/src/bisection-example-flexible.cc
+++ b/src/bisection-example-flexible.cc
@@ -63,7 +63,7 @@ class SampleFunctional {
     while (true) {
       tmp = x;
       tmp.axpy(r, descDir);
-      if (directionalDerivative(tmp, descDir) >= 0)
+      if (pseudoDirectionalDerivative(tmp, descDir) >= 0)
         break;
 
       l = r;
@@ -91,12 +91,13 @@ class SampleFunctional {
       middle = descDir;
       middle *= m;
 
-      double derivative = directionalDerivative(x + middle, descDir);
+      double pseudoDerivative =
+          pseudoDirectionalDerivative(x + middle, descDir);
 
-      if (derivative < 0) {
+      if (pseudoDerivative < 0) {
         l = m;
         m = (m + r) / 2;
-      } else if (derivative > 0) {
+      } else if (pseudoDerivative > 0) {
         r = m;
         m = (l + m) / 2;
       } else
@@ -131,7 +132,9 @@ class SampleFunctional {
     return y;
   }
 
-  // |dir|-times the directional derivative wrt dir/|dir|.
+  // |dir|-times the directional derivative wrt dir/|dir|.  If only
+  // the sign of the directionalDerivative matters, this saves the
+  // cost of normalising.
   double pseudoDirectionalDerivative(const SmallVector x,
                                      const SmallVector dir) const {
     if (x == SmallVector(0.0))
-- 
GitLab