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

Function test_NormalRNG

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

Source from the content-addressed store, hash-verified

385 get_device_count("xpu") <= 1, reason="xpu counts need > 1",
386)
387def test_NormalRNG():
388 m1 = RNG(seed=111, device="xpu0")
389 m2 = RNG(seed=111, device="xpu1")
390 m3 = RNG(seed=222, device="xpu0")
391 out1 = m1.normal(size=(100,))
392 out1_ = m1.uniform(size=(100,))
393 out2 = m2.normal(size=(100,))
394 out3 = m3.normal(size=(100,))
395
396 np.testing.assert_allclose(out1.numpy(), out2.numpy(), atol=1e-6)
397 assert out1.device == "xpu0" and out2.device == "xpu1"
398 assert not (out1.numpy() == out3.numpy()).all()
399 assert not (out1.numpy() == out1_.numpy()).all()
400
401 mean = -1
402 std = 2
403 out = m1.normal(mean=mean, std=std, size=(20, 30, 40))
404 out_shp = out.shape
405 if isinstance(out_shp, tuple):
406 assert out_shp == (20, 30, 40)
407 else:
408 assert all(out.shape.numpy() == np.array([20, 30, 40]))
409 assert np.abs(out.mean().numpy() - mean) / std < 0.1
410 assert np.abs(np.std(out.numpy()) - std) < 0.1
411
412
413@pytest.mark.skipif(

Callers

nothing calls this directly

Calls 7

normalMethod · 0.95
uniformMethod · 0.95
RNGClass · 0.90
allMethod · 0.80
arrayMethod · 0.80
numpyMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected