Skip to content

Commit

Permalink
Merge pull request #20 from noutenki/patch-1
Browse files Browse the repository at this point in the history
Optimize apply_templates (also close #49)
  • Loading branch information
Naoaki Okazaki committed Jan 24, 2016
2 parents 16f7a36 + 392e43d commit d3d4040
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions example/crfutils.py
Expand Up @@ -21,13 +21,17 @@ def apply_templates(X, templates):
@type template: tuple of (str, int)
@param template: The feature template.
"""

x_range = list(range(len(X)))
x_range_set = set(x_range)

for template in templates:
name = '|'.join(['%s[%d]' % (f, o) for f, o in template])
for t in range(len(X)):
for t in x_range:
values = []
for field, offset in template:
p = t + offset
if p not in range(len(X)):
if p not in x_range_set:
values = []
break
values.append(X[p][field])
Expand Down

0 comments on commit d3d4040

Please sign in to comment.