MCPcopy
hub / github.com/benfred/implicit / check_random_state

Function check_random_state

implicit/gpu/matrix_factorization_base.py:237–259  ·  view source on GitHub ↗

Validate the random state, r Check a random seed or existing numpy RandomState and get back an initialized RandomState. Parameters ---------- random_state : int, None, np.random.RandomState or np.random.Generator The existing RandomState. If None, or an int, will be use

(random_state)

Source from the content-addressed store, hash-verified

235
236
237def check_random_state(random_state):
238 """Validate the random state, r
239
240 Check a random seed or existing numpy RandomState
241 and get back an initialized RandomState.
242
243 Parameters
244 ----------
245 random_state : int, None, np.random.RandomState or np.random.Generator
246 The existing RandomState. If None, or an int, will be used
247 to seed a new curand RandomState generator
248 """
249 if isinstance(random_state, np.random.RandomState):
250 # we need to convert from numpy random state our internal random state
251 return implicit.gpu.RandomState(random_state.randint(2**31))
252
253 if isinstance(random_state, np.random.Generator):
254 # we need to convert from numpy random state our internal random state
255 return implicit.gpu.RandomState(random_state.integers(2**31))
256
257 # otherwise try to initialize a new one, and let it fail through
258 # on the numpy side if it doesn't work
259 return implicit.gpu.RandomState(random_state or int(time.time()))

Callers 3

fitMethod · 0.90
fitMethod · 0.70
fitMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected