From 05476e9f694a041fa2de8ef43e74ec3f8ec10d00 Mon Sep 17 00:00:00 2001 From: wawltor Date: Sat, 11 Apr 2020 12:18:25 +0800 Subject: [PATCH] Fix the matmul test case, avoid double and float precision diff reduce the pricision of test case for matmul --- .../fluid/tests/unittests/test_matmul_op.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_matmul_op.py b/python/paddle/fluid/tests/unittests/test_matmul_op.py index b4d975fb5ed..76199abb310 100644 --- a/python/paddle/fluid/tests/unittests/test_matmul_op.py +++ b/python/paddle/fluid/tests/unittests/test_matmul_op.py @@ -253,10 +253,14 @@ class API_TestMm(unittest.TestCase): exe = fluid.Executor(fluid.CPUPlace()) data1 = np.random.rand(3, 2) data2 = np.random.rand(2, 3) - np_res, np_y_1 = exe.run(feed={'x': data1, - 'y': data2}, - fetch_list=[res, y_1]) - self.assertEqual((np_res == np_y_1).all(), True) + np_res, expected_result = exe.run(feed={'x': data1, + 'y': data2}, + fetch_list=[res, y_1]) + self.assertTrue( + np.allclose( + np.array(np_res), np.array(expected_result), atol=1e-5), + "two value is\ + {}\n{}, check diff!".format(np_res, expected_result)) with fluid.program_guard(fluid.Program()): x = fluid.data(name="x", shape=[2], dtype="float64") @@ -270,7 +274,11 @@ class API_TestMm(unittest.TestCase): expected_result = np.matmul( data1.reshape(1, 2), data2.reshape(2, 1)) - self.assertEqual((np_res == expected_result).all(), True) + self.assertTrue( + np.allclose( + np_res, expected_result, atol=1e-5), + "two value is\ + {}\n{}, check diff!".format(np_res, expected_result)) class API_TestMmError(unittest.TestCase): -- GitLab