annoy

Форк
0
/
seed_test.py 
38 строк · 1.1 Кб
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

15
import numpy
16

17
from annoy import AnnoyIndex
18

19

20
def test_seeding():
21
    f = 10
22
    X = numpy.random.rand(1000, f)
23
    Y = numpy.random.rand(50, f)
24

25
    indexes = []
26
    for i in range(2):
27
        index = AnnoyIndex(f, "angular")
28
        index.set_seed(42)
29
        for j in range(X.shape[0]):
30
            index.add_item(j, X[j])
31

32
        index.build(10)
33
        indexes.append(index)
34

35
    for k in range(Y.shape[0]):
36
        assert indexes[0].get_nns_by_vector(Y[k], 100) == indexes[1].get_nns_by_vector(
37
            Y[k], 100
38
        )
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.