44from array_paths import *
55
66from tiledb .vector_search import _tiledbvspy as vspy
7+ from tiledb .vector_search .utils import load_fvecs
78
89ctx = vspy .Ctx ({})
910
@@ -80,6 +81,8 @@ def test_numpy_to_feature_vector_array():
8081 assert a .shape == (10000 , 128 )
8182 assert b .dimension () == 128
8283 assert b .num_vectors () == 10000
84+ assert a .shape == np .array (b ).shape
85+ assert np .array_equal (a , np .array (b ))
8386
8487 a = np .array (np .random .rand (128 , 10000 ), dtype = np .float32 , order = "F" )
8588 b = vspy .FeatureVectorArray (a )
@@ -88,6 +91,9 @@ def test_numpy_to_feature_vector_array():
8891 assert a .shape == (128 , 10000 )
8992 assert b .dimension () == 128
9093 assert b .num_vectors () == 10000
94+ # TODO(paris): This should work, but it doesn't.
95+ # assert a.shape == np.array(b).shape
96+ # assert np.array_equal(a, np.array(b))
9197
9298 a = np .array (np .random .rand (10000 , 128 ), dtype = np .float32 )
9399 b = vspy .FeatureVectorArray (a .T )
@@ -96,6 +102,8 @@ def test_numpy_to_feature_vector_array():
96102 assert a .shape == (10000 , 128 )
97103 assert b .dimension () == 128
98104 assert b .num_vectors () == 10000
105+ assert a .shape == np .array (b ).shape
106+ assert np .array_equal (a , np .array (b ))
99107
100108 a = np .array (np .random .rand (1000000 , 128 ), dtype = np .uint8 )
101109 b = vspy .FeatureVectorArray (a )
@@ -104,17 +112,44 @@ def test_numpy_to_feature_vector_array():
104112 assert a .shape == (1000000 , 128 )
105113 assert b .dimension () == 128
106114 assert b .num_vectors () == 1000000
115+ assert a .shape == np .array (b ).shape
116+ assert np .array_equal (a , np .array (b ))
107117
108118 a = np .array (np .random .rand (10000 , 128 ), dtype = np .float32 )
109119 b = vspy .FeatureVectorArray (a )
110120 logging .info (a .shape )
111121 logging .info ((b .dimension (), b .num_vectors ()))
112-
113- c = np .array (b )
114- logging .info (c .shape )
115-
116- assert a .shape == c .shape
117- assert (a == c ).all ()
122+ assert a .shape == np .array (b ).shape
123+ assert np .array_equal (a , np .array (b ))
124+
125+ a = np .array (np .arange (1 , 16 , dtype = np .float32 ).reshape (3 , 5 ), dtype = np .float32 )
126+ assert a .shape == (3 , 5 )
127+ assert a .flags .f_contiguous is False
128+ assert a .flags .c_contiguous is True
129+ a = np .transpose (a )
130+ assert a .shape == (5 , 3 )
131+ assert a .flags .f_contiguous is True
132+ assert a .flags .c_contiguous is False
133+ b = vspy .FeatureVectorArray (a )
134+ # NOTE(paris): It is strange that we have to transpose this output array to have it match the input array. Should investigate this and fix it.
135+ assert a .shape == np .transpose (np .array (b )).shape
136+ assert np .array_equal (a , np .transpose (np .array (b )))
137+
138+ n = 99
139+ a = load_fvecs (siftsmall_query_file )[0 :n ]
140+ assert a .shape == (n , 128 )
141+ assert a .flags .f_contiguous is False
142+ assert a .flags .c_contiguous is False
143+ a = np .transpose (a )
144+ assert a .shape == (128 , n )
145+ assert a .flags .f_contiguous is False
146+ assert a .flags .c_contiguous is False
147+ # NOTE(paris): load_fvecs() returns a view of an array, which is not contiguous, so make it contiguous. Ideally we would handle this in FeatureVectorArray().
148+ a = np .asfortranarray (a )
149+ b = vspy .FeatureVectorArray (a )
150+ # NOTE(paris): It is strange that we have to transpose this output array to have it match the input array. Should investigate this and fix it.
151+ assert a .shape == np .transpose (np .array (b )).shape
152+ assert np .array_equal (a , np .transpose (np .array (b )))
118153
119154
120155def test_construct_IndexFlatL2 ():
0 commit comments