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 the indexerror of paddle.moveaxis #50004

Closed
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions python/paddle/fluid/tests/unittests/test_transpose_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ def test_error(self):
with self.assertRaises(AssertionError):
paddle.moveaxis(x, [2, 1], [10, 3])

# len of 'source' or 'destination' should not be 0.
with self.assertRaises(ValueError):
paddle.moveaxis(x, [], [])


class TestTransposeDoubleGradCheck(unittest.TestCase):
def transpose_wrapper(self, x):
Expand Down
2 changes: 2 additions & 0 deletions python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4337,6 +4337,8 @@ def moveaxis(x, source, destination, name=None):
raise ValueError("Each elemment of 'source' must be unique!")
if len(dst) != len(set(dst)):
raise ValueError("Each elemment of 'destination' must be unique!")
if len(src) == 0 or len(dst) == 0:
raise ValueError("len of 'source' or 'destination' should not be 0.")

ndim = len(x.shape)

Expand Down