55
66import os
77import unittest
8- from distutils .version import LooseVersion
8+ from packaging .version import Version
99from itertools import product
1010
1111import numpy as np
7272 matrix_diag_part = tf .compat .v1 .matrix_diag_part
7373 fake_quant_with_min_max_args = tf .quantization .fake_quant_with_min_max_args
7474 fake_quant_with_min_max_vars = tf .quantization .fake_quant_with_min_max_vars
75- elif LooseVersion (tf .__version__ ) >= "1.13" :
75+ elif Version (tf .__version__ ) >= Version ( "1.13" ) :
7676 conv2d_backprop_input = tf .compat .v1 .nn .conv2d_backprop_input
7777 conv3d_transpose = tf .compat .v1 .nn .conv3d_transpose
7878 multinomial = tf .compat .v1 .random .multinomial
8686 quantize_and_dequantize = tf .compat .v1 .quantization .quantize_and_dequantize
8787 resize_nearest_neighbor = tf .compat .v1 .image .resize_nearest_neighbor
8888 resize_bilinear = tf .compat .v1 .image .resize_bilinear
89- if LooseVersion (tf .__version__ ) >= "1.14" :
89+ if Version (tf .__version__ ) >= Version ( "1.14" ) :
9090 resize_bilinear_v2 = tf .compat .v2 .image .resize
9191 is_nan = tf .math .is_nan
9292 is_inf = tf .math .is_inf
@@ -1320,8 +1320,8 @@ def func(x1):
13201320
13211321 @check_onnxruntime_incompatibility ("Add" )
13221322 def test_logicaland (self ):
1323- x_val1 = np .array ([1 , 0 , 1 , 1 ], dtype = np . bool ).reshape ((2 , 2 ))
1324- x_val2 = np .array ([0 , 1 , 1 , 1 ], dtype = np . bool ).reshape ((2 , 2 ))
1323+ x_val1 = np .array ([1 , 0 , 1 , 1 ], dtype = bool ).reshape ((2 , 2 ))
1324+ x_val2 = np .array ([0 , 1 , 1 , 1 ], dtype = bool ).reshape ((2 , 2 ))
13251325 def func (x1 , x2 ):
13261326 mi = tf .logical_and (x1 , x2 )
13271327 return tf .identity (mi , name = _TFOUTPUT )
@@ -3505,9 +3505,9 @@ def func(x):
35053505 def test_where_bool (self ):
35063506 x_val = np .array ([1 , 2 , - 3 , 4 , - 5 ], dtype = np .float32 )
35073507 true_result = np .array ([True , False , True , False , True ],
3508- dtype = np . bool )
3508+ dtype = bool )
35093509 false_result = np .array ([False , True , False , True , True ],
3510- dtype = np . bool )
3510+ dtype = bool )
35113511 def func (x ):
35123512 picks = tf .where (x > - 1 , true_result , false_result )
35133513 return tf .identity (picks , name = _TFOUTPUT )
@@ -3770,36 +3770,36 @@ def func(input_1, input_2):
37703770 self ._run_test_case (func , [_OUTPUT ], {_INPUT : input_val_1 , _INPUT1 : input_val_2 }, rtol = 1e-4 )
37713771
37723772 def test_logical_not (self ):
3773- input_val = np .random .randint (0 , 2 , (10 , 20 )).astype (np . bool )
3773+ input_val = np .random .randint (0 , 2 , (10 , 20 )).astype (bool )
37743774 def func (x ):
37753775 res = tf .logical_not (x )
37763776 return tf .identity (res , name = _TFOUTPUT )
37773777 self ._run_test_case (func , [_OUTPUT ], {_INPUT : input_val })
37783778
37793779 def test_reduce_all (self ):
3780- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3780+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
37813781 def func (x ):
37823782 res = tf .reduce_all (input_tensor = x , keepdims = False )
37833783 res1 = tf .reduce_all (input_tensor = x , axis = [0 ], keepdims = False )
37843784 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
37853785 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
37863786
3787- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3787+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
37883788 def func (input_x ):
37893789 res = tf .reduce_all (input_tensor = input_x , keepdims = True )
37903790 res1 = tf .reduce_all (input_tensor = input_x , axis = [0 ], keepdims = True )
37913791 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
37923792 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
37933793
37943794 def test_reduce_any (self ):
3795- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3795+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
37963796 def func (x ):
37973797 res = tf .reduce_any (input_tensor = x , keepdims = False )
37983798 res1 = tf .reduce_any (input_tensor = x , axis = [0 ], keepdims = False )
37993799 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
38003800 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
38013801
3802- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3802+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38033803 def func (x ):
38043804 res = tf .reduce_any (input_tensor = x , keepdims = True )
38053805 res1 = tf .reduce_any (input_tensor = x , axis = [0 ], keepdims = True )
@@ -3808,14 +3808,14 @@ def func(x):
38083808
38093809 @check_opset_min_version (11 , "ReduceMin" )
38103810 def test_reduce_all_negative_axis (self ):
3811- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3811+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38123812 def func (x ):
38133813 res = tf .reduce_all (input_tensor = x , keepdims = False )
38143814 res1 = tf .reduce_all (input_tensor = x , axis = [- 1 ], keepdims = False )
38153815 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
38163816 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
38173817
3818- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3818+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38193819 def func (input_x ):
38203820 res = tf .reduce_all (input_tensor = input_x , keepdims = True )
38213821 res1 = tf .reduce_all (input_tensor = input_x , axis = [- 1 ], keepdims = True )
@@ -3824,14 +3824,14 @@ def func(input_x):
38243824
38253825 @check_opset_min_version (11 , "ReduceSum" )
38263826 def test_reduce_any_negative_axis (self ):
3827- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3827+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38283828 def func (x ):
38293829 res = tf .reduce_any (input_tensor = x , keepdims = False )
38303830 res1 = tf .reduce_any (input_tensor = x , axis = [- 1 ], keepdims = False )
38313831 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
38323832 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
38333833
3834- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3834+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38353835 def func (x ):
38363836 res = tf .reduce_any (input_tensor = x , keepdims = True )
38373837 res1 = tf .reduce_any (input_tensor = x , axis = [- 1 ], keepdims = True )
@@ -3841,15 +3841,15 @@ def func(x):
38413841 @check_opset_min_version (11 , "ReduceSum" )
38423842 @check_tf_min_version ("1.15" )
38433843 def test_reduce_any_empty_axis (self ):
3844- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3844+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38453845 def func (x ):
38463846 res = tf .reduce_any (input_tensor = x , keepdims = False )
38473847 res1 = tf .reduce_any (input_tensor = x , axis = [], keepdims = False )
38483848 return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
38493849 self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
38503850
38513851 def test_reduce_all_scalar_axis (self ):
3852- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3852+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38533853 def func (x ):
38543854 res = tf .reduce_all (input_tensor = x , keepdims = False )
38553855 res1 = tf .reduce_all (input_tensor = x , axis = 0 , keepdims = False )
@@ -3859,7 +3859,7 @@ def func(x):
38593859 @check_opset_min_version (13 , "ReduceSum" )
38603860 @check_tf_min_version ("1.15" )
38613861 def test_reduce_any_nonconst_axis (self ):
3862- input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (np . bool )
3862+ input_val = np .random .randint (0 , 2 , (2 , 20 )).astype (bool )
38633863 y_val = np .array ([1 ], np .int32 )
38643864 def func (x , y ):
38653865 res = tf .reduce_any (input_tensor = x , axis = y , keepdims = False )
0 commit comments