From 320e76517a8f2e9a5e2aaa6efb1c65be625bcf30 Mon Sep 17 00:00:00 2001 From: sneaxiy <32832641+sneaxiy@users.noreply.github.com> Date: Tue, 20 Dec 2022 10:16:28 +0800 Subject: [PATCH] fix data_ptr method (#49173) --- paddle/fluid/pybind/eager_method.cc | 7 ++++--- .../paddle/fluid/tests/unittests/test_tensor_data_ptr.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index 25d2195c15..529876a660 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -1896,9 +1896,10 @@ static PyObject* tensor_data_ptr(TensorObject* self, PyObject* kwargs) { EAGER_TRY if (self->tensor.initialized() && self->tensor.is_dense_tensor()) { - ToPyObject((int64_t)std::dynamic_pointer_cast( // NOLINT - self->tensor.impl()) - ->data()); + return ToPyObject( + (int64_t)std::dynamic_pointer_cast( // NOLINT + self->tensor.impl()) + ->data()); } RETURN_PY_NONE EAGER_CATCH_AND_THROW_RETURN_NULL diff --git a/python/paddle/fluid/tests/unittests/test_tensor_data_ptr.py b/python/paddle/fluid/tests/unittests/test_tensor_data_ptr.py index 1f0462ff41..eeaa91df0d 100644 --- a/python/paddle/fluid/tests/unittests/test_tensor_data_ptr.py +++ b/python/paddle/fluid/tests/unittests/test_tensor_data_ptr.py @@ -25,6 +25,7 @@ class TestTensorDataPtr(unittest.TestCase): src = paddle.to_tensor(np_src, dtype="float64") dst = paddle.Tensor() src._share_buffer_to(dst) + self.assertTrue(src.data_ptr() is not None) self.assertEqual(src.data_ptr(), dst.data_ptr()) -- GitLab