@@ -1962,6 +1962,45 @@ def func():
1962
1962
# since results are random, compare the shapes only
1963
1963
self ._run_test_case (func , [_OUTPUT ], {}, check_value = False , check_shape = True )
1964
1964
1965
+ def test_random_std_normal (self ):
1966
+ def func ():
1967
+ shape = tf .constant ([20 , 10 , 5 ], name = "shape" )
1968
+ x_ = tf .random .normal (shape )
1969
+ return tf .identity (x_ , name = _TFOUTPUT )
1970
+ # since results are random, compare the shapes only
1971
+ g = self ._run_test_case (func , [_OUTPUT ], {}, check_value = False , check_shape = True )
1972
+ results = self .run_backend (g , g .outputs , {})[0 ]
1973
+ self .assertTrue (- 0.1 < np .mean (results ) < 0.1 )
1974
+ self .assertTrue (0.9 < np .std (results ) < 1.1 )
1975
+
1976
+ def test_randomnormal (self ):
1977
+ def func ():
1978
+ shape = tf .constant ([20 , 10 , 5 ], name = "shape" )
1979
+ x_ = tf .random .normal (shape , mean = 10 , stddev = 2 )
1980
+ return tf .identity (x_ , name = _TFOUTPUT )
1981
+ # since results are random, compare the shapes only
1982
+ g = self ._run_test_case (func , [_OUTPUT ], {}, check_value = False , check_shape = True )
1983
+ results = self .run_backend (g , g .outputs , {})[0 ]
1984
+ if not 9.9 < np .mean (results ) < 10.1 :
1985
+ np .testing .assert_allclose (np .mean (results ), 0 )
1986
+ self .assertTrue (1.9 < np .std (results ) < 2.1 )
1987
+
1988
+ @check_opset_min_version (9 , "RandomNormalLike" )
1989
+ def test_randomnormal_unknown_shape (self ):
1990
+ shape_val = np .array ([20 , 10 , 5 ], np .int32 )
1991
+ def func (shape ):
1992
+ x_ = tf .random .normal (shape )
1993
+ return tf .identity (x_ , name = _TFOUTPUT )
1994
+ # since results are random, compare the shapes only
1995
+ feed_dict = {_INPUT : shape_val }
1996
+ g = self ._run_test_case (func , [_OUTPUT ], feed_dict , check_value = False , check_shape = True )
1997
+ if "input" in g .input_names :
1998
+ # TFLite inputs don't have port numbers
1999
+ feed_dict = {k .split (":" )[0 ]: v for k , v in feed_dict .items ()}
2000
+ results = self .run_backend (g , g .outputs , feed_dict )[0 ]
2001
+ self .assertTrue (- 0.1 < np .mean (results ) < 0.1 )
2002
+ self .assertTrue (0.9 < np .std (results ) < 1.1 )
2003
+
1965
2004
def test_randomuniform_int (self ):
1966
2005
def func ():
1967
2006
shape = tf .constant ([100 , 3 ], name = "shape" )
0 commit comments