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

Function test_UniformRNG

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

Source from the content-addressed store, hash-verified

357 get_device_count("xpu") <= 1, reason="xpu counts need > 1",
358)
359def test_UniformRNG():
360 m1 = RNG(seed=111, device="xpu0")
361 m2 = RNG(seed=111, device="xpu1")
362 m3 = RNG(seed=222, device="xpu0")
363 out1 = m1.uniform(size=(100,))
364 out1_ = m1.uniform(size=(100,))
365 out2 = m2.uniform(size=(100,))
366 out3 = m3.uniform(size=(100,))
367
368 np.testing.assert_allclose(out1.numpy(), out2.numpy(), atol=1e-6)
369 assert out1.device == "xpu0" and out2.device == "xpu1"
370 assert not (out1.numpy() == out3.numpy()).all()
371 assert not (out1.numpy() == out1_.numpy()).all()
372
373 low = -234
374 high = 123
375 out = m1.uniform(low=low, high=high, size=(20, 30, 40))
376 out_shp = out.shape
377 if isinstance(out_shp, tuple):
378 assert out_shp == (20, 30, 40)
379 else:
380 assert all(out.shape.numpy() == np.array([20, 30, 40]))
381 assert np.abs(out.mean().numpy() - ((low + high) / 2)) / (high - low) < 0.1
382
383
384@pytest.mark.skipif(

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected