Make vectors.find() return keys in correct order (#4691)

* Make vectors.find() return keys in correct order

* Update spacy/vectors.pyx
This commit is contained in:
Matthew Honnibal 2019-11-21 16:58:32 +01:00 committed by Ines Montani
parent e232356f41
commit 50f89cb85d

View File

@ -265,17 +265,12 @@ cdef class Vectors:
rows = [self.key2row.get(key, -1.) for key in keys] rows = [self.key2row.get(key, -1.) for key in keys]
return xp.asarray(rows, dtype="i") return xp.asarray(rows, dtype="i")
else: else:
targets = set() row2key = {row: key for key, row in self.key2row.items()}
if row is not None: if row is not None:
targets.add(row) return row2key[row]
else: else:
targets.update(rows) results = [row2key[row] for row in rows]
results = [] return xp.asarray(results, dtype="uint64")
for key, row in self.key2row.items():
if row in targets:
results.append(key)
targets.remove(row)
return xp.asarray(results, dtype="uint64")
def add(self, key, *, vector=None, row=None): def add(self, key, *, vector=None, row=None):
"""Add a key to the table. Keys can be mapped to an existing vector """Add a key to the table. Keys can be mapped to an existing vector