Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pgvector/halfvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __repr__(self) -> str:
def __eq__(self, other: object, /) -> bool:
if not isinstance(other, self.__class__):
return NotImplemented
return self._value == other._value
return self.to_list() == other.to_list()

def dimensions(self) -> int:
return len(self._value)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_half_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ def test_equality(self) -> None:
assert HalfVector([1, 2, 3]) != HalfVector([1, 2, 4])
assert HalfVector([1, 2, 3]) != 1

@pytest.mark.parametrize('positive, negative', [
([0.0], [-0.0]),
([0.0, 1.5, -2.0], [-0.0, 1.5, -2.0]),
([1e-8, 1.5], [-1e-8, 1.5]),
])
def test_equality_signed_zero(self, positive: list[float], negative: list[float]) -> None:
left = HalfVector(positive)
right = HalfVector(negative)
assert left == right
assert right == left
# Numeric equality must not normalize the stored sign bit.
assert left.to_binary() != right.to_binary()

def test_equality_signed_zero_from_binary(self) -> None:
left = HalfVector.from_binary(pack('>HH2e', 2, 0, 0.0, 1.5))
right = HalfVector.from_binary(pack('>HH2e', 2, 0, -0.0, 1.5))
assert left == right

def test_equality_signed_zero_from_text(self) -> None:
assert HalfVector.from_text('[0.0,1.5]') == HalfVector.from_text('[-0.0,1.5]')

def test_dimensions(self) -> None:
assert HalfVector([1, 2, 3]).dimensions() == 3

Expand Down