From ceaa1603c8c5b045874c2ee1fe7a9c305846e36b Mon Sep 17 00:00:00 2001 From: huangmengxi Date: Mon, 22 Feb 2021 11:44:20 +0800 Subject: [PATCH] trim down tests & add type checking for meshgrid --- mindspore/numpy/array_creations.py | 7 ++++++- tests/st/numpy_native/test_array_creations.py | 4 ++-- tests/st/numpy_native/test_array_ops.py | 6 +++--- tests/st/numpy_native/test_math_ops.py | 18 +++++++++--------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mindspore/numpy/array_creations.py b/mindspore/numpy/array_creations.py index fe6ac037ad..5d62f191e3 100644 --- a/mindspore/numpy/array_creations.py +++ b/mindspore/numpy/array_creations.py @@ -1262,7 +1262,8 @@ def meshgrid(*xi, sparse=False, indexing='xy'): along the first dimension for `x1`, the second for `x2` and so on. Raises: - TypeError: if the input is not a tensor. + TypeError: if the input is not a tensor, or sparse is not boolean, or + indexing is not 'xy' or 'ij'. Supported Platforms: ``Ascend`` ``GPU`` ``CPU`` @@ -1285,6 +1286,10 @@ def meshgrid(*xi, sparse=False, indexing='xy'): [1.] """ _check_input_tensor(*xi) + if not isinstance(sparse, bool): + _raise_type_error('argument sparse should be boolean') + if indexing not in ('xy', 'ij'): + _raise_type_error("Valid values for `indexing` are 'xy' and 'ij'.") grids = [] for x in xi: diff --git a/tests/st/numpy_native/test_array_creations.py b/tests/st/numpy_native/test_array_creations.py index 6472d646ce..431866e46f 100644 --- a/tests/st/numpy_native/test_array_creations.py +++ b/tests/st/numpy_native/test_array_creations.py @@ -744,8 +744,8 @@ def test_diag(): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_diag_indices(): - mnp_res = mnp.diag_indices(0) - onp_res = onp.diag_indices(0) + mnp_res = mnp.diag_indices(5, 7) + onp_res = onp.diag_indices(5, 7) match_all_arrays(mnp_res, onp_res) diff --git a/tests/st/numpy_native/test_array_ops.py b/tests/st/numpy_native/test_array_ops.py index 4060cebf71..542b4b97e1 100644 --- a/tests/st/numpy_native/test_array_ops.py +++ b/tests/st/numpy_native/test_array_ops.py @@ -970,7 +970,7 @@ def onp_flip(x): return a, b, c, d -@pytest.mark.level1 +@pytest.mark.level2 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_gpu_training @@ -989,7 +989,7 @@ def onp_flipud(x): return onp.flipud(x) -@pytest.mark.level1 +@pytest.mark.level2 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_gpu_training @@ -1008,7 +1008,7 @@ def onp_fliplr(x): return onp.fliplr(x) -@pytest.mark.level1 +@pytest.mark.level2 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_gpu_training diff --git a/tests/st/numpy_native/test_math_ops.py b/tests/st/numpy_native/test_math_ops.py index 3803e2bf64..a6d87d845d 100644 --- a/tests/st/numpy_native/test_math_ops.py +++ b/tests/st/numpy_native/test_math_ops.py @@ -28,7 +28,6 @@ class Cases(): rand_int(2), rand_int(2, 3), rand_int(2, 3, 4), - rand_int(2, 3, 4, 5), ] # scalars expanded across the 0th dimension @@ -36,7 +35,6 @@ class Cases(): rand_int(), rand_int(1), rand_int(1, 1), - rand_int(1, 1, 1, 1), ] # empty arrays @@ -44,7 +42,6 @@ class Cases(): rand_int(0), rand_int(4, 0), rand_int(2, 0, 2), - rand_int(5, 0, 7, 0), ] # arrays of the same size expanded across the 0th dimension @@ -52,7 +49,6 @@ class Cases(): rand_int(2, 3), rand_int(1, 2, 3), rand_int(1, 1, 2, 3), - rand_int(1, 1, 1, 2, 3), ] # arrays with last dimension aligned @@ -68,7 +64,6 @@ class Cases(): rand_int(5), rand_int(6, 1), rand_int(7, 1, 5), - rand_int(8, 1, 6, 1) ] # boolean arrays which can be broadcast @@ -972,7 +967,9 @@ def onp_remainder(x, y): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_remainder(): - run_binop_test(mnp_remainder, onp_remainder, test_case) + x = rand_int(2, 3) + y = rand_int(2, 3) + match_res(mnp_remainder, onp_remainder, x, y) def mnp_mod(x, y): @@ -990,7 +987,9 @@ def onp_mod(x, y): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_mod(): - run_binop_test(mnp_mod, onp_mod, test_case) + x = rand_int(2, 3) + y = rand_int(2, 3) + match_res(mnp_mod, onp_mod, x, y) def mnp_fmod(x, y): @@ -1006,7 +1005,9 @@ def onp_fmod(x, y): @pytest.mark.platform_x86_cpu @pytest.mark.env_onecard def test_fmod(): - run_binop_test(mnp_fmod, onp_fmod, test_case) + x = rand_int(2, 3) + y = rand_int(2, 3) + match_res(mnp_fmod, onp_fmod, x, y) def mnp_fix(x): @@ -1028,7 +1029,6 @@ def test_fix(): y = rand_int(2, 3) floats = onp.divide(onp.subtract(x, y), y) match_res(mnp_fix, onp_fix, floats, error=1e-5) - run_binop_test(mnp_fmod, onp_fmod, test_case, error=1e-5) def mnp_trunc(x):