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

Function test_rng_empty_tensor

imperative/python/test/unit/random/test_rng.py:798–871  ·  view source on GitHub ↗
(is_symbolic)

Source from the content-addressed store, hash-verified

796
797@pytest.mark.parametrize("is_symbolic", [None, False, True])
798def test_rng_empty_tensor(is_symbolic):
799 set_global_seed(1024)
800 shapes = [
801 (0,),
802 (0, 0, 0),
803 (10, 0, 10),
804 ]
805
806 def fn(shape):
807 o1 = random.uniform(0, 1, shape)
808 o2 = random.normal(0, 1, shape)
809 o3 = random.gamma(2, 1, shape)
810 o4 = random.beta(2, 1, shape)
811 o5 = random.poisson(2, shape)
812 o6 = random.exponential(1.5, shape)
813 return o1, o2, o3, o4, o5, o6
814
815 for shape in shapes:
816 if is_symbolic is not None:
817 fn_ = jit.trace(symbolic=is_symbolic)(fn)
818 else:
819 fn_ = fn
820 for _ in range(3):
821 outs = fn_(shape)
822 for out in outs:
823 np.testing.assert_equal(out.numpy().shape, shape)
824 if is_symbolic is None:
825 break
826
827 def fn2(n):
828 return random.permutation(n=n)
829
830 if is_symbolic is not None:
831 fn2 = jit.trace(symbolic=is_symbolic)(fn2)
832
833 for _ in range(3):
834 out = fn2(0)
835 np.testing.assert_equal(out.numpy().shape, (0,))
836 if is_symbolic is None:
837 break
838
839 input_shapes_for_multinomial = [
840 (0,),
841 (0, 0),
842 (0, 10),
843 ]
844
845 output_shapes_for_multinomial = [
846 (0,),
847 (0, 0),
848 (0, 2),
849 ]
850
851 def fn3(shape, replacement):
852 input = random.normal(0, 1, shape)
853 out = random.multinomial(input=input, num_samples=2, replacement=True)
854 return out
855

Callers

nothing calls this directly

Calls 3

fn2Function · 0.85
assert_equalMethod · 0.80
numpyMethod · 0.45

Tested by

no test coverage detected