From bea44bd3c41d684346228790b06908faedb4b321 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 23 Oct 2016 14:23:56 +0200 Subject: [PATCH] Fix vector_norm when vector is assigned to Lexeme. --- spacy/lexeme.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spacy/lexeme.pyx b/spacy/lexeme.pyx index 01305e855..638cd6365 100644 --- a/spacy/lexeme.pyx +++ b/spacy/lexeme.pyx @@ -1,4 +1,5 @@ # cython: embedsignature=True +from libc.math cimport sqrt from cpython.ref cimport Py_INCREF from cymem.cymem cimport Pool from murmurhash.mrmr cimport hash64 @@ -115,8 +116,11 @@ cdef class Lexeme: def __set__(self, vector): assert len(vector) == self.vocab.vectors_length cdef float value + cdef double norm = 0.0 for i, value in enumerate(vector): self.c.vector[i] = value + norm += value * value + self.c.l2_norm = sqrt(norm) property rank: def __get__(self):