Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 空指针 (Null pointer) of case 17 paddle.flip #49972

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/paddle/fluid/tests/unittests/test_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ def test_grad(self):
self.func(p)


class TestFlipError(unittest.TestCase):
def test_axis(self):
paddle.enable_static()

def test_axis_rank():
input = fluid.data(name='input', dtype='float32', shape=[2, 3])
output = paddle.flip(input, axis=[[0]])

self.assertRaises(ValueError, test_axis_rank)


if __name__ == "__main__":
paddle.enable_static()
unittest.main()
3 changes: 3 additions & 0 deletions python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,9 @@ def flip(x, axis, name=None):
if isinstance(axis, int):
axis = [axis]

if np.array(axis).ndim != 1:
raise ValueError('The axis of flip must be a list, tuple or int.')

if in_dygraph_mode():
return _C_ops.flip(x, axis)
else:
Expand Down