Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Use NumPy's Generator class as a replacement for RandomState #141

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/eddymotion/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def fit(
Number of parallel jobs.
seed : :obj:`int` or :obj:`bool`
Seed the random number generator (necessary when we want deterministic
estimation).

estimation). If an integer, the value is used to initialize the
generator; if ``True``, the arbitrary value of ``20210324`` is used
to initialize it.
Return
------
affines : :obj:`list` of :obj:`numpy.ndarray`
Expand All @@ -86,8 +87,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
jhlegarreta marked this conversation as resolved.
Show resolved Hide resolved

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 +124,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