Skip to content

Commit 76afd8e

Browse files
committed
Added test for coo_matrix
1 parent 713590a commit 76afd8e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/test_sparse_vector.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
from pgvector import SparseVector
33
import pytest
4-
from scipy.sparse import coo_array, csr_array, csr_matrix
4+
from scipy.sparse import coo_array, coo_matrix, csr_array, csr_matrix
55
from struct import pack
66

77

@@ -43,6 +43,12 @@ def test_coo_array_dimensions(self):
4343
SparseVector(coo_array(np.array([1, 0, 2, 0, 3, 0])), 6)
4444
assert str(error.value) == 'extra argument'
4545

46+
def test_coo_matrix(self):
47+
mat = coo_matrix(np.array([1, 0, 2, 0, 3, 0]))
48+
vec = SparseVector(mat)
49+
assert vec.to_list() == [1, 0, 2, 0, 3, 0]
50+
assert vec.indices() == [0, 2, 4]
51+
4652
def test_dok_array(self):
4753
arr = coo_array(np.array([1, 0, 2, 0, 3, 0])).todok()
4854
vec = SparseVector(arr)

0 commit comments

Comments
 (0)