From b06962f18b60d333d9c5ce44b7aca4876db1e275 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 28 Jun 2015 10:36:14 +0200 Subject: [PATCH] * Pad buffers in state --- spacy/syntax/stateclass.pyx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/spacy/syntax/stateclass.pyx b/spacy/syntax/stateclass.pyx index d193c64c5..0112a89f5 100644 --- a/spacy/syntax/stateclass.pyx +++ b/spacy/syntax/stateclass.pyx @@ -8,17 +8,22 @@ from ..structs cimport Entity cdef class StateClass: def __init__(self, int length): cdef Pool mem = Pool() - PADDING = 5 - self._buffer = mem.alloc(length + PADDING, sizeof(int)) - self._stack = mem.alloc(length + PADDING, sizeof(int)) - self.shifted = mem.alloc(length + PADDING, sizeof(bint)) - self._sent = mem.alloc(length + PADDING, sizeof(TokenC)) - self._ents = mem.alloc(length + PADDING, sizeof(Entity)) + cdef int PADDING = 5 + self._buffer = mem.alloc(length + (PADDING * 2), sizeof(int)) + self._stack = mem.alloc(length + (PADDING * 2), sizeof(int)) + self.shifted = mem.alloc(length + (PADDING * 2), sizeof(bint)) + self._sent = mem.alloc(length + (PADDING * 2), sizeof(TokenC)) + self._ents = mem.alloc(length + (PADDING * 2), sizeof(Entity)) cdef int i - for i in range(length): + for i in range(length + (PADDING * 2)): self._ents[i].end = -1 - for i in range(length, length + PADDING): + for i in range(length, length + (PADDING * 2)): self._sent[i].lex = &EMPTY_LEXEME + self._sent += PADDING + self._ents += PADDING + self._buffer += PADDING + self._stack += PADDING + self.shifted += PADDING self.mem = mem self.length = length self._break = -1