Browse Source

!12495 trim down test case & add type checking for meshgrid

From: @jachua
Reviewed-by: @xsmq,@liangchenghui
Signed-off-by: @liangchenghui
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 4 years ago
parent
commit
4f13c97c9e
4 changed files with 20 additions and 15 deletions
  1. +6
    -1
      mindspore/numpy/array_creations.py
  2. +2
    -2
      tests/st/numpy_native/test_array_creations.py
  3. +3
    -3
      tests/st/numpy_native/test_array_ops.py
  4. +9
    -9
      tests/st/numpy_native/test_math_ops.py

+ 6
- 1
mindspore/numpy/array_creations.py View File

@@ -1262,7 +1262,8 @@ def meshgrid(*xi, sparse=False, indexing='xy'):
along the first dimension for `x1`, the second for `x2` and so on. along the first dimension for `x1`, the second for `x2` and so on.


Raises: 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: Supported Platforms:
``Ascend`` ``GPU`` ``CPU`` ``Ascend`` ``GPU`` ``CPU``
@@ -1285,6 +1286,10 @@ def meshgrid(*xi, sparse=False, indexing='xy'):
[1.] [1.]
""" """
_check_input_tensor(*xi) _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 = [] grids = []
for x in xi: for x in xi:


+ 2
- 2
tests/st/numpy_native/test_array_creations.py View File

@@ -744,8 +744,8 @@ def test_diag():
@pytest.mark.platform_x86_cpu @pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard @pytest.mark.env_onecard
def test_diag_indices(): 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) match_all_arrays(mnp_res, onp_res)






+ 3
- 3
tests/st/numpy_native/test_array_ops.py View File

@@ -970,7 +970,7 @@ def onp_flip(x):
return a, b, c, d return a, b, c, d




@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training @pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_gpu_training
@@ -989,7 +989,7 @@ def onp_flipud(x):
return onp.flipud(x) return onp.flipud(x)




@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training @pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_gpu_training
@@ -1008,7 +1008,7 @@ def onp_fliplr(x):
return onp.fliplr(x) return onp.fliplr(x)




@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training @pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training @pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training @pytest.mark.platform_x86_gpu_training


+ 9
- 9
tests/st/numpy_native/test_math_ops.py View File

@@ -28,7 +28,6 @@ class Cases():
rand_int(2), rand_int(2),
rand_int(2, 3), rand_int(2, 3),
rand_int(2, 3, 4), rand_int(2, 3, 4),
rand_int(2, 3, 4, 5),
] ]


# scalars expanded across the 0th dimension # scalars expanded across the 0th dimension
@@ -36,7 +35,6 @@ class Cases():
rand_int(), rand_int(),
rand_int(1), rand_int(1),
rand_int(1, 1), rand_int(1, 1),
rand_int(1, 1, 1, 1),
] ]


# empty arrays # empty arrays
@@ -44,7 +42,6 @@ class Cases():
rand_int(0), rand_int(0),
rand_int(4, 0), rand_int(4, 0),
rand_int(2, 0, 2), rand_int(2, 0, 2),
rand_int(5, 0, 7, 0),
] ]


# arrays of the same size expanded across the 0th dimension # arrays of the same size expanded across the 0th dimension
@@ -52,7 +49,6 @@ class Cases():
rand_int(2, 3), rand_int(2, 3),
rand_int(1, 2, 3), rand_int(1, 2, 3),
rand_int(1, 1, 2, 3), rand_int(1, 1, 2, 3),
rand_int(1, 1, 1, 2, 3),
] ]


# arrays with last dimension aligned # arrays with last dimension aligned
@@ -68,7 +64,6 @@ class Cases():
rand_int(5), rand_int(5),
rand_int(6, 1), rand_int(6, 1),
rand_int(7, 1, 5), rand_int(7, 1, 5),
rand_int(8, 1, 6, 1)
] ]


# boolean arrays which can be broadcast # boolean arrays which can be broadcast
@@ -972,7 +967,9 @@ def onp_remainder(x, y):
@pytest.mark.platform_x86_cpu @pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard @pytest.mark.env_onecard
def test_remainder(): 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): def mnp_mod(x, y):
@@ -990,7 +987,9 @@ def onp_mod(x, y):
@pytest.mark.platform_x86_cpu @pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard @pytest.mark.env_onecard
def test_mod(): 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): def mnp_fmod(x, y):
@@ -1006,7 +1005,9 @@ def onp_fmod(x, y):
@pytest.mark.platform_x86_cpu @pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard @pytest.mark.env_onecard
def test_fmod(): 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): def mnp_fix(x):
@@ -1028,7 +1029,6 @@ def test_fix():
y = rand_int(2, 3) y = rand_int(2, 3)
floats = onp.divide(onp.subtract(x, y), y) floats = onp.divide(onp.subtract(x, y), y)
match_res(mnp_fix, onp_fix, floats, error=1e-5) 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): def mnp_trunc(x):


Loading…
Cancel
Save