diff --git a/test/legacy_test/test_complex_elementwise_layers.py b/test/legacy_test/test_complex_elementwise_layers.py index fe23f287155359..ea579cbf0948b4 100644 --- a/test/legacy_test/test_complex_elementwise_layers.py +++ b/test/legacy_test/test_complex_elementwise_layers.py @@ -38,8 +38,8 @@ def setUp(self): def paddle_calc(self, x, y, op, place): with dg.guard(place): - x_t = dg.to_variable(x) - y_t = dg.to_variable(y) + x_t = paddle.to_tensor(x) + y_t = paddle.to_tensor(y) return paddle_apis[op](x_t, y_t).numpy() def assert_check(self, pd_result, np_result, place): @@ -72,8 +72,8 @@ def compare_by_basic_api(self, x, y): def compare_op_by_basic_api(self, x, y): for place in self._places: with dg.guard(place): - var_x = dg.to_variable(x) - var_y = dg.to_variable(y) + var_x = paddle.to_tensor(x) + var_y = paddle.to_tensor(y) self.assert_check((var_x + var_y).numpy(), x + y, place) self.assert_check((var_x - var_y).numpy(), x - y, place) self.assert_check((var_x * var_y).numpy(), x * y, place) diff --git a/test/legacy_test/test_complex_getitem.py b/test/legacy_test/test_complex_getitem.py index a3b249212e93d0..a7356af8052b8e 100644 --- a/test/legacy_test/test_complex_getitem.py +++ b/test/legacy_test/test_complex_getitem.py @@ -16,6 +16,7 @@ import numpy as np +import paddle import paddle.base.dygraph as dg from paddle import base @@ -32,7 +33,7 @@ def test_case1(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) @@ -43,7 +44,7 @@ def test_case2(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0][1] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) @@ -54,7 +55,7 @@ def test_case3(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0][1][2] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) @@ -65,7 +66,7 @@ def test_case4(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0][1][0:3] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) @@ -76,7 +77,7 @@ def test_case5(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0][1][0:4:2] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) @@ -89,7 +90,7 @@ def test_case6(self): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) x_var_slice = x_var[0][1:3][0:4:2] np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) diff --git a/test/legacy_test/test_complex_kron.py b/test/legacy_test/test_complex_kron.py index fe6a14bf56b89f..d46b8e227ba080 100644 --- a/test/legacy_test/test_complex_kron.py +++ b/test/legacy_test/test_complex_kron.py @@ -39,8 +39,8 @@ def runTest(self): def test_kron_api(self, place): with dg.guard(place): - x_var = dg.to_variable(self.x) - y_var = dg.to_variable(self.y) + x_var = paddle.to_tensor(self.x) + y_var = paddle.to_tensor(self.y) out_var = paddle.kron(x_var, y_var) np.testing.assert_allclose( out_var.numpy(), self.ref_result, rtol=1e-05 diff --git a/test/legacy_test/test_complex_matmul.py b/test/legacy_test/test_complex_matmul.py index 36c0e435111895..8740571587a7a8 100644 --- a/test/legacy_test/test_complex_matmul.py +++ b/test/legacy_test/test_complex_matmul.py @@ -31,8 +31,8 @@ def setUp(self): def compare_by_basic_api(self, x, y, np_result): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x) - y_var = dg.to_variable(y) + x_var = paddle.to_tensor(x) + y_var = paddle.to_tensor(y) result = paddle.matmul(x_var, y_var) pd_result = result.numpy() np.testing.assert_allclose( @@ -49,8 +49,8 @@ def compare_by_basic_api(self, x, y, np_result): def compare_op_by_basic_api(self, x, y, np_result): for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x) - y_var = dg.to_variable(y) + x_var = paddle.to_tensor(x) + y_var = paddle.to_tensor(y) result = x_var.matmul(y_var) pd_result = result.numpy() np.testing.assert_allclose( diff --git a/test/legacy_test/test_complex_reshape.py b/test/legacy_test/test_complex_reshape.py index 14eb0fd75e7298..efcb1adf753efe 100644 --- a/test/legacy_test/test_complex_reshape.py +++ b/test/legacy_test/test_complex_reshape.py @@ -36,7 +36,7 @@ def test_shape_norm_dims(self): shape = (2, -1) for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) y_var = paddle.reshape(x_var, shape) y_np = y_var.numpy() np.testing.assert_allclose( @@ -52,7 +52,7 @@ def test_shape_omit_dims(self): shape_ = (2, 12) for place in self._places: with dg.guard(place): - x_var = dg.to_variable(x_np) + x_var = paddle.to_tensor(x_np) y_var = paddle.reshape(x_var, shape) y_np = y_var.numpy() np.testing.assert_allclose( diff --git a/test/legacy_test/test_complex_sum_layer.py b/test/legacy_test/test_complex_sum_layer.py index 2ecbdbef4cfafa..f39e4959fb7b6f 100644 --- a/test/legacy_test/test_complex_sum_layer.py +++ b/test/legacy_test/test_complex_sum_layer.py @@ -36,7 +36,7 @@ def test_complex_basic_api(self): ).astype(dtype) for place in self._places: with dg.guard(place): - var_x = dg.to_variable(input) + var_x = paddle.to_tensor(input) result = tensor.sum(var_x, axis=[1, 2]).numpy() target = np.sum(input, axis=(1, 2)) np.testing.assert_allclose(result, target, rtol=1e-05) diff --git a/test/legacy_test/test_complex_trace_layer.py b/test/legacy_test/test_complex_trace_layer.py index 3df257fe4e916f..bcb3057b766522 100644 --- a/test/legacy_test/test_complex_trace_layer.py +++ b/test/legacy_test/test_complex_trace_layer.py @@ -17,6 +17,7 @@ import numpy as np from numpy.random import random as rand +import paddle import paddle.base.dygraph as dg from paddle import base, tensor @@ -35,7 +36,7 @@ def test_basic_api(self): ).astype(dtype) for place in self._places: with dg.guard(place): - var_x = dg.to_variable(input) + var_x = paddle.to_tensor(input) result = tensor.trace( var_x, offset=1, axis1=0, axis2=2 ).numpy() diff --git a/test/legacy_test/test_complex_transpose.py b/test/legacy_test/test_complex_transpose.py index 5ce77e6e00715c..7754b40cc82637 100644 --- a/test/legacy_test/test_complex_transpose.py +++ b/test/legacy_test/test_complex_transpose.py @@ -37,7 +37,7 @@ def test_transpose_by_complex_api(self): np_trans = np.transpose(data, perm) for place in self._places: with dg.guard(place): - var = dg.to_variable(data) + var = paddle.to_tensor(data) trans = paddle.transpose(var, perm=perm) np.testing.assert_allclose(trans.numpy(), np_trans, rtol=1e-05) diff --git a/test/legacy_test/test_complex_variable.py b/test/legacy_test/test_complex_variable.py index 83c4f634a78c59..9509176a7b9441 100644 --- a/test/legacy_test/test_complex_variable.py +++ b/test/legacy_test/test_complex_variable.py @@ -31,10 +31,9 @@ def compare(self): b = np.array([[1.0 + 1.0j, 1.0 + 1.0j]]).astype(self._dtype) with dg.guard(): - x = dg.to_variable(a, "x") - y = dg.to_variable(b) + x = paddle.to_tensor(a) + y = paddle.to_tensor(b) out = paddle.add(x, y) - self.assertIsNotNone(f"{out}") np.testing.assert_allclose(out.numpy(), a + b, rtol=1e-05) self.assertEqual(out.dtype, convert_np_dtype_to_dtype_(self._dtype)) diff --git a/test/legacy_test/test_conv2d_api.py b/test/legacy_test/test_conv2d_api.py index 1b02bf550f6c41..9d2398a5782caf 100644 --- a/test/legacy_test/test_conv2d_api.py +++ b/test/legacy_test/test_conv2d_api.py @@ -344,7 +344,7 @@ def run1(self, place): def run2(self, place): with base.dygraph.guard(place): - inputs = base.dygraph.to_variable(self.input_np) + inputs = paddle.to_tensor(self.input_np) conv = paddle.nn.Conv2D( in_channels=3, out_channels=4,