reduce precision limit

This commit is contained in:
huangmengxi 2021-10-13 09:36:08 +08:00
parent ef44a0a981
commit 4f246a4be9
2 changed files with 6 additions and 9 deletions

View File

@ -2137,7 +2137,7 @@ def test_histogram():
mnp_res = mnp.histogram(to_tensor(x), bins=bins, range=range,
weights=to_tensor(weights), density=True)
onp_res = onp.histogram(x, bins=bins, range=range, weights=weights, density=True)
match_all_arrays(mnp_res, onp_res, error=1)
match_all_arrays(mnp_res, onp_res, error=0)
@pytest.mark.level0
@ -2161,8 +2161,8 @@ def test_histogramdd():
mnp_res = mnp.histogramdd(mnp_y, bins=bins, range=range, weights=to_tensor(weights),
density=True)
onp_res = onp.histogramdd(y, bins, range=range, weights=weights, density=True)
match_all_arrays(mnp_res[0], onp_res[0], error=1)
match_all_arrays(mnp_res[1], onp_res[1], error=1)
match_all_arrays(mnp_res[0], onp_res[0], error=0)
match_all_arrays(mnp_res[1], onp_res[1], error=0)
bins = onp.arange(24).reshape(3, 8)
mnp_res = mnp.histogramdd(to_tensor(x), bins=to_tensor(bins))
@ -2189,7 +2189,7 @@ def test_histogram2d():
mnp_res = mnp.histogram2d(to_tensor(x), to_tensor(y), bins=bins, range=range,
weights=to_tensor(weights), density=True)
onp_res = onp.histogram2d(x, y, bins=bins, range=range, weights=weights, density=True)
match_all_arrays(mnp_res, onp_res, error=1)
match_all_arrays(mnp_res, onp_res, error=0)
@pytest.mark.level1

View File

@ -27,11 +27,8 @@ def match_array(actual, expected, error=0):
if isinstance(expected, (int, tuple)):
expected = onp.asarray(expected)
if error > 0:
onp.testing.assert_almost_equal(actual.tolist(), expected.tolist(),
decimal=error)
else:
onp.testing.assert_equal(actual.tolist(), expected.tolist())
onp.testing.assert_almost_equal(actual.tolist(), expected.tolist(),
decimal=error)
def check_all_results(onp_results, mnp_results, error=0):