@@ -37,29 +37,39 @@ def test_backward(self):
37
37
self .check_grad (['X' ], 'Out' )
38
38
39
39
40
+ class TestAssignFP16Op (op_test .OpTest ):
41
+ def setUp (self ):
42
+ self .op_type = "assign"
43
+ x = np .random .random (size = (100 , 10 )).astype ('float16' )
44
+ self .inputs = {'X' : x }
45
+ self .outputs = {'Out' : x }
46
+
47
+ def test_forward (self ):
48
+ self .check_output ()
49
+
50
+ def test_backward (self ):
51
+ self .check_grad (['X' ], 'Out' )
52
+
53
+
40
54
class TestAssignOpError (unittest .TestCase ):
41
55
def test_errors (self ):
42
56
with program_guard (Program (), Program ()):
43
57
# The type of input must be Variable or numpy.ndarray.
44
58
x1 = fluid .create_lod_tensor (
45
59
np .array ([[- 1 ]]), [[1 ]], fluid .CPUPlace ())
46
60
self .assertRaises (TypeError , fluid .layers .assign , x1 )
47
- # When the type of input is Variable, the dtype of input must be float32, float64, int32, int64, bool.
48
- x3 = fluid .layers .data (name = 'x3' , shape = [4 ], dtype = "float16 " )
61
+ # When the type of input is Variable, the dtype of input must be float16, float32, float64, int32, int64, bool.
62
+ x3 = fluid .layers .data (name = 'x3' , shape = [4 ], dtype = "uint8 " )
49
63
self .assertRaises (TypeError , fluid .layers .assign , x3 )
50
- x4 = fluid .layers .data (name = 'x4' , shape = [4 ], dtype = "uint8" )
51
- self .assertRaises (TypeError , fluid .layers .assign , x4 )
52
64
# When the type of input is numpy.ndarray, the dtype of input must be float32, int32.
53
- x5 = np .array ([[2.5 , 2.5 ]], dtype = 'bool' )
65
+ x4 = np .array ([[2.5 , 2.5 ]], dtype = 'bool' )
66
+ self .assertRaises (TypeError , fluid .layers .assign , x4 )
67
+ x5 = np .array ([[2.5 , 2.5 ]], dtype = 'float64' )
54
68
self .assertRaises (TypeError , fluid .layers .assign , x5 )
55
- x6 = np .array ([[2.5 , 2.5 ]], dtype = 'float16 ' )
69
+ x6 = np .array ([[2.5 , 2.5 ]], dtype = 'int64 ' )
56
70
self .assertRaises (TypeError , fluid .layers .assign , x6 )
57
- x7 = np .array ([[2.5 , 2.5 ]], dtype = 'float64 ' )
71
+ x7 = np .array ([[2.5 , 2.5 ]], dtype = 'uint8 ' )
58
72
self .assertRaises (TypeError , fluid .layers .assign , x7 )
59
- x8 = np .array ([[2.5 , 2.5 ]], dtype = 'int64' )
60
- self .assertRaises (TypeError , fluid .layers .assign , x8 )
61
- x9 = np .array ([[2.5 , 2.5 ]], dtype = 'uint8' )
62
- self .assertRaises (TypeError , fluid .layers .assign , x9 )
63
73
64
74
65
75
if __name__ == '__main__' :
0 commit comments