!16288 fix numpy-native bugs

From: @yanglf1121
Reviewed-by: @guoqi1024,@liangchenghui
Signed-off-by: @liangchenghui
This commit is contained in:
mindspore-ci-bot 2021-05-14 19:05:18 +08:00 committed by Gitee
commit d4eef75155
6 changed files with 16 additions and 13 deletions

View File

@ -510,7 +510,7 @@ def cumsum(x, axis=None, dtype=None):
original_dtype = x.dtype
# If original tensor is int, and has precision less then int32, convert
# to int32
if x.dtype in (mstype.int8, mstype.int16, mstype.uint8, mstype.int16):
if x.dtype in (mstype.bool_, mstype.int8, mstype.int16, mstype.uint8, mstype.int16):
x = x.astype(mstype.int32)
if axis is None:
x = x.ravel()

View File

@ -796,7 +796,7 @@ class Tensor(Tensor_):
x = self
original_dtype = x.dtype
# If original tensor is int, and has precision less then int32, convert to int32
if mstype.issubclass_(x.dtype, mstype.int_) and x.itemsize < 4:
if x.dtype in (mstype.bool_, mstype.int8, mstype.int16, mstype.uint8, mstype.int16):
x = x.astype(mstype.int32)
if axis is None:
x = x.ravel()

View File

@ -4176,7 +4176,7 @@ def argmax(a, axis=None):
5
>>> print(np.argmax(a, axis=0))
[1 1 1]
>>> print(np.argmax(a, axis=0))
>>> print(np.argmax(a, axis=1))
[2 2]
"""
a = _to_tensor(a)
@ -4212,7 +4212,7 @@ def argmin(a, axis=None):
0
>>> print(np.argmin(a, axis=0))
[0 0 0]
>>> print(np.argmin(a, axis=0))
>>> print(np.argmin(a, axis=1))
[0 0]
"""
a = _to_tensor(a)
@ -4653,7 +4653,7 @@ def histogram(a, bins=10, range=None, weights=None, density=False): # pylint: di
if density:
count = F.cast(count, mstype.float32)
count = count/diff(bin_edges)/F.reduce_sum(count)
return count.astype(mstype.int32), bin_edges
return count, bin_edges
@constexpr
@ -4792,7 +4792,7 @@ def histogramdd(sample, bins=10, range=None, weights=None, density=False): # pyl
shape = _expanded_shape(ndim, dedges[i].size, i)
count /= _to_tensor(dedges[i]).reshape(shape)
count /= s
return count.astype(mstype.int32), bin_edges
return count, bin_edges
def histogram2d(x, y, bins=10, range=None, weights=None, density=False): # pylint: disable=redefined-builtin
@ -4856,7 +4856,7 @@ def histogram2d(x, y, bins=10, range=None, weights=None, density=False): # pylin
5.33333349e+00, 6.00000000e+00]))
"""
count, bin_edges = histogramdd((x, y), bins=bins, range=range, weights=weights, density=density)
return count.astype(mstype.int32), bin_edges[0], bin_edges[1]
return count, bin_edges[0], bin_edges[1]
def matrix_power(a, n):

View File

@ -910,7 +910,10 @@ def reduce_(a, reduce_fn, cmp_fn=None, axis=None, keepdims=False, initial=None,
const_utils.raise_value_error('zero-size tensors are not supported.')
if initial is not None:
initial = F.fill(dtype, shape, initial)
if isinstance(initial, Tensor):
initial = F.tile(initial, shape).astype(dtype)
else:
initial = F.fill(dtype, shape, initial)
a = cmp_fn(a, initial)
if isinstance(where, Tensor):

View File

@ -1641,7 +1641,7 @@ def test_apply_over_axes():
match_array(actual.asnumpy(), expected, error=5)
@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training

View File

@ -1372,7 +1372,7 @@ def test_negative():
match_array(mnp_neg.asnumpy(), onp_neg, 1e-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
@ -2170,7 +2170,7 @@ def test_bincount():
match_res(mnp.bincount, onp.bincount, x, weights, minlength=25, error=3)
@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training
@ -2193,7 +2193,7 @@ def test_histogram():
match_all_arrays(mnp_res, onp_res, error=1)
@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training
@ -2236,7 +2236,7 @@ def test_histogramdd():
match_all_arrays(mnp_res[1], onp_res[1], error=3)
@pytest.mark.level1
@pytest.mark.level2
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training