Tidy up and only use self.vector once

This commit is contained in:
Ines Montani 2019-03-07 01:06:12 +01:00
parent a8f1efd2f5
commit 9d6ca18a10
4 changed files with 4 additions and 9 deletions

View File

@ -125,11 +125,9 @@ cdef class Lexeme:
if self.vector_norm == 0 or other.vector_norm == 0:
user_warning(Warnings.W008.format(obj='Lexeme'))
return 0.0
vector = self.vector
xp = get_array_module(vector)
return (xp.dot(self.vector, other.vector) /
(self.vector_norm * other.vector_norm))
return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
def to_bytes(self):
lex_data = Lexeme.c_to_bytes(self.c)

View File

@ -329,10 +329,9 @@ cdef class Doc:
if self.vector_norm == 0 or other.vector_norm == 0:
user_warning(Warnings.W008.format(obj='Doc'))
return 0.0
vector = self.vector
xp = get_array_module(vector)
return xp.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
property has_vector:
"""A boolean value indicating whether a word vector is associated with

View File

@ -234,10 +234,9 @@ cdef class Span:
if self.vector_norm == 0.0 or other.vector_norm == 0.0:
user_warning(Warnings.W008.format(obj='Span'))
return 0.0
vector = self.vector
xp = get_array_module(vector)
return xp.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
cpdef np.ndarray to_array(self, object py_attr_ids):
"""Given a list of M attribute IDs, export the tokens to a numpy

View File

@ -172,8 +172,7 @@ cdef class Token:
return 0.0
vector = self.vector
xp = get_array_module(vector)
return (xp.dot(vector, other.vector) /
(self.vector_norm * other.vector_norm))
return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
property lex_id:
"""RETURNS (int): Sequential ID of the token's lexical type."""