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/05/27 00:34:11 UTC
[05/32] incubator-joshua git commit: Removed a few unneeded
allocations
Removed a few unneeded allocations
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/74d166a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/74d166a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/74d166a6
Branch: refs/heads/JOSHUA-252
Commit: 74d166a680a18a877f6579144278f70f135de08b
Parents: 357f578
Author: Kellen Sunderland <ke...@amazon.com>
Authored: Wed Jan 27 10:15:48 2016 +0100
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Tue May 24 18:19:07 2016 +0200
----------------------------------------------------------------------
src/joshua/decoder/DecoderThread.java | 7 +++----
src/joshua/decoder/chart_parser/Chart.java | 2 +-
src/joshua/decoder/chart_parser/CubePruneState.java | 4 +---
src/joshua/decoder/hypergraph/HyperEdge.java | 11 ++---------
4 files changed, 7 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/74d166a6/src/joshua/decoder/DecoderThread.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/DecoderThread.java b/src/joshua/decoder/DecoderThread.java
index 4e2a15c..b1857cd 100644
--- a/src/joshua/decoder/DecoderThread.java
+++ b/src/joshua/decoder/DecoderThread.java
@@ -94,15 +94,14 @@ public class DecoderThread extends Thread {
*/
public Translation translate(Sentence sentence) {
- Decoder.LOG(1, String.format("Input %d: %s", sentence.id(), sentence.fullSource()));
+ Decoder.LOG(1, "Input " + sentence.id() + ", " + sentence.fullSource());
if (sentence.target() != null)
- Decoder.LOG(1, String.format("Input %d: Constraining to target sentence '%s'",
- sentence.id(), sentence.target()));
+ Decoder.LOG(1, "Input "+ sentence.id() +": Constraining to target sentence " + sentence.target());
// skip blank sentences
if (sentence.isEmpty()) {
- Decoder.LOG(1, String.format("Translation %d: Translation took 0 seconds", sentence.id()));
+ Decoder.LOG(1, "Translation " + sentence.id() + ": Translation took 0 seconds");
return new Translation(sentence, null, featureFunctions, joshuaConfiguration);
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/74d166a6/src/joshua/decoder/chart_parser/Chart.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/chart_parser/Chart.java b/src/joshua/decoder/chart_parser/Chart.java
index b10c013..b9b74de 100644
--- a/src/joshua/decoder/chart_parser/Chart.java
+++ b/src/joshua/decoder/chart_parser/Chart.java
@@ -359,7 +359,7 @@ public class Chart {
/* Use the updated ranks to assign the next rule and tail node. */
Rule nextRule = rules.get(nextRanks[0] - 1);
// HGNode[] nextAntNodes = new HGNode[state.antNodes.size()];
- List<HGNode> nextAntNodes = new ArrayList<HGNode>();
+ List<HGNode> nextAntNodes = new ArrayList<HGNode>(state.antNodes.size());
for (int x = 0; x < state.ranks.length - 1; x++)
nextAntNodes.add(superNodes.get(x).nodes.get(nextRanks[x + 1] - 1));
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/74d166a6/src/joshua/decoder/chart_parser/CubePruneState.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/chart_parser/CubePruneState.java b/src/joshua/decoder/chart_parser/CubePruneState.java
index c9ee8e6..b92f0a2 100644
--- a/src/joshua/decoder/chart_parser/CubePruneState.java
+++ b/src/joshua/decoder/chart_parser/CubePruneState.java
@@ -18,7 +18,6 @@
*/
package joshua.decoder.chart_parser;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,8 +40,7 @@ public class CubePruneState implements Comparable<CubePruneState> {
this.computeNodeResult = score;
this.ranks = ranks;
this.rules = rules;
- // create a new vector is critical, because currentAntecedents will change later
- this.antNodes = new ArrayList<HGNode>(antecedents);
+ this.antNodes = antecedents;
this.dotNode = dotNode;
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/74d166a6/src/joshua/decoder/hypergraph/HyperEdge.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/hypergraph/HyperEdge.java b/src/joshua/decoder/hypergraph/HyperEdge.java
index 114908e..f28fff1 100644
--- a/src/joshua/decoder/hypergraph/HyperEdge.java
+++ b/src/joshua/decoder/hypergraph/HyperEdge.java
@@ -41,7 +41,7 @@ public class HyperEdge {
* this remembers the stateless + non_stateless logP assocated with the rule (excluding the
* best-logP from ant nodes)
* */
- private Float transitionScore = null;
+ private float transitionScore;
private Rule rule;
@@ -79,17 +79,13 @@ public class HyperEdge {
}
public float getTransitionLogP(boolean forceCompute) {
- StringBuilder sb = new StringBuilder();
- if (forceCompute || transitionScore == null) {
+ if (forceCompute) {
float res = bestDerivationScore;
- sb.append(String.format("Best derivation = %.5f", res));
if (tailNodes != null) for (HGNode tailNode : tailNodes) {
res += tailNode.bestHyperedge.bestDerivationScore;
- sb.append(String.format(", tail = %.5f", tailNode.bestHyperedge.bestDerivationScore));
}
transitionScore = res;
}
- // System.err.println("HYPEREDGE SCORE = " + sb.toString());
return transitionScore;
}
@@ -100,9 +96,6 @@ public class HyperEdge {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.rule);
-// if (getTailNodes() != null) for (HGNode tailNode : getTailNodes()) {
-// sb.append(" tail=" + tailNode);
-// }
return sb.toString();
}
}