Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/numpy/random/_pickle.py: 62%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1from .mtrand import RandomState 

2from ._philox import Philox 

3from ._pcg64 import PCG64, PCG64DXSM 

4from ._sfc64 import SFC64 

5 

6from ._generator import Generator 

7from ._mt19937 import MT19937 

8 

9BitGenerators = {'MT19937': MT19937, 

10 'PCG64': PCG64, 

11 'PCG64DXSM': PCG64DXSM, 

12 'Philox': Philox, 

13 'SFC64': SFC64, 

14 } 

15 

16 

17def __bit_generator_ctor(bit_generator_name='MT19937'): 

18 """ 

19 Pickling helper function that returns a bit generator object 

20 

21 Parameters 

22 ---------- 

23 bit_generator_name : str 

24 String containing the name of the BitGenerator 

25 

26 Returns 

27 ------- 

28 bit_generator : BitGenerator 

29 BitGenerator instance 

30 """ 

31 if bit_generator_name in BitGenerators: 

32 bit_generator = BitGenerators[bit_generator_name] 

33 else: 

34 raise ValueError(str(bit_generator_name) + ' is not a known ' 

35 'BitGenerator module.') 

36 

37 return bit_generator() 

38 

39 

40def __generator_ctor(bit_generator_name="MT19937", 

41 bit_generator_ctor=__bit_generator_ctor): 

42 """ 

43 Pickling helper function that returns a Generator object 

44 

45 Parameters 

46 ---------- 

47 bit_generator_name : str 

48 String containing the core BitGenerator's name 

49 bit_generator_ctor : callable, optional 

50 Callable function that takes bit_generator_name as its only argument 

51 and returns an instantized bit generator. 

52 

53 Returns 

54 ------- 

55 rg : Generator 

56 Generator using the named core BitGenerator 

57 """ 

58 return Generator(bit_generator_ctor(bit_generator_name)) 

59 

60 

61def __randomstate_ctor(bit_generator_name="MT19937", 

62 bit_generator_ctor=__bit_generator_ctor): 

63 """ 

64 Pickling helper function that returns a legacy RandomState-like object 

65 

66 Parameters 

67 ---------- 

68 bit_generator_name : str 

69 String containing the core BitGenerator's name 

70 bit_generator_ctor : callable, optional 

71 Callable function that takes bit_generator_name as its only argument 

72 and returns an instantized bit generator. 

73 

74 Returns 

75 ------- 

76 rs : RandomState 

77 Legacy RandomState using the named core BitGenerator 

78 """ 

79 

80 return RandomState(bit_generator_ctor(bit_generator_name))