This commit is contained in:
huangmengxi 2021-06-18 10:19:46 +08:00
parent 63d853cf35
commit 4ebd647590
2 changed files with 5 additions and 2 deletions

View File

@ -1825,6 +1825,8 @@ def _check_indices(dims, indices, mode, allow_negative_index=True):
_raise_unimplemented_error('"raise" mode is not implemented')
if mode == 'wrap':
return _mod(indices, F.fill(mstype.float32, shape, dims)).astype(dtype)
if mode != 'clip':
_raise_value_error('invalid mode. Expected "raise", "wrap", or "clip"')
zeros = F.fill(dtype, shape, 0)
clipped = F.select(out_of_lowerbounds, zeros, indices)
clipped = F.select(out_of_upperbounds, upperbounds, clipped)
@ -2180,6 +2182,7 @@ def choose(a, choices, mode='clip'):
else:
choices = _to_tensor(choices)
shape_choice = _infer_out_shape(F.shape(a), F.shape(choices)[1:])
choices = F.reshape(choices, choices.shape[:1] + _add_unit_axes(choices.shape[1:], len(shape_choice)))
choices = broadcast_to(choices, (F.shape(choices)[0],) + shape_choice)
if F.rank(a) == 0 or F.rank(choices) == 0:

View File

@ -4516,7 +4516,7 @@ def digitize(x, bins, right=False):
Args:
x (Union[int, float, bool, list, tuple, Tensor]): Input array to be binned.
bins (Union[int, float, bool, list, tuple, Tensor]): Array of bins. It has to
bins (Union[list, tuple, Tensor]): Array of bins. It has to
be 1-dimensional and monotonic.
right (boolean, optional): Indicating whether the intervals include the right
or the left bin edge. Default behavior is ``(right==False)`` indicating
@ -4539,7 +4539,7 @@ def digitize(x, bins, right=False):
[1 3 3 4 5]
"""
x, bins = _to_tensor(x, bins)
if F.rank(bins) > 1:
if F.rank(bins) != 1:
_raise_value_error('bins should be 1-dimensional')
if x.size == 0:
return x