CatOrNot/venv/lib64/python3.7/site-packages/numpy/random/_pickle.py

83 lines
2.2 KiB
Python
Raw Permalink Normal View History

2020-01-06 16:11:15 +01:00
from .mtrand import RandomState
from .philox import Philox
from .pcg64 import PCG64
from .sfc64 import SFC64
from .generator import Generator
from .mt19937 import MT19937
BitGenerators = {'MT19937': MT19937,
'PCG64': PCG64,
'Philox': Philox,
'SFC64': SFC64,
}
def __generator_ctor(bit_generator_name='MT19937'):
"""
Pickling helper function that returns a Generator object
Parameters
----------
bit_generator_name: str
String containing the core BitGenerator
Returns
-------
rg: Generator
Generator using the named core BitGenerator
"""
if bit_generator_name in BitGenerators:
bit_generator = BitGenerators[bit_generator_name]
else:
raise ValueError(str(bit_generator_name) + ' is not a known '
'BitGenerator module.')
return Generator(bit_generator())
def __bit_generator_ctor(bit_generator_name='MT19937'):
"""
Pickling helper function that returns a bit generator object
Parameters
----------
bit_generator_name: str
String containing the name of the BitGenerator
Returns
-------
bit_generator: BitGenerator
BitGenerator instance
"""
if bit_generator_name in BitGenerators:
bit_generator = BitGenerators[bit_generator_name]
else:
raise ValueError(str(bit_generator_name) + ' is not a known '
'BitGenerator module.')
return bit_generator()
def __randomstate_ctor(bit_generator_name='MT19937'):
"""
Pickling helper function that returns a legacy RandomState-like object
Parameters
----------
bit_generator_name: str
String containing the core BitGenerator
Returns
-------
rs: RandomState
Legacy RandomState using the named core BitGenerator
"""
if bit_generator_name in BitGenerators:
bit_generator = BitGenerators[bit_generator_name]
else:
raise ValueError(str(bit_generator_name) + ' is not a known '
'BitGenerator module.')
return RandomState(bit_generator())