forked from huawei/mindspore2022
!12791 [Numpy Native] fix mindspore.numpy.linspace and mindspore.numpy.maximum
From: @yanglf1121 Reviewed-by: Signed-off-by:
This commit is contained in:
commit
ca6586715b
|
|
@ -516,7 +516,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis
|
|||
out = reshape(start, bounds_shape)
|
||||
else: # num == 0
|
||||
delta = nan
|
||||
out = _type_convert([], Tensor).astype(dtype)
|
||||
out = _type_convert(Tensor, []).astype(dtype)
|
||||
if retstep:
|
||||
return out.astype(dtype), delta
|
||||
return out.astype(dtype)
|
||||
|
|
|
|||
|
|
@ -690,12 +690,16 @@ def minimum(x1, x2, out=None, where=True, dtype=None):
|
|||
[[1 2]
|
||||
[1 2]]
|
||||
"""
|
||||
if isinstance(x1, (int, float, bool, list, tuple, Tensor)) and \
|
||||
isinstance(x2, (int, float, bool, list, tuple, Tensor)):
|
||||
if isinstance(x1, (int, float, bool, list, tuple)):
|
||||
x1 = asarray_const(x1)
|
||||
elif not isinstance(x1, Tensor):
|
||||
_raise_type_error("Input x1 is expected to be array_like")
|
||||
|
||||
if isinstance(x2, (int, float, bool, list, tuple)):
|
||||
x2 = asarray_const(x2)
|
||||
else:
|
||||
_raise_type_error("Input x1 and x2 are expected to be array_like")
|
||||
elif not isinstance(x2, Tensor):
|
||||
_raise_type_error("Input x2 is expected to be array_like")
|
||||
|
||||
# if both are scalars, expand x1 to 1d tensor, since cpu kernel doesn't support
|
||||
# comparisons with 2 scalars
|
||||
if x1.ndim == 0 and x2.ndim == 0:
|
||||
|
|
@ -1530,12 +1534,16 @@ def maximum(x1, x2, out=None, where=True, dtype=None):
|
|||
>>> print(output)
|
||||
[2 5 4]
|
||||
"""
|
||||
if isinstance(x1, (int, float, bool, list, tuple, Tensor)) and \
|
||||
isinstance(x2, (int, float, bool, list, tuple, Tensor)):
|
||||
if isinstance(x1, (int, float, bool, list, tuple)):
|
||||
x1 = asarray_const(x1)
|
||||
elif not isinstance(x1, Tensor):
|
||||
_raise_type_error("Input x1 is expected to be array_like")
|
||||
|
||||
if isinstance(x2, (int, float, bool, list, tuple)):
|
||||
x2 = asarray_const(x2)
|
||||
else:
|
||||
_raise_type_error("Input x1 and x2 are expected to be array_like")
|
||||
elif not isinstance(x2, Tensor):
|
||||
_raise_type_error("Input x2 is expected to be array_like")
|
||||
|
||||
# F.maximum does not support when both operands are scalar
|
||||
if x1.ndim == 0 and x2.ndim == 0:
|
||||
x1 = expand_dims(x1, 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue