17
17
18
18
class PDCase (PaddleAPIBenchmarkBase ):
19
19
def build_program (self , config ):
20
- zero_var = fluid .layers .zeros (
21
- shape = config .input_shape , dtype = config .input_dtype )
22
20
five_var = fluid .layers .fill_constant (
23
21
shape = config .input_shape , dtype = config .input_dtype , value = 5 )
22
+ ten_var = fluid .layers .fill_constant (
23
+ shape = config .input_shape , dtype = config .input_dtype , value = 10 )
24
+ one_var = fluid .layers .ones (
25
+ shape = config .input_shape , dtype = config .input_dtype )
24
26
25
27
x = self .variable (name = 'x' , shape = config .x_shape , dtype = config .x_dtype )
26
28
y = self .variable (name = 'y' , shape = config .y_shape , dtype = config .y_dtype )
27
- input = self .variable (
28
- name = 'input' , shape = config .input_shape , dtype = config .input_dtype )
29
29
30
30
def f1 ():
31
31
return fluid .layers .elementwise_add (x = x , y = y )
@@ -36,28 +36,27 @@ def f2():
36
36
def f3 ():
37
37
return fluid .layers .elementwise_mul (x = x , y = y )
38
38
39
- pred_1 = fluid .layers .less_than (input , zero_var )
40
- pred_2 = fluid .layers .greater_than (input , five_var )
39
+ pred_1 = fluid .layers .less_than (one_var , five_var )
40
+ pred_2 = fluid .layers .greater_than (one_var , ten_var )
41
41
42
42
result = fluid .layers .case (
43
43
pred_fn_pairs = [(pred_1 , f1 ), (pred_2 , f2 )], default = f3 )
44
- self .feed_vars = [x , y , input ]
44
+ self .feed_vars = [x , y ]
45
45
self .fetch_vars = [result ]
46
46
if config .backward :
47
47
self .append_gradients (result , [x , y ])
48
48
49
49
50
50
class TFCase (TensorflowAPIBenchmarkBase ):
51
51
def build_graph (self , config ):
52
- zero_var = tf .constant (
53
- 0 , shape = config .input_shape , dtype = config .input_dtype )
54
52
five_var = tf .constant (
55
53
5 , shape = config .input_shape , dtype = config .input_dtype )
54
+ ten_var = tf .constant (
55
+ 10 , shape = config .input_shape , dtype = config .input_dtype )
56
+ one_var = tf .ones (shape = config .input_shape , dtype = config .input_dtype )
56
57
57
58
x = self .variable (name = 'x' , shape = config .x_shape , dtype = config .x_dtype )
58
59
y = self .variable (name = 'y' , shape = config .y_shape , dtype = config .y_dtype )
59
- input = self .variable (
60
- name = 'input' , shape = config .input_shape , dtype = config .input_dtype )
61
60
62
61
def f1 ():
63
62
return tf .add (x , y )
@@ -68,13 +67,13 @@ def f2():
68
67
def f3 ():
69
68
return tf .multiply (x , y )
70
69
71
- pred_1 = tf .less (input , zero_var )
72
- pred_2 = tf .greater (input , five_var )
70
+ pred_1 = tf .less (one_var , five_var )
71
+ pred_2 = tf .greater (one_var , ten_var )
73
72
74
73
result = tf .case (
75
74
[(tf .reshape (pred_1 , []), f1 ), (tf .reshape (pred_2 , []), f2 )],
76
75
default = f3 )
77
- self .feed_list = [x , y , input ]
76
+ self .feed_list = [x , y ]
78
77
self .fetch_list = [result ]
79
78
if config .backward :
80
79
self .append_gradients (result , [x , y ])
0 commit comments