summaryrefslogtreecommitdiff
path: root/python/src/hypergraph.pxi
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-08-09 01:18:51 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-08-09 01:18:51 -0400
commit454ef7fd3a37a7d3105d6bf0f5750047979da2d4 (patch)
tree276fc4758188db716962ba409ccfe832077453a6 /python/src/hypergraph.pxi
parent2a9c9a414abc074ec4ea8a5494e8dd50e1f94d70 (diff)
parente0eabf1e59cbfa85b00efcff699cdcd6a524e9c5 (diff)
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r--python/src/hypergraph.pxi13
1 files changed, 7 insertions, 6 deletions
diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi
index 62dd5bb1..f0312a12 100644
--- a/python/src/hypergraph.pxi
+++ b/python/src/hypergraph.pxi
@@ -10,6 +10,11 @@ cdef class Hypergraph:
if self.rng != NULL:
del self.rng
+ cdef MT19937* _rng(self):
+ if self.rng == NULL:
+ self.rng = new MT19937()
+ return self.rng
+
def viterbi(self):
cdef vector[WordID] trans
hypergraph.ViterbiESentence(self.hg[0], &trans)
@@ -75,9 +80,7 @@ cdef class Hypergraph:
def sample(self, unsigned n):
cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
- if self.rng == NULL:
- self.rng = new MT19937()
- hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ hypergraph.sample_hypotheses(self.hg[0], n, self._rng(), hypos)
cdef unsigned k
try:
for k in range(hypos.size()):
@@ -87,9 +90,7 @@ cdef class Hypergraph:
def sample_trees(self, unsigned n):
cdef vector[string]* trees = new vector[string]()
- if self.rng == NULL:
- self.rng = new MT19937()
- hypergraph.sample_trees(self.hg[0], n, self.rng, trees)
+ hypergraph.sample_trees(self.hg[0], n, self._rng(), trees)
cdef unsigned k
try:
for k in range(trees.size()):