mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 13:44:55 +03:00
Add equality definition for vectors
This re-uses the check from sourcing components.
This commit is contained in:
parent
9baa686f82
commit
52bc927db9
|
@ -626,3 +626,23 @@ def test_floret_vectors(floret_vectors_vec_str, floret_vectors_hashvec_str):
|
||||||
OPS.to_numpy(vocab_r[word].vector),
|
OPS.to_numpy(vocab_r[word].vector),
|
||||||
decimal=6,
|
decimal=6,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_equality():
|
||||||
|
vectors1 = Vectors(shape=(10, 10))
|
||||||
|
vectors2 = Vectors(shape=(10, 8))
|
||||||
|
|
||||||
|
assert vectors1 != vectors2
|
||||||
|
|
||||||
|
vectors2 = Vectors(shape=(10, 10))
|
||||||
|
assert vectors1 == vectors2
|
||||||
|
|
||||||
|
vectors1.add("hello", row=2)
|
||||||
|
assert vectors1 != vectors2
|
||||||
|
|
||||||
|
vectors2.add("hello", row=2)
|
||||||
|
assert vectors1 == vectors2
|
||||||
|
|
||||||
|
vectors1.resize((5, 9))
|
||||||
|
vectors2.resize((5, 9))
|
||||||
|
assert vectors1 == vectors2
|
||||||
|
|
|
@ -243,6 +243,16 @@ cdef class Vectors:
|
||||||
else:
|
else:
|
||||||
return key in self.key2row
|
return key in self.key2row
|
||||||
|
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return (
|
||||||
|
self.shape == other.shape
|
||||||
|
and self.key2row == other.key2row
|
||||||
|
and self.to_bytes(exclude=["strings"])
|
||||||
|
== other.to_bytes(exclude=["strings"])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def resize(self, shape, inplace=False):
|
def resize(self, shape, inplace=False):
|
||||||
"""Resize the underlying vectors array. If inplace=True, the memory
|
"""Resize the underlying vectors array. If inplace=True, the memory
|
||||||
is reallocated. This may cause other references to the data to become
|
is reallocated. This may cause other references to the data to become
|
||||||
|
|
Loading…
Reference in New Issue
Block a user