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 #50028

Merged
merged 2 commits into from
Feb 6, 2023
Merged
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: 3 additions & 1 deletion paddle/fluid/pybind/op_function_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "paddle/fluid/imperative/tracer.h"
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/operators/ops_extra_info.h"
#include "paddle/fluid/pybind/eager.h"
#include "paddle/fluid/pybind/imperative.h"
#include "paddle/phi/common/complex.h"

Expand Down Expand Up @@ -70,7 +71,8 @@ bool PyObject_CheckLongOrToLong(PyObject** obj) {
if ((PyLong_Check(*obj) && !PyBool_Check(*obj)) ||
PyObject_IsInstance(*obj, (PyObject*)g_vartype_pytype) || // NOLINT
PyObject_IsInstance(*obj, (PyObject*)g_varbase_pytype) || // NOLINT
PyObject_IsInstance(*obj, (PyObject*)p_tensor_type)) { // NOLINT
(PyObject_IsInstance(*obj, (PyObject*)p_tensor_type) && // NOLINT
(((TensorObject*)(*obj))->tensor.numel() == 1))) { // NOLINT
return true;
}

Expand Down
17 changes: 17 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,23 @@ 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(TypeError, test_axis_rank)

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

self.assertRaises(TypeError, test_axis_rank2)


if __name__ == "__main__":
paddle.enable_static()
unittest.main()