def test_get_vector_resize(strings, data, resize_data): v = Vectors(data=data) v.resize(shape=resize_data.shape) strings = [hash_string(s) for s in strings] for i, string in enumerate(strings): v.add(string, row=i) assert list(v[strings[0]]) == list(resize_data[0]) assert list(v[strings[0]]) != list(resize_data[1]) assert list(v[strings[1]]) != list(resize_data[0]) assert list(v[strings[1]]) == list(resize_data[1])
def test_get_vector_resize(strings, data): strings = [hash_string(s) for s in strings] # decrease vector dimension (truncate) v = Vectors(data=data) resized_dim = v.shape[1] - 1 v.resize(shape=(v.shape[0], resized_dim)) for i, string in enumerate(strings): v.add(string, row=i) assert list(v[strings[0]]) == list(data[0, :resized_dim]) assert list(v[strings[1]]) == list(data[1, :resized_dim]) # increase vector dimension (pad with zeros) v = Vectors(data=data) resized_dim = v.shape[1] + 1 v.resize(shape=(v.shape[0], resized_dim)) for i, string in enumerate(strings): v.add(string, row=i) assert list(v[strings[0]]) == list(data[0]) + [0] assert list(v[strings[1]]) == list(data[1]) + [0]
def test_issue1539(): """Ensure vectors.resize() doesn't try to modify dictionary during iteration.""" v = Vectors(shape=(10, 10), keys=[5, 3, 98, 100]) v.resize((100, 100))
def test_issue1518(): """Test vectors.resize() works.""" vectors = Vectors(shape=(10, 10)) vectors.add("hello", row=2) vectors.resize((5, 9))
def test_init_vectors_with_resize_data(data, resize_data): v = Vectors(data=data) v.resize(shape=resize_data.shape) assert v.shape == resize_data.shape assert v.shape != data.shape
def test_init_vectors_with_resize_shape(strings, resize_data): v = Vectors(shape=(len(strings), 3)) v.resize(shape=resize_data.shape) assert v.shape == resize_data.shape assert v.shape != (len(strings), 3)