diff --git a/python/paddle/fluid/tests/unittests/eager_op_test.py b/python/paddle/fluid/tests/unittests/eager_op_test.py index 737f0d7b9bc5f58d7378fede5746dc29d4e8e08d..e42a83f0653f5a641f05dc17ef2b7a073f39816a 100644 --- a/python/paddle/fluid/tests/unittests/eager_op_test.py +++ b/python/paddle/fluid/tests/unittests/eager_op_test.py @@ -1604,6 +1604,23 @@ class OpTest(unittest.TestCase): raise NotImplementedError("base class, not implement!") def _compare_numpy(self, name, actual_np, expect_np): + if actual_np.shape == expect_np.shape: + np.testing.assert_allclose( + actual_np, + expect_np, + atol=atol, + rtol=self.rtol if hasattr(self, 'rtol') else 1e-5, + equal_nan=equal_nan, + err_msg=( + "Output (" + + name + + ") has diff at " + + str(place) + + " in " + + self.checker_name + ), + ) + return self.op_test.assertTrue( np.allclose( actual_np, @@ -1777,6 +1794,23 @@ class OpTest(unittest.TestCase): ): pass else: + if actual_np.shape == expect_np.shape: + np.testing.assert_allclose( + actual_np, + expect_np, + atol=atol, + rtol=self.rtol if hasattr(self, 'rtol') else 1e-5, + equal_nan=equal_nan, + err_msg=( + "Output (" + + name + + ") has diff at " + + str(place) + + " in " + + self.checker_name + ), + ) + return self.op_test.assertTrue( np.allclose( actual_np, diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 9edf5565519cd2019fc0ba04a5e3cc0883d6275a..0c2f88490e69f0673fbb8624384f21939a159780 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -1599,6 +1599,23 @@ class OpTest(unittest.TestCase): raise NotImplementedError("base class, not implement!") def _compare_numpy(self, name, actual_np, expect_np): + if actual_np.shape == expect_np.shape: + np.testing.assert_allclose( + actual_np, + expect_np, + atol=atol, + rtol=self.rtol if hasattr(self, 'rtol') else 1e-5, + equal_nan=equal_nan, + err_msg=( + "Output (" + + name + + ") has diff at " + + str(place) + + " in " + + self.checker_name + ), + ) + return self.op_test.assertTrue( np.allclose( actual_np, @@ -1810,6 +1827,23 @@ class OpTest(unittest.TestCase): ): pass else: + if actual_np.shape == expect_np.shape: + np.testing.assert_allclose( + actual_np, + expect_np, + atol=atol, + rtol=self.rtol if hasattr(self, 'rtol') else 1e-5, + equal_nan=equal_nan, + err_msg=( + "Output (" + + name + + ") has diff at " + + str(place) + + " in " + + self.checker_name + ), + ) + return self.op_test.assertTrue( np.allclose( actual_np, diff --git a/python/paddle/fluid/tests/unittests/test_assign_pos_op.py b/python/paddle/fluid/tests/unittests/test_assign_pos_op.py index ea517e2f9785c9eb327bb6ad0e92468112d262b7..ecc91b1f4c85a0f0b6746fad6b3bcb7a9036d32a 100644 --- a/python/paddle/fluid/tests/unittests/test_assign_pos_op.py +++ b/python/paddle/fluid/tests/unittests/test_assign_pos_op.py @@ -87,7 +87,7 @@ class TestAssignPosOpInt64(op_test.OpTest): self.cum_count = cum_count def test_forward(self): - np.allclose = get_redefined_allclose(self.cum_count) + np.testing.assert_allclose = get_redefined_allclose(self.cum_count) self.check_output_with_place(paddle.CUDAPlace(0))