Browse Source

fix np.maximum and np.linspace

tags/v1.2.0-rc1
yanglf1121 4 years ago
parent
commit
3b1b6fc8cb
2 changed files with 17 additions and 9 deletions
  1. +1
    -1
      mindspore/numpy/array_creations.py
  2. +16
    -8
      mindspore/numpy/math_ops.py

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

@@ -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)


+ 16
- 8
mindspore/numpy/math_ops.py View File

@@ -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:
@@ -1528,12 +1532,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…
Cancel
Save