!12495 trim down test case & add type checking for meshgrid
From: @jachua Reviewed-by: @xsmq,@liangchenghui Signed-off-by: @liangchenghui
This commit is contained in:
commit
4f13c97c9e
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue