diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-08-08 18:56:02 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-08-08 18:56:02 -0400 |
commit | e0eabf1e59cbfa85b00efcff699cdcd6a524e9c5 (patch) | |
tree | e6d013ebdb0eafc8e1e380e84549460847d685ac /python/src/hypergraph.pxi | |
parent | cc5584e9b066e6d1177495f7028ff49ab057ed52 (diff) |
[python] Get rid of the GIL
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r-- | python/src/hypergraph.pxi | 13 |
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()): |