Skip to content

Commit

Permalink
ENH: Use NumPy's Generator class as a replacement for RandomState
Browse files Browse the repository at this point in the history
Use NumPy's `Generator` class as a replacement for `RandomState` for
random variarte generation methods.

`RandomState` was deprecated in NumPy 1.17.0.

Documentation:
https://numpy.org/doc/stable/reference/random/new-or-different.html#what-s-new-or-different
https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html
  • Loading branch information
jhlegarreta committed Mar 24, 2024
1 parent 3b1e8d0 commit 464c288
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/eddymotion/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ def fit(
"""
align_kwargs = align_kwargs or {}

_seed = None
if seed or seed == 0:
np.random.seed(20210324 if seed is True else seed)
_seed = 20210324 if seed is True else seed

rng = np.random.default_rng(_seed)

if "num_threads" not in align_kwargs and omp_nthreads is not None:
align_kwargs["num_threads"] = omp_nthreads
Expand Down Expand Up @@ -120,7 +123,7 @@ def fit(
kwargs["xlim"] = dwdata.total_duration

index_order = np.arange(len(dwdata))
np.random.shuffle(index_order)
rng.shuffle(index_order)

single_model = model.lower() in (
"b0",
Expand Down

0 comments on commit 464c288

Please sign in to comment.