27
27
28
28
29
29
def convert_dtype (dtype ):
30
- if isinstance (dtype , str ):
31
- if dtype in [
32
- 'bool' , 'float16' , 'float32' , 'float64' , 'int8' , 'int16' ,
33
- 'int32' , 'int64' , 'uint8'
34
- ]:
35
- return dtype
36
- else :
30
+ if isinstance (dtype , core .VarDesc .VarType ):
37
31
if dtype == core .VarDesc .VarType .BOOL :
38
32
return 'bool'
39
33
elif dtype == core .VarDesc .VarType .FP16 :
@@ -52,6 +46,19 @@ def convert_dtype(dtype):
52
46
return 'int64'
53
47
elif dtype == core .VarDesc .VarType .UINT8 :
54
48
return 'uint8'
49
+ else :
50
+ if dtype in [
51
+ 'bool' , 'float16' , 'float32' , 'float64' , 'int8' , 'int16' ,
52
+ 'int32' , 'int64' , 'uint8' , u'bool' , u'float16' , u'float32' ,
53
+ u'float64' , u'int8' , u'int16' , u'int32' , u'int64' , u'uint8'
54
+ ]:
55
+ # this code is a little bit dangerous, since error could happen
56
+ # when casting no-asci code to str in python2.
57
+ # but since the set itself is limited, so currently, it is good.
58
+ # however, jointly supporting python2 and python3, (as well as python4 maybe)
59
+ # may still be a long-lasting problem.
60
+ return str (dtype )
61
+
55
62
raise ValueError (
56
63
"dtype must be any of [bool, float16, float32, float64, int8, int16, "
57
64
"int32, int64, uint8]" )
0 commit comments