From 8ef5c9b0e15c45b09a22fd89a4ed7b0e180a9d2b Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sun, 2 Jun 2013 14:55:53 -0400 Subject: Possible fix for #13 - use IntList .len instead of len() which can return long - a bit of code cleanup - upgrade to Cython 0.19 --- python/src/sa/rulefactory.pxi | 71 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'python/src/sa/rulefactory.pxi') diff --git a/python/src/sa/rulefactory.pxi b/python/src/sa/rulefactory.pxi index 559e8396..10bb9737 100644 --- a/python/src/sa/rulefactory.pxi +++ b/python/src/sa/rulefactory.pxi @@ -879,15 +879,15 @@ cdef class HieroCachingRuleFactory: def advance(self, frontier, res, fwords): cdef unsigned na nf = [] - for (toskip, (i, alt, pathlen)) in frontier: + for toskip, (i, alt, pathlen) in frontier: spanlen = fwords[i][alt][2] - if (toskip == 0): + if toskip == 0: res.append((i, alt, pathlen)) ni = i + spanlen - if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + if ni < len(fwords) and pathlen + 1 < self.max_initial_size: for na in range(len(fwords[ni])): nf.append((toskip - 1, (ni, na, pathlen + 1))) - if (len(nf) > 0): + if len(nf) > 0: return self.advance(nf, res, fwords) else: return res @@ -895,11 +895,11 @@ cdef class HieroCachingRuleFactory: def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): cdef unsigned alt_it frontier = [] - if (i+spanlen+skip >= len(next_states)): + if i+spanlen+skip >= len(next_states): return frontier key = tuple([i,spanlen]) reachable = [] - if (key in reachable_buffer): + if key in reachable_buffer: reachable = reachable_buffer[key] else: reachable = self.reachable(fwords, i, spanlen) @@ -911,7 +911,7 @@ cdef class HieroCachingRuleFactory: continue if pathlen+jump <= self.max_initial_size: for alt_id in range(len(fwords[next_id])): - if (fwords[next_id][alt_id][0] != EPSILON): + if fwords[next_id][alt_id][0] != EPSILON: newel = (next_id,alt_id,pathlen+jump) if newel not in frontier: frontier.append((next_id,alt_id,pathlen+jump)) @@ -919,18 +919,18 @@ cdef class HieroCachingRuleFactory: def reachable(self, fwords, ifrom, dist): ret = [] - if (ifrom >= len(fwords)): + if ifrom >= len(fwords): return ret for alt_id in range(len(fwords[ifrom])): - if (fwords[ifrom][alt_id][0] == EPSILON): + if fwords[ifrom][alt_id][0] == EPSILON: ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) else: - if (dist==0): - if (ifrom not in ret): + if dist == 0: + if ifrom not in ret: ret.append(ifrom) else: for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): - if (ifromchild not in ret): + if ifromchild not in ret: ret.append(ifromchild) return ret @@ -938,15 +938,15 @@ cdef class HieroCachingRuleFactory: def shortest(self, fwords, ifrom, ito): cdef unsigned alt_id min = 1000 - if (ifrom > ito): + if ifrom > ito: return min - if (ifrom == ito): + if ifrom == ito: return 0 for alt_id in range(len(fwords[ifrom])): currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) - if (fwords[ifrom][alt_id][0] != EPSILON): + if fwords[ifrom][alt_id][0] != EPSILON: currmin += 1 - if (currmin