annoy
1# Copyright (c) 2013 Spotify AB
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import numpy
16
17from annoy import AnnoyIndex
18
19
20def test_seeding():
21f = 10
22X = numpy.random.rand(1000, f)
23Y = numpy.random.rand(50, f)
24
25indexes = []
26for i in range(2):
27index = AnnoyIndex(f, "angular")
28index.set_seed(42)
29for j in range(X.shape[0]):
30index.add_item(j, X[j])
31
32index.build(10)
33indexes.append(index)
34
35for k in range(Y.shape[0]):
36assert indexes[0].get_nns_by_vector(Y[k], 100) == indexes[1].get_nns_by_vector(
37Y[k], 100
38)
39