mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
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:
parent
e232356f41
commit
50f89cb85d
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user