Skip to content

Commit 88bef31

Browse files
committed
Added tests for non-contiguous arrays [skip ci]
1 parent 81c717b commit 88bef31

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

examples/loading/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from pgvector import Vector
23
from pgvector.psycopg import register_vector
34
import psycopg
45

@@ -25,7 +26,7 @@
2526
copy.set_types(['vector'])
2627

2728
for i, embedding in enumerate(embeddings):
28-
copy.write_row([embedding])
29+
copy.write_row([Vector(embedding)])
2930

3031
# show progress
3132
if i % 10000 == 0:

examples/loading/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ dev = [
99
"pgvector",
1010
"psycopg[binary]"
1111
]
12+
13+
[tool.uv.sources]
14+
pgvector = { path = "../..", editable = true }

tests/test_half_vector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test_ndarray(self) -> None:
3434
assert HalfVector(arr).to_list() == [1, 2, 3]
3535
assert HalfVector(arr).to_numpy() is not arr
3636
assert HalfVector(arr).to_numpy().dtype == np.float16
37+
# non-contiguous
38+
assert HalfVector(np.flip(arr)).to_list() == [3, 2, 1]
39+
assert HalfVector(np.flip(arr)).to_binary() == HalfVector([3, 2, 1]).to_binary()
3740

3841
def test_int(self) -> None:
3942
with pytest.raises(ValueError) as error:

tests/test_vector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test_ndarray(self) -> None:
3434
assert Vector(arr).to_list() == [1, 2, 3]
3535
assert Vector(arr).to_numpy() is not arr
3636
assert Vector(arr).to_numpy().dtype == np.float32
37+
# non-contiguous
38+
assert Vector(np.flip(arr)).to_list() == [3, 2, 1]
39+
assert Vector(np.flip(arr)).to_binary() == Vector([3, 2, 1]).to_binary()
3740

3841
def test_int(self) -> None:
3942
with pytest.raises(ValueError) as error:

0 commit comments

Comments
 (0)