| 385 | get_device_count("xpu") <= 1, reason="xpu counts need > 1", |
| 386 | ) |
| 387 | def 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( |