From 232c4e3babdf40e5b3b96303e37539766d693fe6 Mon Sep 17 00:00:00 2001 From: cnn Date: Tue, 27 Oct 2020 10:20:39 +0800 Subject: [PATCH] fix sample code of reduce_all and reduce_any, test=document_fix (#28237) --- python/paddle/fluid/layers/nn.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 0842576413f..ac762944b3a 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -4717,15 +4717,15 @@ def reduce_all(input, dim=None, keep_dim=False, name=None): # x is a bool Tensor variable with following elements: # [[True, False] # [True, True]] - x = paddle.assign(np.array([[1, 0], [1, 1]], dtype='int32')) - x = paddle.cast(x, 'bool') + x = fluid.layers.assign(np.array([[1, 0], [1, 1]], dtype='int32')) + x = fluid.layers.cast(x, 'bool') - out = paddle.reduce_all(x) # False - out = paddle.reduce_all(x, dim=0) # [True, False] - out = paddle.reduce_all(x, dim=-1) # [False, True] + out = fluid.layers.reduce_all(x) # False + out = fluid.layers.reduce_all(x, dim=0) # [True, False] + out = fluid.layers.reduce_all(x, dim=-1) # [False, True] # keep_dim=False, x.shape=(2,2), out.shape=(2,) - out = paddle.reduce_all(x, dim=1, keep_dim=True) # [[False], [True]] + out = fluid.layers.reduce_all(x, dim=1, keep_dim=True) # [[False], [True]] # keep_dim=True, x.shape=(2,2), out.shape=(2,1) """ @@ -4777,15 +4777,15 @@ def reduce_any(input, dim=None, keep_dim=False, name=None): # x is a bool Tensor variable with following elements: # [[True, False] # [False, False]] - x = paddle.assign(np.array([[1, 0], [0, 0]], dtype='int32')) - x = paddle.cast(x, 'bool') + x = fluid.layers.assign(np.array([[1, 0], [0, 0]], dtype='int32')) + x = fluid.layers.cast(x, 'bool') - out = paddle.reduce_any(x) # True - out = paddle.reduce_any(x, dim=0) # [True, False] - out = paddle.reduce_any(x, dim=-1) # [True, False] + out = fluid.layers.reduce_any(x) # True + out = fluid.layers.reduce_any(x, dim=0) # [True, False] + out = fluid.layers.reduce_any(x, dim=-1) # [True, False] # keep_dim=False, x.shape=(2,2), out.shape=(2,) - out = paddle.reduce_any(x, dim=1, + out = fluid.layers.reduce_any(x, dim=1, keep_dim=True) # [[True], [False]] # keep_dim=True, x.shape=(2,2), out.shape=(2,1) -- GitLab