diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index 4b01f2b568b0fccb895000d835fb2bbfe1ba49a3..f8e2d14a79852599420afd8c7fe922cc83b9ce9f 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -608,9 +608,10 @@ void SetStringTensorFromPyArray(phi::StringTensor *self, } template -void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor, - const py::array_t &array, - int device_id) { +void SetUVATensorFromPyArrayImpl( + framework::LoDTensor *self_tensor, + const py::array_t &array, + int device_id) { #if defined(PADDLE_WITH_CUDA) VLOG(4) << "Running in SetUVATensorFromPyArrayImpl."; std::vector dims; @@ -647,7 +648,7 @@ void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor, template void SetUVATensorFromPyArray( const std::shared_ptr &self, - const py::array_t &array, + const py::array_t &array, int device_id) { #if defined(PADDLE_WITH_CUDA) VLOG(4) << "Running in SetUVATensorFromPyArray for VarBase."; diff --git a/python/paddle/fluid/tests/unittests/test_tensor_uva.py b/python/paddle/fluid/tests/unittests/test_tensor_uva.py index 8133ce50567d87f58ec50d3670fdea2831138a5e..1261cf41b79ed0ca65b99136eda9c5820e214ae7 100644 --- a/python/paddle/fluid/tests/unittests/test_tensor_uva.py +++ b/python/paddle/fluid/tests/unittests/test_tensor_uva.py @@ -57,6 +57,17 @@ class TestUVATensorFromNumpy(unittest.TestCase): np.testing.assert_allclose(tensor.numpy(), data, rtol=1e-05) np.testing.assert_allclose(tensor2.numpy(), data, rtol=1e-05) + def test_uva_tensor_corectness(self): + if paddle.fluid.core.is_compiled_with_cuda(): + a = np.arange(0, 100, dtype="int32") + a = a.reshape([10, 10]) + slice_a = a[:, 5] + tensor1 = paddle.to_tensor(slice_a) + tensor2 = core.eager.to_uva_tensor(slice_a) + np.testing.assert_allclose(tensor1.numpy(), + tensor2.numpy(), + rtol=1e-05) + def test_uva_tensor_creation(self): with _test_eager_guard(): self.func_uva_tensor_creation()