未验证 提交 320e7651 编写于 作者: S sneaxiy 提交者: GitHub

fix data_ptr method (#49173)

上级 0b79129d
...@@ -1896,7 +1896,8 @@ static PyObject* tensor_data_ptr(TensorObject* self, ...@@ -1896,7 +1896,8 @@ static PyObject* tensor_data_ptr(TensorObject* self,
PyObject* kwargs) { PyObject* kwargs) {
EAGER_TRY EAGER_TRY
if (self->tensor.initialized() && self->tensor.is_dense_tensor()) { if (self->tensor.initialized() && self->tensor.is_dense_tensor()) {
ToPyObject((int64_t)std::dynamic_pointer_cast<phi::DenseTensor>( // NOLINT return ToPyObject(
(int64_t)std::dynamic_pointer_cast<phi::DenseTensor>( // NOLINT
self->tensor.impl()) self->tensor.impl())
->data()); ->data());
} }
......
...@@ -25,6 +25,7 @@ class TestTensorDataPtr(unittest.TestCase): ...@@ -25,6 +25,7 @@ class TestTensorDataPtr(unittest.TestCase):
src = paddle.to_tensor(np_src, dtype="float64") src = paddle.to_tensor(np_src, dtype="float64")
dst = paddle.Tensor() dst = paddle.Tensor()
src._share_buffer_to(dst) src._share_buffer_to(dst)
self.assertTrue(src.data_ptr() is not None)
self.assertEqual(src.data_ptr(), dst.data_ptr()) self.assertEqual(src.data_ptr(), dst.data_ptr())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册