| 134 | @pytest.mark.parametrize("gen", [None, cupy.random.default_rng, np.random.default_rng]) |
| 135 | @pytest.mark.parametrize("shape", [(2), (2, 3), (2, 3, 4), (2, 3, 4, 2)], ids=type) |
| 136 | def test_random_all_Generator(backend, gen, shape): |
| 137 | # Generator argument takes priority over backend |
| 138 | if gen == cupy.random.default_rng: |
| 139 | expect = cupy.ndarray |
| 140 | elif gen == np.random.default_rng: |
| 141 | expect = np.ndarray |
| 142 | elif backend == "cupy": |
| 143 | expect = cupy.ndarray |
| 144 | else: |
| 145 | expect = np.ndarray |
| 146 | |
| 147 | def rnd_test(func, *args, **kwargs): |
| 148 | a = func(*args, **kwargs) |
| 149 | assert type(a._meta) == expect |
| 150 | assert_eq(a, a) # Check that _meta and computed arrays match types |
| 151 | |
| 152 | with config.set({"array.backend": backend}): |
| 153 | generator = gen(5) if gen else None |
| 154 | rng = da.random.default_rng(generator) |
| 155 | |
| 156 | rnd_test(rng.beta, 1, 2, size=shape, chunks=3) |
| 157 | rnd_test(rng.binomial, 10, 0.5, size=shape, chunks=3) |
| 158 | rnd_test(rng.chisquare, 1, size=shape, chunks=3) |
| 159 | rnd_test(rng.exponential, 1, size=shape, chunks=3) |
| 160 | rnd_test(rng.f, 1, 2, size=shape, chunks=3) |
| 161 | rnd_test(rng.gamma, 5, 1, size=shape, chunks=3) |
| 162 | rnd_test(rng.geometric, 1, size=shape, chunks=3) |
| 163 | rnd_test(rng.hypergeometric, 1, 2, 3, size=shape, chunks=3) |
| 164 | rnd_test(rng.integers, 1, high=10, size=shape, chunks=3) |
| 165 | rnd_test(rng.logseries, 0.5, size=shape, chunks=3) |
| 166 | rnd_test(rng.poisson, 1, size=shape, chunks=3) |
| 167 | rnd_test(rng.power, 1, size=shape, chunks=3) |
| 168 | rnd_test(rng.random, size=shape, chunks=3) |
| 169 | rnd_test(rng.standard_exponential, size=shape, chunks=3) |
| 170 | rnd_test(rng.standard_gamma, 2, size=shape, chunks=3) |
| 171 | rnd_test(rng.standard_normal, size=shape, chunks=3) |
| 172 | |
| 173 | |
| 174 | @pytest.mark.parametrize("backend", ["cupy", "numpy"]) |