Skip to content

Commit

Permalink
Fix unittest, test=develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zhhsplendid committed Sep 21, 2020
1 parent ea2ad88 commit 34735e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def set_test_func(self):
self.func = simple_func

def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3, 4]
self.static_abs_lineno_list = [3, 4, 5]

def set_dygraph_info(self):
self.line_num = 3
Expand Down Expand Up @@ -149,7 +149,7 @@ def set_test_func(self):
self.func = nested_func

def set_static_lineno(self):
self.static_abs_lineno_list = [2, 4, 5, 6, 7]
self.static_abs_lineno_list = [3, 5, 6, 7, 8]

def set_dygraph_info(self):
self.line_num = 5
Expand All @@ -174,7 +174,7 @@ def set_test_func(self):
self.func = decorated_func

def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3]
self.static_abs_lineno_list = [3, 4]

def set_dygraph_info(self):
self.line_num = 2
Expand Down Expand Up @@ -208,7 +208,7 @@ def set_test_func(self):
self.func = decorated_func2

def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3]
self.static_abs_lineno_list = [3, 4]

def set_dygraph_info(self):
self.line_num = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ def get_source_code(func):
class StaticCode1():
# TODO: Transform return statement
def dyfunc_with_if_else(x_v, label=None):
__return_1 = fluid.layers.fill_constant(
shape=[1], dtype='bool', value=False)
__return_0 = fluid.layers.fill_constant(
shape=[1], dtype='bool', value=False)
__return_value_init_0 = fluid.layers.fill_constant(
__return_1 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_0 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_value_init_0 = paddle.fill_constant(
shape=[1], dtype='float64', value=0.0)
__return_value_0 = __return_value_init_0

Expand All @@ -79,13 +77,13 @@ def false_fn_0(x_v):
x_v = x_v + 1
return x_v

x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
x_v = paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.layers.mean(x_v)[0] > 5, true_fn_0, false_fn_0, (x_v, ),
(x_v, ), (x_v, ))

def true_fn_1(__return_0, __return_value_0, label, x_v):
loss = fluid.layers.cross_entropy(x_v, label)
__return_0 = fluid.layers.fill_constant(
__return_0 = paddle.fill_constant(
shape=[1], dtype='bool', value=True)
__return_value_0 = loss
return __return_0, __return_value_0
Expand All @@ -94,13 +92,13 @@ def false_fn_1(__return_0, __return_value_0):
return __return_0, __return_value_0

__return_0, __return_value_0 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
label is not None, true_fn_1, false_fn_1,
(__return_0, __return_value_0, label, x_v),
(__return_0, __return_value_0), (__return_0, __return_value_0)))

def true_fn_2(__return_1, __return_value_0, x_v):
__return_1 = fluid.layers.fill_constant(
__return_1 = paddle.fill_constant(
shape=[1], dtype='bool', value=True)
__return_value_0 = x_v
return __return_1, __return_value_0
Expand All @@ -109,8 +107,8 @@ def false_fn_2(__return_1, __return_value_0):
return __return_1, __return_value_0

__return_1, __return_value_0 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
fluid.dygraph.dygraph_to_static.convert_operators.
paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
paddle.jit.dygraph_to_static.convert_operators.
convert_logical_not(__return_0), true_fn_2, false_fn_2,
(__return_1, __return_value_0, x_v),
(__return_1, __return_value_0), (__return_1, __return_value_0)))
Expand All @@ -120,11 +118,9 @@ def false_fn_2(__return_1, __return_value_0):
class StaticCode2():
# TODO: Transform return statement
def dyfunc_with_if_else(x_v, label=None):
__return_3 = fluid.layers.fill_constant(
shape=[1], dtype='bool', value=False)
__return_2 = fluid.layers.fill_constant(
shape=[1], dtype='bool', value=False)
__return_value_init_1 = fluid.layers.fill_constant(
__return_3 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_2 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_value_init_1 = paddle.fill_constant(
shape=[1], dtype='float64', value=0.0)
__return_value_1 = __return_value_init_1

Expand All @@ -136,13 +132,13 @@ def false_fn_3(x_v):
x_v = x_v + 1
return x_v

x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
x_v = paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.layers.mean(x_v)[0] > 5, true_fn_3, false_fn_3, (x_v, ),
(x_v, ), (x_v, ))

def true_fn_4(__return_2, __return_value_1, label, x_v):
loss = fluid.layers.cross_entropy(x_v, label)
__return_2 = fluid.layers.fill_constant(
__return_2 = paddle.fill_constant(
shape=[1], dtype='bool', value=True)
__return_value_1 = loss
return __return_2, __return_value_1
Expand All @@ -151,13 +147,13 @@ def false_fn_4(__return_2, __return_value_1):
return __return_2, __return_value_1

__return_2, __return_value_1 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
label is not None, true_fn_4, false_fn_4,
(__return_2, __return_value_1, label, x_v),
(__return_2, __return_value_1), (__return_2, __return_value_1)))

def true_fn_5(__return_3, __return_value_1, x_v):
__return_3 = fluid.layers.fill_constant(
__return_3 = paddle.fill_constant(
shape=[1], dtype='bool', value=True)
__return_value_1 = x_v
return __return_3, __return_value_1
Expand All @@ -166,8 +162,8 @@ def false_fn_5(__return_3, __return_value_1):
return __return_3, __return_value_1

__return_3, __return_value_1 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(
fluid.dygraph.dygraph_to_static.convert_operators.
paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
paddle.jit.dygraph_to_static.convert_operators.
convert_logical_not(__return_2), true_fn_5, false_fn_5,
(__return_3, __return_value_1, x_v),
(__return_3, __return_value_1), (__return_3, __return_value_1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ def test_feed_mismatch_shape(self):
class TestVariableTransFunc(unittest.TestCase):
def test_create_fill_constant_node(self):
node = create_fill_constant_node("a", 1.0)
source = "a = fluid.layers.fill_constant(shape=[1], dtype='float64', value=1.0)"
source = "a = paddle.fill_constant(shape=[1], dtype='float64', value=1.0)"
self.assertEqual(ast_to_source_code(node).strip(), source)

node = create_fill_constant_node("b", True)
source = "b = fluid.layers.fill_constant(shape=[1], dtype='bool', value=True)"
source = "b = paddle.fill_constant(shape=[1], dtype='bool', value=True)"
self.assertEqual(ast_to_source_code(node).strip(), source)

if six.PY2:
node = create_fill_constant_node("c", 214)
source = "c = fluid.layers.fill_constant(shape=[1], dtype='int32', value=214)"
source = "c = paddle.fill_constant(shape=[1], dtype='int32', value=214)"
self.assertEqual(ast_to_source_code(node).strip(), source)

node = create_fill_constant_node("d", long(10086))
source = "d = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10086)"
source = "d = paddle.fill_constant(shape=[1], dtype='int64', value=10086)"
self.assertEqual(ast_to_source_code(node).strip(), source)
else:
node = create_fill_constant_node("c", 4293)
source = "c = fluid.layers.fill_constant(shape=[1], dtype='int64', value=4293)"
source = "c = paddle.fill_constant(shape=[1], dtype='int64', value=4293)"
self.assertEqual(ast_to_source_code(node).strip(), source)

self.assertIsNone(create_fill_constant_node("e", None))
Expand Down

0 comments on commit 34735e9

Please sign in to comment.