|
|
|
@ -116,6 +116,30 @@ class TestDygraphIfElse6(TestDygraphIfElse):
|
|
|
|
|
self.dyfunc = dyfunc_ifExp_with_while
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dyfunc_ifExp_with_while2(x):
|
|
|
|
|
y = [x]
|
|
|
|
|
|
|
|
|
|
def add_fn(x):
|
|
|
|
|
x = x + 1
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
def map_func(func, tensor_list):
|
|
|
|
|
return [func(x) for x in tensor_list]
|
|
|
|
|
|
|
|
|
|
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=0)
|
|
|
|
|
# It will be converted into `layers.cond` as followed.
|
|
|
|
|
# map_func(lambda x: fluid.layers.cond(i==0, lambda: x, lambda: add_fn(x), y)
|
|
|
|
|
# `i (Tensor) == 0` is supported in dygraph.
|
|
|
|
|
y = map_func(lambda x: x if i == 0 else add_fn(x), y)
|
|
|
|
|
return y[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDygraphIfElse7(TestDygraphIfElse):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.x = np.random.random([10, 16]).astype('float32')
|
|
|
|
|
self.dyfunc = dyfunc_ifExp_with_while2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDygraphIfElseWithAndOr(TestDygraphIfElse):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.x = np.random.random([10, 16]).astype('float32')
|
|
|
|
|