Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/legacy_test/test_complex_elementwise_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions test/legacy_test/test_complex_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np

import paddle
import paddle.base.dygraph as dg
from paddle import base

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_complex_kron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/legacy_test/test_complex_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_complex_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_complex_sum_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/legacy_test/test_complex_trace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_complex_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions test/legacy_test/test_complex_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_conv2d_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down