* Store the l2 norm of the word's vector

This commit is contained in:
Matthew Honnibal 2015-02-07 08:42:16 -05:00
parent c7d8644149
commit 321b402739
1 changed files with 4 additions and 0 deletions

View File

@ -37,6 +37,7 @@ cdef class Lexeme:
cdef readonly attr_t cluster cdef readonly attr_t cluster
cdef readonly float prob cdef readonly float prob
cdef readonly float sentiment cdef readonly float sentiment
cdef readonly float l2_norm
# Workaround for an apparent bug in the way the decorator is handled --- # Workaround for an apparent bug in the way the decorator is handled ---
# TODO: post bug report / patch to Cython. # TODO: post bug report / patch to Cython.
@ -45,6 +46,7 @@ cdef class Lexeme:
cdef Lexeme py = Lexeme.__new__(Lexeme, 300) cdef Lexeme py = Lexeme.__new__(Lexeme, 300)
for i in range(300): for i in range(300):
py.repvec[i] = ptr.repvec[i] py.repvec[i] = ptr.repvec[i]
py.l2_norm = ptr.l2_norm
py.flags = ptr.flags py.flags = ptr.flags
py.id = ptr.id py.id = ptr.id
py.length = ptr.length py.length = ptr.length
@ -68,6 +70,8 @@ cdef class Lexeme:
py.sentiment = ptr.sentiment py.sentiment = ptr.sentiment
return py return py
cpdef bint check(self, attr_id_t flag_id) except -1
cdef inline bint check_flag(const LexemeC* lexeme, attr_id_t flag_id) nogil: cdef inline bint check_flag(const LexemeC* lexeme, attr_id_t flag_id) nogil:
return lexeme.flags & (1 << flag_id) return lexeme.flags & (1 << flag_id)