Skip to content

Commit

Permalink
Fixup use default_rng for cpython code.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymillar committed Nov 23, 2023
1 parent 1061ef9 commit f242145
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sgkit/stats/genedrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ def simulate_genedrop(
Simulation with random seed
>>> sim = sg.simulate_genedrop(ds, merge=False, seed=0)
>>> sim = sg.simulate_genedrop(ds, merge=False, seed=1)
>>> sim["sample_id"] = ds["sample_id"]
>>> sim["variant_position"] = ds["variant_position"]
>>> sim["variant_allele"] = ds["variant_allele"]
>>> sg.display_genotypes(sim) # doctest: +NORMALIZE_WHITESPACE
samples S0 S1 S2 S3 S4
variants
0 0/1 2/3 1/2 1/3 1/1
1 0/1 2/3 0/3 0/2 3/2
2 0/1 2/3 1/3 1/3 3/3
0 0/1 2/3 0/3 1/3 0/3
1 0/1 2/3 0/3 0/3 0/3
2 0/1 2/3 0/2 0/3 2/0
Simulation with seed per variant (including duplicates)
Expand Down Expand Up @@ -302,10 +302,11 @@ def simulate_genedrop(
gt = da.asarray(ds[call_genotype].data)
parent = da.asarray(ds[parent].data, chunks=ds[parent].shape)
if hasattr(seed, "__len__"):
seeds = da.array(seed)
seeds = np.array(seed, copy=False)
elif seed is not None:
rng = np.random.default_rng(seed)
seeds = rng.integers(2**32, size=len(gt), dtype=np.uint32)
else:
if seed is not None:
np.random.seed(seed)
seeds = np.random.randint(2**32, size=len(gt), dtype=np.uint32)
seeds = da.asarray(seeds, chunks=gt.chunks[0])
if method == EST_DIPLOID:
Expand Down

0 comments on commit f242145

Please sign in to comment.