MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_poisson_op

Function test_poisson_op

imperative/python/test/unit/random/test_rng.py:157–175  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155 get_device_count("xpu") <= 2, reason="xpu counts need > 2",
156)
157def test_poisson_op():
158 set_global_seed(1024)
159 lam = F.full([8, 9, 11, 12], value=2, dtype="float32")
160 op = PoissonRNG(seed=get_global_rng_seed())
161 (output,) = apply(op, lam)
162 assert np.fabs(output.numpy().mean() - 2.0) < 1e-1
163 assert np.fabs(np.sqrt(output.numpy().var()) - np.sqrt(2.0)) < 1e-1
164 assert str(output.device) == str(CompNode("xpux"))
165
166 cn = CompNode("xpu2")
167 seed = 233333
168 h = new_rng_handle(cn, seed)
169 lam = F.full([8, 9, 11, 12], value=2, dtype="float32", device=cn)
170 op = PoissonRNG(seed=seed, handle=h)
171 (output,) = apply(op, lam)
172 delete_rng_handle(h)
173 assert np.fabs(output.numpy().mean() - 2.0) < 1e-1
174 assert np.fabs(np.sqrt(output.numpy().var()) - np.sqrt(2.0)) < 1e-1
175 assert str(output.device) == str(cn)
176
177
178@pytest.mark.skipif(

Callers

nothing calls this directly

Calls 10

get_global_rng_seedFunction · 0.90
PoissonRNGClass · 0.85
strFunction · 0.85
CompNodeClass · 0.85
applyFunction · 0.50
fabsMethod · 0.45
meanMethod · 0.45
numpyMethod · 0.45
sqrtMethod · 0.45
varMethod · 0.45

Tested by

no test coverage detected