You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/06/01 02:52:01 UTC

[66/94] [abbrv] incubator-joshua git commit: wrapping some debugging calls in boolean checks for speed

wrapping some debugging calls in boolean checks for speed


Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/ee9f06ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/ee9f06ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/ee9f06ad

Branch: refs/heads/master
Commit: ee9f06ade232a27f1553f540897dda2e1ccc37a0
Parents: 1aba8ae
Author: Matt Post <po...@cs.jhu.edu>
Authored: Thu May 26 20:33:59 2016 -0400
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Thu May 26 20:33:59 2016 -0400

----------------------------------------------------------------------
 .../joshua/decoder/chart_parser/Chart.java      | 29 +++++++++++++-------
 .../decoder/chart_parser/ComputeNodeResult.java | 24 ++++++++++------
 .../joshua/decoder/chart_parser/DotChart.java   |  1 +
 3 files changed, 36 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/ee9f06ad/src/main/java/org/apache/joshua/decoder/chart_parser/Chart.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/chart_parser/Chart.java b/src/main/java/org/apache/joshua/decoder/chart_parser/Chart.java
index 6fb3782..c2f009d 100644
--- a/src/main/java/org/apache/joshua/decoder/chart_parser/Chart.java
+++ b/src/main/java/org/apache/joshua/decoder/chart_parser/Chart.java
@@ -563,7 +563,8 @@ public class Chart {
     for (int width = 1; width <= sourceLength; width++) {
       for (int i = 0; i <= sourceLength - width; i++) {
         int j = i + width;
-        LOG.debug("Processing span ({}, {})", i, j);
+        if (LOG.isDebugEnabled())
+          LOG.debug("Processing span ({}, {})", i, j);
 
         /* Skips spans for which no path exists (possible in lattices). */
         if (inputLattice.distance(i, j) == Float.POSITIVE_INFINITY) {
@@ -575,7 +576,8 @@ public class Chart {
          * rules over (i,j-1) that need the terminal at (j-1,j) and looking at
          * all split points k to expand nonterminals.
          */
-        LOG.debug("Expanding cell");
+        if (LOG.isDebugEnabled())
+          LOG.debug("Expanding cell");
         for (int k = 0; k < this.grammars.length; k++) {
           /**
            * Each dotChart can act individually (without consulting other
@@ -589,17 +591,20 @@ public class Chart {
          * 2. The regular CKY part: add completed items onto the chart via cube
          * pruning.
          */
-        LOG.debug("Adding complete items into chart");
+        if (LOG.isDebugEnabled())
+          LOG.debug("Adding complete items into chart");
         completeSpan(i, j);
 
         /* 3. Process unary rules. */
-        LOG.debug("Adding unary items into chart");
+        if (LOG.isDebugEnabled())
+          LOG.debug("Adding unary items into chart");
         addUnaryNodes(this.grammars, i, j);
 
         // (4)=== in dot_cell(i,j), add dot-nodes that start from the /complete/
         // superIterms in
         // chart_cell(i,j)
-        LOG.debug("Initializing new dot-items that start from complete items in this cell");
+        if (LOG.isDebugEnabled())
+          LOG.debug("Initializing new dot-items that start from complete items in this cell");
         for (int k = 0; k < this.grammars.length; k++) {
           if (this.grammars[k].hasRuleForSpan(i, j, inputLattice.distance(i, j))) {
             this.dotcharts[k].startDotItems(i, j);
@@ -629,7 +634,8 @@ public class Chart {
       return null;
     }
 
-    LOG.debug("Finished expand");
+    if (LOG.isDebugEnabled())
+      LOG.debug("Finished expand");
     return new HyperGraph(this.goalBin.getSortedNodes().get(0), -1, -1, this.sentence);
   }
 
@@ -655,8 +661,9 @@ public class Chart {
   // ===============================================================
 
   private void logStatistics() {
-    LOG.debug("Input {}: Chart: added {} merged {} dot-items added: {}",
-        this.sentence.id(), this.nAdded, this.nMerged, this.nDotitemAdded);
+    if (LOG.isDebugEnabled())
+      LOG.debug("Input {}: Chart: added {} merged {} dot-items added: {}",
+          this.sentence.id(), this.nAdded, this.nMerged, this.nDotitemAdded);
   }
 
   /**
@@ -680,7 +687,8 @@ public class Chart {
     ArrayList<HGNode> queue = new ArrayList<HGNode>(chartBin.getSortedNodes());
     HashSet<Integer> seen_lhs = new HashSet<Integer>();
 
-    LOG.debug("Adding unary to [{}, {}]", i, j);
+    if (LOG.isDebugEnabled())
+      LOG.debug("Adding unary to [{}, {}]", i, j);
 
     while (queue.size() > 0) {
       HGNode node = queue.remove(0);
@@ -709,7 +717,8 @@ public class Chart {
             HGNode resNode = chartBin.addHyperEdgeInCell(states, rule, i, j, antecedents,
                 new SourcePath(), true);
 
-            LOG.debug("{}", rule);
+            if (LOG.isDebugEnabled())
+              LOG.debug("{}", rule);
             if (null != resNode && !seen_lhs.contains(resNode.lhs)) {
               queue.add(resNode);
               qtyAdditionsToQueue++;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/ee9f06ad/src/main/java/org/apache/joshua/decoder/chart_parser/ComputeNodeResult.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/chart_parser/ComputeNodeResult.java b/src/main/java/org/apache/joshua/decoder/chart_parser/ComputeNodeResult.java
index 084df13..9833734 100644
--- a/src/main/java/org/apache/joshua/decoder/chart_parser/ComputeNodeResult.java
+++ b/src/main/java/org/apache/joshua/decoder/chart_parser/ComputeNodeResult.java
@@ -77,8 +77,11 @@ public class ComputeNodeResult {
     // The total Viterbi cost of this edge. This is the Viterbi cost of the tail nodes, plus
     // whatever costs we incur applying this rule to create a new hyperedge.
     float viterbiCost = 0.0f;
-    LOG.debug("ComputeNodeResult():");
-    LOG.debug("-> RULE {}", rule);
+    
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("ComputeNodeResult():");
+      LOG.debug("-> RULE {}", rule);
+    }
 
     /*
      * Here we sum the accumulated cost of each of the tail nodes. The total cost of the new
@@ -88,8 +91,10 @@ public class ComputeNodeResult {
      */
     if (null != tailNodes) {
       for (HGNode item : tailNodes) {
-        LOG.debug("-> item.bestedge: {}", item);
-        LOG.debug("-> TAIL NODE {}", item);
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("-> item.bestedge: {}", item);
+          LOG.debug("-> TAIL NODE {}", item);
+        }
         viterbiCost += item.bestHyperedge.getBestDerivationScore();
       }
     }
@@ -113,9 +118,11 @@ public class ComputeNodeResult {
       transitionCost += acc.getScore();
 
 
-      LOG.debug("FEATURE {} = {} * {} = {}", feature.getName(),
-          acc.getScore() / Decoder.weights.getSparse(feature.getName()),
-          Decoder.weights.getSparse(feature.getName()), acc.getScore());
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("FEATURE {} = {} * {} = {}", feature.getName(),
+            acc.getScore() / Decoder.weights.getSparse(feature.getName()),
+            Decoder.weights.getSparse(feature.getName()), acc.getScore());
+      }
 
       if (feature.isStateful()) {
         futureCostEstimate += feature.estimateFutureCost(rule, newState, sentence);
@@ -123,7 +130,8 @@ public class ComputeNodeResult {
       }
     }
     viterbiCost += transitionCost;
-    LOG.debug("-> COST = {}", transitionCost);
+    if (LOG.isDebugEnabled())
+      LOG.debug("-> COST = {}", transitionCost);
     // Set the final results.
     this.pruningCostEstimate = viterbiCost + futureCostEstimate;
     this.viterbiCost = viterbiCost;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/ee9f06ad/src/main/java/org/apache/joshua/decoder/chart_parser/DotChart.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/chart_parser/DotChart.java b/src/main/java/org/apache/joshua/decoder/chart_parser/DotChart.java
index 7d1479e..367ec94 100644
--- a/src/main/java/org/apache/joshua/decoder/chart_parser/DotChart.java
+++ b/src/main/java/org/apache/joshua/decoder/chart_parser/DotChart.java
@@ -171,6 +171,7 @@ class DotChart {
    * </ol>
    */
   void expandDotCell(int i, int j) {
+    if (LOG.isDebugEnabled())
       LOG.debug("Expanding dot cell ({}, {})", i, j);
 
     /*