From e77e6e3b008ba7f925d796c80579043e1343b3e4 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Tue, 13 Sep 2011 14:06:49 +0200
Subject: [PATCH] Only compute some scalar products once

---
 src/samplefunctional.hh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/samplefunctional.hh b/src/samplefunctional.hh
index 6f7033f9..28188fdb 100644
--- a/src/samplefunctional.hh
+++ b/src/samplefunctional.hh
@@ -46,17 +46,19 @@ class SampleFunctional {
 
     SmallVector const pg = upperGradient(x);
     SmallVector const mg = lowerGradient(x);
+    double const pgx = pg * x;
+    double const mgx = mg * x;
     // TODO: collinearity checks suck
-    if (pg * x == pg.two_norm() * x.two_norm() &&
-        -(mg * x) == mg.two_norm() * x.two_norm()) {
+    if (pgx == pg.two_norm() * x.two_norm() &&
+        -mgx == mg.two_norm() * x.two_norm()) {
       ret = SmallVector(0.0);
       return;
-    } else if (pg * x >= 0 && mg * x >= 0) {
+    } else if (pgx >= 0 && mgx >= 0) {
       ret = pg;
       Dune::dverb << "## Directional derivative (as per scalar product w/ "
                      "semigradient): " << -(ret * mg)
                   << " (coordinates of the restriction)" << std::endl;
-    } else if (pg * x <= 0 && mg * x <= 0) {
+    } else if (pgx <= 0 && mgx <= 0) {
       ret = mg;
       Dune::dverb << "## Directional derivative (as per scalar product w/ "
                      "semigradient): " << -(ret * pg)
-- 
GitLab