Code Duplication    Length = 13-13 lines in 3 locations

gradient_free_optimizers/search.py 1 location

@@ 20-32 (lines=13) @@
17
from .stop_run import StopRun
18
19
20
def set_random_seed(nth_process, random_state):
21
    """
22
    Sets the random seed separately for each thread
23
    (to avoid getting the same results in each thread)
24
    """
25
    if nth_process is None:
26
        nth_process = 0
27
28
    if random_state is None:
29
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
30
31
    random.seed(random_state + nth_process)
32
    np.random.seed(random_state + nth_process)
33
34
35
class Search(TimesTracker):

gradient_free_optimizers/optimizers/base_optimizer.py 1 location

@@ 16-28 (lines=13) @@
13
from ..utils import set_random_seed, move_random
14
15
16
def set_random_seed(nth_process, random_state):
17
    """
18
    Sets the random seed separately for each thread
19
    (to avoid getting the same results in each thread)
20
    """
21
    if nth_process is None:
22
        nth_process = 0
23
24
    if random_state is None:
25
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
26
27
    random.seed(random_state + nth_process)
28
    np.random.seed(random_state + nth_process)
29
30
31
def get_n_inits(initialize):

gradient_free_optimizers/utils.py 1 location

@@ 9-21 (lines=13) @@
6
import numpy as np
7
8
9
def set_random_seed(nth_process, random_state):
10
    """
11
    Sets the random seed separately for each thread
12
    (to avoid getting the same results in each thread)
13
    """
14
    if nth_process is None:
15
        nth_process = 0
16
17
    if random_state is None:
18
        random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64)
19
20
    random.seed(random_state + nth_process)
21
    np.random.seed(random_state + nth_process)
22
23
24
def move_random(ss_positions):