layers.reverse gets unexpected behavior with negative axis
Created by: iclementine
Thank you for contributing to PaddlePaddle. Before submitting the issue, you could search issue in the github in case that there was a similar issue submitted or resolved before. If there is no solution,please provide us with the following details : System information -PaddlePaddle version 2019/12/19 develop -GPU: cuda 10.1 / cudnn 7.5 -OS Platform and DistributionL ubuntu 16.04LTS -Python version 3.7.4
reproduce:
import numpy as np
from paddle import fluid
import paddle.fluid.layers as F
import paddle.fluid.dygraph as dg
x = np.reshape(np.arange(20), (4, 5)).astype(np.float32)
print(x)
place = fluid.CPUPlace()
with dg.guard(place):
x_var = dg.to_variable(x)
y_var = F.reverse(x_var, axis=-1)
y_np = y_var.numpy()
print(y_np)
output:
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[10. 11. 12. 13. 14.]
[15. 16. 17. 18. 19.]]
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[10. 11. 12. 13. 14.]
[15. 16. 17. 18. 19.]]
expected ouput:
[[ 0. 1. 2. 3. 4.]
[ 5. 6. 7. 8. 9.]
[10. 11. 12. 13. 14.]
[15. 16. 17. 18. 19.]]
[[ 4. 3. 2. 1. 0.]
[ 9. 8. 7. 6. 5.]
[14. 13. 12. 11. 10.]
[19. 18. 17. 16. 15.]]
When I use axis=1, I get the expected behavior.