* Add padding to arrays in stateclass. May be papering over a deeper bug.

This commit is contained in:
Matthew Honnibal 2015-06-23 03:03:22 +02:00
parent 5e94b5d581
commit f01b3d043e
1 changed files with 8 additions and 7 deletions

View File

@ -7,14 +7,17 @@ from ..structs cimport Entity
cdef class StateClass:
def __init__(self, int length):
cdef Pool mem = Pool()
self._buffer = <int*>mem.alloc(length, sizeof(int))
self._stack = <int*>mem.alloc(length, sizeof(int))
self.shifted = <bint*>mem.alloc(length, sizeof(bint))
self._sent = <TokenC*>mem.alloc(length, sizeof(TokenC))
self._ents = <Entity*>mem.alloc(length, sizeof(Entity))
PADDING = 5
self._buffer = <int*>mem.alloc(length + PADDING, sizeof(int))
self._stack = <int*>mem.alloc(length + PADDING, sizeof(int))
self.shifted = <bint*>mem.alloc(length + PADDING, sizeof(bint))
self._sent = <TokenC*>mem.alloc(length + PADDING, sizeof(TokenC))
self._ents = <Entity*>mem.alloc(length + PADDING, sizeof(Entity))
cdef int i
for i in range(length):
self._ents[i].end = -1
for i in range(length, length + PADDING):
self._sent[i].lex = &EMPTY_LEXEME
self.mem = mem
self.length = length
self._break = -1
@ -181,8 +184,6 @@ cdef class StateClass:
cdef int dist = head - child
self._sent[child].head = dist
self._sent[child].dep = label
# Keep a bit-vector tracking child dependencies. If a word has a child at
# offset i from it, set that bit (tracking left and right separately)
if child > head:
self._sent[head].r_kids += 1
else: