diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index 25d2195c15cf2b121e8062f667a2ec03fc34c69a..529876a6605e175dd513a04e94e5e688c32d481b 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 1f0462ff41bfca392ea74081a6cf6dddc2ab4977..eeaa91df0dcc17dc0127c30c132a1bde8bca8703 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())