From 288b1e75de24410c1f6156d8ae06a53002375a9f Mon Sep 17 00:00:00 2001 From: Qinghe JING Date: Mon, 6 Jan 2020 13:08:28 +0800 Subject: [PATCH] Fix segmentation fault bug in reduce ops (#22079) * fix dim=[] bug in reduce ops --- python/paddle/fluid/layers/nn.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 8fa7d29a631..c1fdf12df73 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -3882,9 +3882,9 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None): if dim is not None and not isinstance(dim, list): dim = [dim] attrs = { - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False } if in_dygraph_mode(): @@ -3957,9 +3957,9 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None): if dim is not None and not isinstance(dim, list): dim = [dim] attrs = { - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False } if in_dygraph_mode(): @@ -4034,9 +4034,9 @@ def reduce_max(input, dim=None, keep_dim=False, name=None): inputs={'X': input}, outputs={'Out': out}, attrs={ - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False }) return out @@ -4095,9 +4095,9 @@ def reduce_min(input, dim=None, keep_dim=False, name=None): inputs={'X': input}, outputs={'Out': out}, attrs={ - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False }) return out @@ -4157,9 +4157,9 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None): inputs={'X': input}, outputs={'Out': out}, attrs={ - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False }) return out @@ -4215,9 +4215,9 @@ def reduce_all(input, dim=None, keep_dim=False, name=None): inputs={'X': input}, outputs={'Out': out}, attrs={ - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False }) return out @@ -4273,9 +4273,9 @@ def reduce_any(input, dim=None, keep_dim=False, name=None): inputs={'X': input}, outputs={'Out': out}, attrs={ - 'dim': dim if dim != None else [0], + 'dim': dim if dim != None and dim != [] else [0], 'keep_dim': keep_dim, - 'reduce_all': True if dim == None else False + 'reduce_all': True if dim == None or dim == [] else False }) return out -- GitLab