From f242145259664c9676eceae0689cdaeafd7629b5 Mon Sep 17 00:00:00 2001 From: Tim Millar Date: Mon, 20 Nov 2023 14:29:55 +1300 Subject: [PATCH] Fixup use default_rng for cpython code. --- sgkit/stats/genedrop.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sgkit/stats/genedrop.py b/sgkit/stats/genedrop.py index 1b8690d74..b105ae0b2 100644 --- a/sgkit/stats/genedrop.py +++ b/sgkit/stats/genedrop.py @@ -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) @@ -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: