summaryrefslogtreecommitdiff
path: root/python/src/hypergraph.pxi
diff options
context:
space:
mode:
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()):