5
5
6
6
import os
7
7
import unittest
8
- from distutils .version import LooseVersion
8
+ from packaging .version import Version
9
9
from itertools import product
10
10
11
11
import numpy as np
72
72
matrix_diag_part = tf .compat .v1 .matrix_diag_part
73
73
fake_quant_with_min_max_args = tf .quantization .fake_quant_with_min_max_args
74
74
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" ) :
76
76
conv2d_backprop_input = tf .compat .v1 .nn .conv2d_backprop_input
77
77
conv3d_transpose = tf .compat .v1 .nn .conv3d_transpose
78
78
multinomial = tf .compat .v1 .random .multinomial
86
86
quantize_and_dequantize = tf .compat .v1 .quantization .quantize_and_dequantize
87
87
resize_nearest_neighbor = tf .compat .v1 .image .resize_nearest_neighbor
88
88
resize_bilinear = tf .compat .v1 .image .resize_bilinear
89
- if LooseVersion (tf .__version__ ) >= "1.14" :
89
+ if Version (tf .__version__ ) >= Version ( "1.14" ) :
90
90
resize_bilinear_v2 = tf .compat .v2 .image .resize
91
91
is_nan = tf .math .is_nan
92
92
is_inf = tf .math .is_inf
@@ -1320,8 +1320,8 @@ def func(x1):
1320
1320
1321
1321
@check_onnxruntime_incompatibility ("Add" )
1322
1322
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 ))
1325
1325
def func (x1 , x2 ):
1326
1326
mi = tf .logical_and (x1 , x2 )
1327
1327
return tf .identity (mi , name = _TFOUTPUT )
@@ -3505,9 +3505,9 @@ def func(x):
3505
3505
def test_where_bool (self ):
3506
3506
x_val = np .array ([1 , 2 , - 3 , 4 , - 5 ], dtype = np .float32 )
3507
3507
true_result = np .array ([True , False , True , False , True ],
3508
- dtype = np . bool )
3508
+ dtype = bool )
3509
3509
false_result = np .array ([False , True , False , True , True ],
3510
- dtype = np . bool )
3510
+ dtype = bool )
3511
3511
def func (x ):
3512
3512
picks = tf .where (x > - 1 , true_result , false_result )
3513
3513
return tf .identity (picks , name = _TFOUTPUT )
@@ -3770,36 +3770,36 @@ def func(input_1, input_2):
3770
3770
self ._run_test_case (func , [_OUTPUT ], {_INPUT : input_val_1 , _INPUT1 : input_val_2 }, rtol = 1e-4 )
3771
3771
3772
3772
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 )
3774
3774
def func (x ):
3775
3775
res = tf .logical_not (x )
3776
3776
return tf .identity (res , name = _TFOUTPUT )
3777
3777
self ._run_test_case (func , [_OUTPUT ], {_INPUT : input_val })
3778
3778
3779
3779
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 )
3781
3781
def func (x ):
3782
3782
res = tf .reduce_all (input_tensor = x , keepdims = False )
3783
3783
res1 = tf .reduce_all (input_tensor = x , axis = [0 ], keepdims = False )
3784
3784
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3785
3785
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3786
3786
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 )
3788
3788
def func (input_x ):
3789
3789
res = tf .reduce_all (input_tensor = input_x , keepdims = True )
3790
3790
res1 = tf .reduce_all (input_tensor = input_x , axis = [0 ], keepdims = True )
3791
3791
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3792
3792
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3793
3793
3794
3794
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 )
3796
3796
def func (x ):
3797
3797
res = tf .reduce_any (input_tensor = x , keepdims = False )
3798
3798
res1 = tf .reduce_any (input_tensor = x , axis = [0 ], keepdims = False )
3799
3799
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3800
3800
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3801
3801
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 )
3803
3803
def func (x ):
3804
3804
res = tf .reduce_any (input_tensor = x , keepdims = True )
3805
3805
res1 = tf .reduce_any (input_tensor = x , axis = [0 ], keepdims = True )
@@ -3808,14 +3808,14 @@ def func(x):
3808
3808
3809
3809
@check_opset_min_version (11 , "ReduceMin" )
3810
3810
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 )
3812
3812
def func (x ):
3813
3813
res = tf .reduce_all (input_tensor = x , keepdims = False )
3814
3814
res1 = tf .reduce_all (input_tensor = x , axis = [- 1 ], keepdims = False )
3815
3815
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3816
3816
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3817
3817
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 )
3819
3819
def func (input_x ):
3820
3820
res = tf .reduce_all (input_tensor = input_x , keepdims = True )
3821
3821
res1 = tf .reduce_all (input_tensor = input_x , axis = [- 1 ], keepdims = True )
@@ -3824,14 +3824,14 @@ def func(input_x):
3824
3824
3825
3825
@check_opset_min_version (11 , "ReduceSum" )
3826
3826
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 )
3828
3828
def func (x ):
3829
3829
res = tf .reduce_any (input_tensor = x , keepdims = False )
3830
3830
res1 = tf .reduce_any (input_tensor = x , axis = [- 1 ], keepdims = False )
3831
3831
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3832
3832
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3833
3833
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 )
3835
3835
def func (x ):
3836
3836
res = tf .reduce_any (input_tensor = x , keepdims = True )
3837
3837
res1 = tf .reduce_any (input_tensor = x , axis = [- 1 ], keepdims = True )
@@ -3841,15 +3841,15 @@ def func(x):
3841
3841
@check_opset_min_version (11 , "ReduceSum" )
3842
3842
@check_tf_min_version ("1.15" )
3843
3843
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 )
3845
3845
def func (x ):
3846
3846
res = tf .reduce_any (input_tensor = x , keepdims = False )
3847
3847
res1 = tf .reduce_any (input_tensor = x , axis = [], keepdims = False )
3848
3848
return tf .identity (res , name = _TFOUTPUT ), tf .identity (res1 , name = _TFOUTPUT1 )
3849
3849
self ._run_test_case (func , [_OUTPUT , _OUTPUT1 ], {_INPUT : input_val })
3850
3850
3851
3851
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 )
3853
3853
def func (x ):
3854
3854
res = tf .reduce_all (input_tensor = x , keepdims = False )
3855
3855
res1 = tf .reduce_all (input_tensor = x , axis = 0 , keepdims = False )
@@ -3859,7 +3859,7 @@ def func(x):
3859
3859
@check_opset_min_version (13 , "ReduceSum" )
3860
3860
@check_tf_min_version ("1.15" )
3861
3861
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 )
3863
3863
y_val = np .array ([1 ], np .int32 )
3864
3864
def func (x , y ):
3865
3865
res = tf .reduce_any (input_tensor = x , axis = y , keepdims = False )
0 commit comments