Skip to content

Commit

Permalink
add eager unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
pangyoki committed Mar 31, 2022
1 parent 3d4bcd6 commit 07611af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 19 additions & 3 deletions python/paddle/fluid/tests/unittests/test_tensor_fill_.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import numpy as np
import six
import paddle
from paddle.fluid.framework import _test_eager_guard


class TensorFill_Test(unittest.TestCase):
def setUp(self):
self.shape = [32, 32]

def test_tensor_fill_true(self):
def func_test_tensor_fill_true(self):
typelist = ['float32', 'float64', 'int32', 'int64', 'float16']
places = [fluid.CPUPlace()]
if fluid.core.is_compiled_with_cuda():
Expand All @@ -46,7 +47,12 @@ def test_tensor_fill_true(self):
tensor.fill_(var) #var type is basic type in typelist
self.assertEqual((tensor.numpy() == target).all(), True)

def test_tensor_fill_backward(self):
def test_tensor_fill_true(self):
with _test_eager_guard():
self.func_test_tensor_fill_true()
self.func_test_tensor_fill_true()

def func_test_tensor_fill_backward(self):
typelist = ['float32']
places = [fluid.CPUPlace()]
if fluid.core.is_compiled_with_cuda():
Expand All @@ -71,13 +77,23 @@ def test_tensor_fill_backward(self):

self.assertEqual((y.grad.numpy() == 0).all().item(), True)

def test_errors(self):
def test_tensor_fill_backward(self):
with _test_eager_guard():
self.func_test_tensor_fill_backward()
self.func_test_tensor_fill_backward()

def func_test_errors(self):
def test_list():
x = paddle.to_tensor([2, 3, 4])
x.fill_([1])

self.assertRaises(TypeError, test_list)

def test_errors(self):
with _test_eager_guard():
self.func_test_errors()
self.func_test_errors()


if __name__ == '__main__':
unittest.main()
8 changes: 7 additions & 1 deletion python/paddle/fluid/tests/unittests/test_tensor_zero_.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import numpy as np
import six
import paddle
from paddle.fluid.framework import _test_eager_guard


class TensorFill_Test(unittest.TestCase):
def setUp(self):
self.shape = [32, 32]

def test_tensor_fill_true(self):
def func_test_tensor_fill_true(self):
typelist = ['float32', 'float64', 'int32', 'int64', 'float16']
places = [fluid.CPUPlace()]
if fluid.core.is_compiled_with_cuda():
Expand All @@ -41,6 +42,11 @@ def test_tensor_fill_true(self):
tensor.zero_()
self.assertEqual((tensor.numpy() == target).all().item(), True)

def test_tensor_fill_true(self):
with _test_eager_guard():
self.func_test_tensor_fill_true()
self.func_test_tensor_fill_true()


if __name__ == '__main__':
unittest.main()

1 comment on commit 07611af

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.