def test_rng_funcs(backend_default):
    # like the tests above but also tests the rng_get_state and rng_set_state funcs
    be = backend_default

    # keep sz*sz*batch_size < 3*2048*32 (NervanaGPU._RNG_POOL_SIZE
    sz = 32
    x = be.zeros((sz, sz))

    # use binary mask to test rng resetting

    be.make_binary_mask(out=x)
    x1 = x.get().copy()
    r1 = be.rng_get_state()

    be.make_binary_mask(out=x)
    x2 = x.get().copy()

    # there should be infinitesmial chance for x1 to equal x2
    # this assert is to make sure the rng is doing something
    assert np.max(np.abs(x2-x1)) > 0

    be.rng_reset()
    be.make_binary_mask(out=x)
    x1_2 = x.get().copy()

    assert np.max(np.abs(x1-x1_2)) == 0.0

    be.rng_reset()
    be.rng_set_state(r1)
    be.make_binary_mask(out=x)
    x2_2 = x.get().copy()

    assert np.max(np.abs(x2-x2_2)) == 0.0
dataset/ETHPy150Open NervanaSystems/neon/neon/backends/tests/test_randomstate.py/test_rng_funcs/original