Skip to content

Commit 1aec1c0

Browse files
committed
Improved code [skip ci]
1 parent e0c84e4 commit 1aec1c0

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

pgvector/utils/bit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def __init__(self, value):
1313
else:
1414
self.value = np.array(value, dtype=bool)
1515

16+
def __str__(self):
17+
return self.__class__.to_db(self)
18+
19+
def __repr__(self):
20+
return f'Bit({self})'
21+
1622
def to_db(value):
1723
if not isinstance(value, Bit):
1824
raise ValueError('expected bit')
@@ -26,9 +32,3 @@ def to_db_binary(value):
2632

2733
value = value.value
2834
return pack('>i', len(value)) + np.packbits(value).tobytes()
29-
30-
def __str__(self):
31-
return self.__class__.to_db(self)
32-
33-
def __repr__(self):
34-
return f'Bit({self})'

pgvector/utils/halfvec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def __init__(self, value):
1515
def to_list(self):
1616
return list(self.value)
1717

18+
def __repr__(self):
19+
return f'HalfVector({self.value})'
20+
1821
def to_db(value, dim=None):
1922
if value is None:
2023
return value
@@ -43,6 +46,3 @@ def from_db_binary(value):
4346
return value
4447
dim, unused = unpack_from('>HH', value)
4548
return HalfVector(unpack_from(f'>{dim}e', value, 4))
46-
47-
def __repr__(self):
48-
return f'HalfVector({self.value})'

pgvector/utils/sparsevec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def to_dense(self):
2222
vec[i] = v
2323
return vec
2424

25+
def __repr__(self):
26+
return f'SparseVector({self.dim}, {self.indices}, {self.values})'
27+
2528
def to_db(value, dim=None):
2629
if value is None:
2730
return value
@@ -68,6 +71,3 @@ def from_db_binary(value):
6871
indices = unpack_from(f'>{nnz}i', value, 12)
6972
values = unpack_from(f'>{nnz}f', value, 12 + nnz * 4)
7073
return SparseVector(int(dim), indices, values)
71-
72-
def __repr__(self):
73-
return f'SparseVector({self.dim}, {self.indices}, {self.values})'

0 commit comments

Comments
 (0)