forked from mindspore-Ecosystem/mindspore
add numpy-native ut/st test files
This commit is contained in:
parent
63672de8e6
commit
463ca2434c
|
@ -593,7 +593,7 @@ def onp_trace(arr):
|
|||
return onp.trace(arr, offset=4, axis1=1, axis2=2)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -602,16 +602,10 @@ def onp_trace(arr):
|
|||
def test_trace():
|
||||
|
||||
arr = rand_int(3, 5)
|
||||
for i in [-1, 0]:
|
||||
match_res(mnp.trace, onp.trace, arr, offset=i, axis1=0, axis2=1)
|
||||
match_res(mnp.trace, onp.trace, arr, offset=i, axis1=1, axis2=0)
|
||||
match_res(mnp.trace, onp.trace, arr, offset=-1, axis1=0, axis2=1)
|
||||
|
||||
arr = rand_int(7, 4, 9)
|
||||
for i in [-1, 0, 2]:
|
||||
match_res(mnp.trace, onp.trace, arr, offset=i, axis1=0, axis2=-1)
|
||||
match_res(mnp.trace, onp.trace, arr, offset=i, axis1=-2, axis2=2)
|
||||
match_res(mnp.trace, onp.trace, arr, offset=i, axis1=-1, axis2=-2)
|
||||
|
||||
match_res(mnp.trace, onp.trace, arr, offset=0, axis1=-2, axis2=2)
|
||||
|
||||
|
||||
def mnp_meshgrid(*xi):
|
||||
|
@ -630,7 +624,7 @@ def onp_meshgrid(*xi):
|
|||
return a, b, c, d
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -646,38 +640,6 @@ def test_meshgrid():
|
|||
match_all_arrays(mnp_res, onp_res)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
def test_mgrid():
|
||||
mnp_res = mnp.mgrid[0:5]
|
||||
onp_res = onp.mgrid[0:5]
|
||||
match_all_arrays(mnp_res, onp_res, error=5)
|
||||
|
||||
mnp_res = mnp.mgrid[2:30:4j, -10:20:7, 2:5:0.5]
|
||||
onp_res = onp.mgrid[2:30:4j, -10:20:7, 2:5:0.5]
|
||||
match_all_arrays(mnp_res, onp_res, error=5)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
def test_ogrid():
|
||||
mnp_res = mnp.ogrid[0:5]
|
||||
onp_res = onp.ogrid[0:5]
|
||||
match_all_arrays(mnp_res, onp_res, error=5)
|
||||
|
||||
mnp_res = mnp.ogrid[2:30:4j, -10:20:7, 2:5:0.5]
|
||||
onp_res = onp.ogrid[2:30:4j, -10:20:7, 2:5:0.5]
|
||||
match_all_arrays(mnp_res, onp_res, error=5)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
|
@ -920,7 +882,7 @@ def test_tril_indices_from():
|
|||
match_all_arrays(mnp_res, onp_res)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -928,11 +890,9 @@ def test_tril_indices_from():
|
|||
@pytest.mark.env_onecard
|
||||
def test_histogram_bin_edges():
|
||||
x = onp.random.randint(-10, 10, 10)
|
||||
for bins in [(1, 2, 3), [2], 1, 5, 10]:
|
||||
# pylint: disable=redefined-builtin
|
||||
for range in [None, (3, 3), (2, 20)]:
|
||||
match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, bins=bins, range=range, error=3)
|
||||
match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, onp.arange(5))
|
||||
match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, bins=(1, 2, 3), range=None, error=3)
|
||||
match_res(mnp.histogram_bin_edges, onp.histogram_bin_edges, x, bins=10, range=(2, 20), error=3)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
|
@ -968,7 +928,7 @@ def test_empty_like_exception():
|
|||
mnp.empty_like([[1, 2, 3], [4, 5]])
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
|
|
@ -610,7 +610,7 @@ def onp_where(condition, x, y):
|
|||
return onp.where(condition, x, y)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -890,7 +890,7 @@ def onp_broadcast_to(x):
|
|||
return a, b
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1252,6 +1252,10 @@ def test_select():
|
|||
match_res(mnp.select, onp.select, condlist, choicelist, default=10)
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
def test_choose():
|
||||
x = rand_int(2, 1, 4).astype(onp.int32)
|
||||
y = rand_int(3, 2, 5, 4).astype(onp.int32)
|
||||
|
@ -1588,7 +1592,7 @@ def test_piecewise():
|
|||
match_all_arrays(mnp_res, onp_res)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
|
|
@ -185,7 +185,7 @@ def onp_isfinite(x):
|
|||
return onp.isfinite(x)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -203,7 +203,7 @@ def onp_isnan(x):
|
|||
return onp.isnan(x)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -219,7 +219,7 @@ def onp_isinf(x):
|
|||
return onp.isinf(x)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -274,7 +274,7 @@ def test_isscalar():
|
|||
assert mnp.isscalar('numpy') == onp.isscalar('numpy')
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
|
|
|
@ -470,7 +470,7 @@ def onp_average(x):
|
|||
return a, b, c, d, e, f, g, h, i
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -831,7 +831,7 @@ def onp_logaddexp(x1, x2):
|
|||
return onp.logaddexp(x1, x2)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -839,9 +839,6 @@ def onp_logaddexp(x1, x2):
|
|||
@pytest.mark.env_onecard
|
||||
def test_logaddexp():
|
||||
test_cases = [
|
||||
onp.random.randint(1, 5, (2)).astype('float16'),
|
||||
onp.random.randint(1, 5, (3, 2)).astype('float16'),
|
||||
onp.random.randint(1, 5, (1, 3, 2)).astype('float16'),
|
||||
onp.random.randint(1, 5, (5, 6, 3, 2)).astype('float16')]
|
||||
for _, x1 in enumerate(test_cases):
|
||||
for _, x2 in enumerate(test_cases):
|
||||
|
@ -961,7 +958,7 @@ def onp_clip(x):
|
|||
return a, b, c, d, e, f
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1133,7 +1130,7 @@ def onp_remainder(x, y):
|
|||
return onp.remainder(x, y)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1294,10 +1291,20 @@ def onp_kron(x, y):
|
|||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
def test_kron():
|
||||
run_binop_test(mnp_kron, onp_kron, test_case)
|
||||
x = rand_int()
|
||||
y = rand_int(2, 3, 4)
|
||||
match_res(mnp.kron, onp.kron, x, y)
|
||||
|
||||
x = rand_int(6, 1)
|
||||
y = rand_int(7, 1, 5)
|
||||
match_res(mnp.kron, onp.kron, x, y)
|
||||
|
||||
x = rand_int(1, 1, 2, 3)
|
||||
y = rand_int(1, 1, 2, 3)
|
||||
match_res(mnp.kron, onp.kron, x, y)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1737,7 +1744,7 @@ def test_convolve():
|
|||
match_all_arrays(mnp_res, onp_res)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1745,23 +1752,8 @@ def test_convolve():
|
|||
@pytest.mark.env_onecard
|
||||
def test_cov():
|
||||
x = onp.random.random((3, 4)).tolist()
|
||||
mnp_res = mnp.cov(x)
|
||||
onp_res = onp.cov(x)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.cov(x[0])
|
||||
onp_res = onp.cov(x[0])
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
w1 = [0, 1, 2, 3]
|
||||
w2 = [4, 5, 6, 7]
|
||||
mnp_res = mnp.cov(x, fweights=w1)
|
||||
onp_res = onp.cov(x, fweights=w1)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.cov(x, aweights=w2)
|
||||
onp_res = onp.cov(x, aweights=w2)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.cov(x, fweights=w1, aweights=w2)
|
||||
onp_res = onp.cov(x, fweights=w1, aweights=w2)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.cov(x, fweights=w1, aweights=w2, ddof=3)
|
||||
onp_res = onp.cov(x, fweights=w1, aweights=w2, ddof=3)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
|
@ -1815,7 +1807,7 @@ def onp_lcm(x, y):
|
|||
return onp.lcm(x, y)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -1948,26 +1940,20 @@ def test_nansum():
|
|||
|
||||
|
||||
def mnp_nanmean(x):
|
||||
a = mnp.nanmean(x)
|
||||
b = mnp.nanmean(x, keepdims=True)
|
||||
c = mnp.nanmean(x, axis=-2)
|
||||
d = mnp.nanmean(x, axis=0, keepdims=True)
|
||||
e = mnp.nanmean(x, axis=(-2, 3))
|
||||
f = mnp.nanmean(x, axis=(-3, -1), keepdims=True)
|
||||
return a, b, c, d, e, f
|
||||
a = mnp.nanmean(x, keepdims=True)
|
||||
b = mnp.nanmean(x, axis=(-2, 3))
|
||||
c = mnp.nanmean(x, axis=(-3, -1), keepdims=True)
|
||||
return a, b, c
|
||||
|
||||
|
||||
def onp_nanmean(x):
|
||||
a = onp.nanmean(x)
|
||||
b = onp.nanmean(x, keepdims=True)
|
||||
c = onp.nanmean(x, axis=-2)
|
||||
d = onp.nanmean(x, axis=0, keepdims=True)
|
||||
e = onp.nanmean(x, axis=(-2, 3))
|
||||
f = onp.nanmean(x, axis=(-3, -1), keepdims=True)
|
||||
return a, b, c, d, e, f
|
||||
a = onp.nanmean(x, keepdims=True)
|
||||
b = onp.nanmean(x, axis=(-2, 3))
|
||||
c = onp.nanmean(x, axis=(-3, -1), keepdims=True)
|
||||
return a, b, c
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -2018,7 +2004,7 @@ def test_mean():
|
|||
run_multi_test(mnp_mean, onp_mean, test_case.scalars, error=3)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2029,9 +2015,6 @@ def test_corrcoef():
|
|||
mnp_res = mnp.corrcoef(x)
|
||||
onp_res = onp.corrcoef(x)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.corrcoef(x[0])
|
||||
onp_res = onp.corrcoef(x[0])
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.corrcoef(x, rowvar=False)
|
||||
onp_res = onp.corrcoef(x, rowvar=False)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
|
@ -2052,7 +2035,7 @@ def test_multi_dot():
|
|||
match_all_arrays(mnp.multi_dot(mnp_arrays[1:-1]), onp.linalg.multi_dot(arrays[1:-1]))
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2060,12 +2043,6 @@ def test_multi_dot():
|
|||
@pytest.mark.env_onecard
|
||||
def test_gradient():
|
||||
f = onp.random.random((3, 4, 5)).tolist()
|
||||
mnp_res = mnp.gradient(f)
|
||||
onp_res = onp.gradient(f)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.gradient(f, axis=1)
|
||||
onp_res = onp.gradient(f, axis=1)
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
mnp_res = mnp.gradient(f, -3, axis=(-1, 1))
|
||||
onp_res = onp.gradient(f, -3, axis=(-1, 1))
|
||||
match_all_arrays(mnp_res, onp_res, error=1e-5)
|
||||
|
@ -2106,7 +2083,7 @@ def test_argmin():
|
|||
match_res(mnp.argmin, onp.argmin, x, axis=i)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2116,9 +2093,6 @@ def test_searchsorted():
|
|||
x = onp.arange(-10, 10)
|
||||
y = onp.random.randint(-15, 15, size=(2, 3, 4)) + onp.random.choice([0, 0.5], (2, 3, 4))
|
||||
sorter = onp.random.shuffle(onp.arange(20))
|
||||
match_res(mnp.searchsorted, onp.searchsorted, x, y)
|
||||
match_res(mnp.searchsorted, onp.searchsorted, x, y, side='right')
|
||||
match_res(mnp.searchsorted, onp.searchsorted, x, y, sorter=sorter)
|
||||
match_res(mnp.searchsorted, onp.searchsorted, x, y, side='right', sorter=sorter)
|
||||
|
||||
|
||||
|
@ -2184,21 +2158,18 @@ def test_bincount():
|
|||
def test_histogram():
|
||||
x = onp.random.randint(-10, 10, 10)
|
||||
weights = onp.random.randn(10)
|
||||
for bins in [(1, 2, 3), [2], 1, 5, 10]:
|
||||
for bins in [(1, 2, 3), [2], 1, 5]:
|
||||
# pylint: disable=redefined-builtin
|
||||
for range in [None, (3, 3), (2, 20)]:
|
||||
for range in [None, (2, 20)]:
|
||||
match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, error=1)
|
||||
match_res(mnp.histogram, onp.histogram, x, bins=bins, range=range, density=True, error=1)
|
||||
mnp_res = mnp.histogram(to_tensor(x), bins=bins, range=range, weights=to_tensor(weights))
|
||||
onp_res = onp.histogram(x, bins=bins, range=range, weights=weights)
|
||||
match_all_arrays(mnp_res, onp_res, error=1)
|
||||
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)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2209,9 +2180,9 @@ def test_histogramdd():
|
|||
y = [onp.random.randint(-10, 10, 5), onp.random.randint(-10, 10, 5), onp.random.randint(-10, 10, 5)]
|
||||
mnp_y = list(map(to_tensor, y))
|
||||
weights = onp.random.randn(5)
|
||||
for bins in [(15, 4, 9), 10]:
|
||||
for bins in [(15, 4, 9)]:
|
||||
# pylint: disable=redefined-builtin
|
||||
for range in [None, [[0, 5], [2, 7], [1, 3]]]:
|
||||
for range in [[[0, 5], [2, 7], [1, 3]]]:
|
||||
mnp_res = mnp.histogramdd(to_tensor(x), bins=bins, range=range)
|
||||
onp_res = onp.histogramdd(x, bins=bins, range=range)
|
||||
match_all_arrays(mnp_res[0], onp_res[0], error=1)
|
||||
|
@ -2521,7 +2492,7 @@ def test_result_type():
|
|||
assert actual == expected
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2530,8 +2501,8 @@ def test_result_type():
|
|||
def test_unwrap():
|
||||
x = onp.linspace(onp.linspace((0, 1), (10, 15), 5), onp.linspace((0, 2), (3*onp.pi, 7*onp.pi), 5), 7)
|
||||
x[5:2] += onp.pi
|
||||
for i in range(-3, 3):
|
||||
match_res(mnp.unwrap, onp.unwrap, x, axis=i, error=3)
|
||||
match_res(mnp.unwrap, onp.unwrap, x, axis=0, error=3)
|
||||
match_res(mnp.unwrap, onp.unwrap, x, axis=-1, error=3)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
|
@ -2604,7 +2575,7 @@ def test_ravel_multi_index():
|
|||
match_array(actual.asnumpy(), expected, error=5)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
|
@ -2708,17 +2679,13 @@ def onp_correlate(a, v):
|
|||
return a, b, c, d
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_correlate():
|
||||
first_sequences = [[1], [1, 2], [0, 0, 0, 1], [1, 2, 3, 4, 5]]
|
||||
second_sequences = [[2], [0, 1], [1, 2, 3]]
|
||||
for a in first_sequences:
|
||||
for v in second_sequences:
|
||||
mnp_res = mnp_correlate(a, v)
|
||||
onp_res = onp_correlate(a, v)
|
||||
match_all_arrays(mnp_res, onp_res)
|
||||
mnp_res = mnp_correlate([1, 2, 3, 4, 5], [1, 2, 3])
|
||||
onp_res = onp_correlate([1, 2, 3, 4, 5], [1, 2, 3])
|
||||
match_all_arrays(mnp_res, onp_res)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
"""setup for pytest"""
|
||||
import mindspore.context as context
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_module(module):
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
|
@ -0,0 +1,327 @@
|
|||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
""" test numpy ops """
|
||||
import numpy as np
|
||||
|
||||
import mindspore.numpy as mnp
|
||||
from mindspore import Tensor
|
||||
from mindspore.nn import Cell
|
||||
import mindspore.context as context
|
||||
from ....mindspore_test_framework.mindspore_test import mindspore_test
|
||||
from ....mindspore_test_framework.pipeline.forward.compile_forward \
|
||||
import pipeline_for_compile_forward_ge_graph_for_case_by_case_config
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
class MeshGrid(Cell):
|
||||
def construct(self, a, b, c, d):
|
||||
ret = mnp.meshgrid(a, b, c, d)
|
||||
return ret
|
||||
|
||||
|
||||
class Choose(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.choose(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Histogram(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.histogram(a)
|
||||
return ret
|
||||
|
||||
|
||||
class Norm(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.norm(a)
|
||||
return ret
|
||||
|
||||
|
||||
class Cross(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.cross(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Stack(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.stack((a, b))
|
||||
return ret
|
||||
|
||||
|
||||
class Correlate(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.correlate(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Split(Cell):
|
||||
def construct(self, tensor):
|
||||
a = mnp.split(tensor, indices_or_sections=1)
|
||||
b = mnp.split(tensor, indices_or_sections=3)
|
||||
c = mnp.array_split(tensor, indices_or_sections=1)
|
||||
d = mnp.array_split(tensor, indices_or_sections=3, axis=-1)
|
||||
return a, b, c, d
|
||||
|
||||
|
||||
class MatrixPower(Cell):
|
||||
def construct(self, tensor):
|
||||
a = mnp.matrix_power(tensor, 3)
|
||||
return a
|
||||
|
||||
|
||||
class RavelMultiIndex(Cell):
|
||||
def construct(self, tensor):
|
||||
a = mnp.ravel_multi_index(tensor, (7, 6))
|
||||
b = mnp.ravel_multi_index(tensor, (7, 6), order='F')
|
||||
c = mnp.ravel_multi_index(tensor, (4, 6), mode='clip')
|
||||
d = mnp.ravel_multi_index(tensor, (4, 4), mode='wrap')
|
||||
return a, b, c, d
|
||||
|
||||
|
||||
class GeomSpace(Cell):
|
||||
def construct(self, start):
|
||||
a = mnp.geomspace(1, 256, num=9)
|
||||
b = mnp.geomspace(1, 256, num=8, endpoint=False)
|
||||
c = mnp.geomspace(start, [1000, 2000, 3000], num=4)
|
||||
d = mnp.geomspace(start, [1000, 2000, 3000], num=4, endpoint=False, axis=-1)
|
||||
return a, b, c, d
|
||||
|
||||
|
||||
class Arange(Cell):
|
||||
def construct(self):
|
||||
a = mnp.arange(10)
|
||||
b = mnp.arange(0, 10)
|
||||
c = mnp.arange(0.1, 9.9)
|
||||
return a, b, c
|
||||
|
||||
|
||||
class Eye(Cell):
|
||||
def construct(self):
|
||||
res = []
|
||||
for n in range(1, 5):
|
||||
for k in range(0, 5):
|
||||
res.append(mnp.eye(10, n, k))
|
||||
return res
|
||||
|
||||
|
||||
class Trace(Cell):
|
||||
def construct(self, arr):
|
||||
a = mnp.trace(arr, offset=-1, axis1=0, axis2=1)
|
||||
b = mnp.trace(arr, offset=0, axis1=1, axis2=0)
|
||||
return a, b
|
||||
|
||||
|
||||
class Pad(Cell):
|
||||
def construct(self, arr1, arr2):
|
||||
a = mnp.pad(arr1, ((1, 1), (2, 2), (3, 4)))
|
||||
b = mnp.pad(arr1, ((1, 1), (2, 2), (3, 4)), mode="mean", stat_length=((1, 2), (2, 10), (3, 4)))
|
||||
c = mnp.pad(arr1, ((1, 1), (2, 2), (3, 4)), mode="edge")
|
||||
d = mnp.pad(arr1, ((1, 1), (2, 2), (3, 4)), mode="wrap")
|
||||
e = mnp.pad(arr1, ((1, 3), (5, 2), (3, 0)), mode="linear_ramp", end_values=((0, 10), (9, 1), (-10, 99)))
|
||||
f = mnp.pad(arr2, ((10, 13), (5, 12), (3, 0), (2, 6)), mode='symmetric', reflect_type='even')
|
||||
g = mnp.pad(arr2, ((10, 13)), mode='reflect', reflect_type='even')
|
||||
return a, b, c, d, e, f, g
|
||||
|
||||
|
||||
class Where(Cell):
|
||||
def construct(self, a, b, c):
|
||||
ret = mnp.where(a, b, c)
|
||||
return ret
|
||||
|
||||
|
||||
class Select(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.select(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class IsClose(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.isclose(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Average(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.average(a)
|
||||
return ret
|
||||
|
||||
|
||||
class Remainder(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.remainder(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Diff(Cell):
|
||||
def construct(self, a):
|
||||
ret1 = mnp.diff(a)
|
||||
ret2 = mnp.ediff1d(a)
|
||||
return ret1, ret2
|
||||
|
||||
|
||||
class Trapz(Cell):
|
||||
def construct(self, arr):
|
||||
a = mnp.trapz(arr, x=[-2, 1, 2], axis=1)
|
||||
b = mnp.trapz(arr, dx=3, axis=0)
|
||||
return a, b
|
||||
|
||||
|
||||
class Lcm(Cell):
|
||||
def construct(self, a, b):
|
||||
ret = mnp.lcm(a, b)
|
||||
return ret
|
||||
|
||||
|
||||
class Cov(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.cov(a, a)
|
||||
return ret
|
||||
|
||||
|
||||
class Gradient(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.gradient(a)
|
||||
return ret
|
||||
|
||||
|
||||
class MultiDot(Cell):
|
||||
def construct(self, a, b, c, d):
|
||||
ret = mnp.multi_dot((a, b, c, d))
|
||||
return ret
|
||||
|
||||
|
||||
class Histogramdd(Cell):
|
||||
def construct(self, a):
|
||||
ret = mnp.histogramdd(a)
|
||||
return ret
|
||||
|
||||
|
||||
test_cases = [
|
||||
('MeshGrid', {
|
||||
'block': MeshGrid(),
|
||||
'desc_inputs': [Tensor(np.full(3, 2, dtype=np.float32)),
|
||||
Tensor(np.full(1, 5, dtype=np.float32)),
|
||||
Tensor(np.full((2, 3), 9, dtype=np.float32)),
|
||||
Tensor(np.full((4, 5, 6), 7, dtype=np.float32))],
|
||||
}),
|
||||
('Norm', {
|
||||
'block': Norm(),
|
||||
'desc_inputs': [Tensor(np.ones((5, 2, 3, 7), dtype=np.float32))],
|
||||
}),
|
||||
('Cross', {
|
||||
'block': Cross(),
|
||||
'desc_inputs': [Tensor(np.arange(18, dtype=np.int32).reshape(2, 3, 1, 3)),
|
||||
Tensor(np.arange(9, dtype=np.int32).reshape(1, 3, 3))],
|
||||
}),
|
||||
('Stack', {
|
||||
'block': Stack(),
|
||||
'desc_inputs': [Tensor(np.arange(9, dtype=np.int32).reshape(3, 3)),
|
||||
Tensor(np.arange(9, dtype=np.int32).reshape(3, 3)),],
|
||||
}),
|
||||
('Correlate', {
|
||||
'block': Correlate(),
|
||||
'desc_inputs': [Tensor(np.array([1, 2, 3, 4, 5], dtype=np.int32)),
|
||||
Tensor(np.array([0, 1], dtype=np.int32)),],
|
||||
}),
|
||||
('Split', {
|
||||
'block': Split(),
|
||||
'desc_inputs': [Tensor(np.arange(9, dtype=np.float32).reshape(3, 3))],
|
||||
}),
|
||||
('MatrixPower', {
|
||||
'block': MatrixPower(),
|
||||
'desc_inputs': [Tensor(np.arange(9, dtype=np.float32).reshape(3, 3))],
|
||||
}),
|
||||
('RavelMultiIndex', {
|
||||
'block': RavelMultiIndex(),
|
||||
'desc_inputs': [Tensor(np.array([[3, 6, 6], [4, 5, 1]], dtype=np.int32))],
|
||||
}),
|
||||
('GeomSpace', {
|
||||
'block': GeomSpace(),
|
||||
'desc_inputs': [Tensor(np.arange(1, 7, dtype=np.float32).reshape(2, 3))],
|
||||
}),
|
||||
('Arange', {
|
||||
'block': Arange(),
|
||||
'desc_inputs': [],
|
||||
}),
|
||||
('Eye', {
|
||||
'block': Eye(),
|
||||
'desc_inputs': [],
|
||||
}),
|
||||
('Trace', {
|
||||
'block': Trace(),
|
||||
'desc_inputs': [Tensor(np.ones((3, 5), dtype=np.float32))],
|
||||
}),
|
||||
('Where', {
|
||||
'block': Where(),
|
||||
'desc_inputs': [Tensor(np.full((1, 1, 2), [False, True])),
|
||||
Tensor(np.full((1, 3, 2), 5, dtype=np.float32)),
|
||||
Tensor(np.full((2, 1, 1), 7, dtype=np.float32))],
|
||||
}),
|
||||
('Select', {
|
||||
'block': Select(),
|
||||
'desc_inputs': [Tensor([[True, True, True, False, False], [False, False, True, False, True]]),
|
||||
Tensor(np.array([[0, 1, 2, 3, 4], [0, 1, 4, 9, 16]], dtype=np.int32))],
|
||||
}),
|
||||
('IsClose', {
|
||||
'block': IsClose(),
|
||||
'desc_inputs': [Tensor(np.array([0, 1, 2, float('inf'), float('inf'), float('nan')], dtype=np.float32)),
|
||||
Tensor(np.array([0, 1, -2, float('-inf'), float('inf'), float('nan')], dtype=np.float32))],
|
||||
}),
|
||||
('Average', {
|
||||
'block': Average(),
|
||||
'desc_inputs': [Tensor(np.array([[1., 2.], [3., 4.]], dtype=np.float32))],
|
||||
}),
|
||||
('Remainder', {
|
||||
'block': Remainder(),
|
||||
'desc_inputs': [Tensor(np.array([4, 7], dtype=np.int32)),
|
||||
Tensor(np.array([[1, 2], [3, 4]], dtype=np.int32))],
|
||||
}),
|
||||
('Diff', {
|
||||
'block': Diff(),
|
||||
'desc_inputs': [Tensor(np.array([1, 3, -1, 0, 4], dtype=np.int32))],
|
||||
}),
|
||||
('Trapz', {
|
||||
'block': Trapz(),
|
||||
'desc_inputs': [Tensor(np.arange(6, dtype=np.int32).reshape(2, 3))],
|
||||
}),
|
||||
('Lcm', {
|
||||
'block': Lcm(),
|
||||
'desc_inputs': [Tensor(np.arange(6, dtype=np.int32)),
|
||||
Tensor(np.array(20, dtype=np.int32))],
|
||||
}),
|
||||
('Cov', {
|
||||
'block': Cov(),
|
||||
'desc_inputs': [Tensor(np.array([[2., 3., 4., 5.], [0., 2., 3., 4.], [7., 8., 9., 10.]], dtype=np.float32))],
|
||||
}),
|
||||
('Gradient', {
|
||||
'block': Gradient(),
|
||||
'desc_inputs': [Tensor(np.array([[2., 3., 4., 5.], [0., 2., 3., 4.], [7., 8., 9., 10.]], dtype=np.float32))],
|
||||
}),
|
||||
('MultiDot', {
|
||||
'block': MultiDot(),
|
||||
'desc_inputs': [Tensor(np.ones((10000, 100), dtype=np.float32)),
|
||||
Tensor(np.ones((100, 1000), dtype=np.float32)),
|
||||
Tensor(np.ones((1000, 5), dtype=np.float32)),
|
||||
Tensor(np.ones((5, 333), dtype=np.float32))],
|
||||
}),
|
||||
]
|
||||
|
||||
|
||||
@mindspore_test(pipeline_for_compile_forward_ge_graph_for_case_by_case_config)
|
||||
def test_exec():
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
return test_cases
|
Loading…
Reference in New Issue