Add Notes.
This commit is contained in:
parent
96acc23b08
commit
d4563e5b60
|
@ -1322,7 +1322,7 @@ mindspore.Tensor
|
|||
`indices` 的最后一个轴是每个索引向量的深度。对于每个索引向量, `updates` 中必须有相应的值。`updates` 的shape应该等于 `input_x[indices]` 的shape,其中 `input_x` 指当前Tensor。有关更多详细信息,请参见使用用例。
|
||||
|
||||
.. note::
|
||||
如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到当前Tensor,而不是抛出索引错误。
|
||||
GPU平台上,如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误;CPU平台上直接抛出索引错误;Ascend平台不支持越界检查,若越界可能会造成未知错误。
|
||||
|
||||
**参数:**
|
||||
|
||||
|
@ -1415,7 +1415,7 @@ mindspore.Tensor
|
|||
`indices` 的最后一个轴是每个索引向量的深度。对于每个索引向量, `updates` 中必须有相应的值。`updates` 的shape应该等于 `input_x[indices]` 的shape,其中 `input_x` 指当前Tensor。有关更多详细信息,请参见使用用例。
|
||||
|
||||
.. note::
|
||||
如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到当前Tensor,而不是抛出索引错误。
|
||||
GPU平台上,如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误;CPU平台上直接抛出索引错误;Ascend平台不支持越界检查,若越界可能会造成未知错误。
|
||||
|
||||
**参数:**
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
`indices` 的最后一个轴是每个索引向量的深度。对于每个索引向量, `updates` 中必须有相应的值。 `updates` 的shape应该等于 `input_x[indices]` 的shape。有关更多详细信息,请参见使用用例。
|
||||
|
||||
.. note::
|
||||
如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误。
|
||||
GPU平台上,如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误;CPU平台上直接抛出索引错误;Ascend平台不支持越界检查,若越界可能会造成未知错误。
|
||||
|
||||
**参数:**
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
`indices` 的最后一个轴是每个索引向量的深度。对于每个索引向量, `updates` 中必须有相应的值。 `updates` 的shape应该等于 `input_x[indices]` 的shape。有关更多详细信息,请参见使用用例。
|
||||
|
||||
.. note::
|
||||
如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误。
|
||||
GPU平台上,如果 `indices` 的某些值超出范围,则相应的 `updates` 不会更新到 `input_x` ,而不是抛出索引错误;CPU平台上直接抛出索引错误;Ascend平台不支持越界检查,若越界可能会造成未知错误。
|
||||
|
||||
**参数:**
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ bool TensorScatterOpCpuKernelMode::LaunchKernel(const std::vector<kernel::Addres
|
|||
const Eigen::DenseIndex idx_index = eigen_indices(i, j);
|
||||
out_index += batch_strides_[j] * idx_index;
|
||||
if (idx_index < 0 || idx_index >= static_cast<S>(input_shape_[j])) {
|
||||
invalid_index_pos = SizeToLong(idx_index);
|
||||
invalid_index_pos = SizeToLong(i * slice_size_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -174,9 +174,8 @@ bool TensorScatterOpCpuKernelMode::LaunchKernel(const std::vector<kernel::Addres
|
|||
indices_ss << std::to_string(indices[invalid_index_pos + i]);
|
||||
input_shape_ss << std::to_string(input_shape_[i]);
|
||||
}
|
||||
MS_LOG(ERROR) << "For '" << kernel_name_ << "', the " << invalid_index_pos << "-th value of 'indices'["
|
||||
<< indices_ss.str() << "] is out of range[" + input_shape_ss.str() + "].";
|
||||
return false;
|
||||
MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the " << invalid_index_pos << "-th value of 'indices'["
|
||||
<< indices_ss.str() << "] is out of range[" << input_shape_ss.str() << "].";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2552,8 +2552,10 @@ class Tensor(Tensor_):
|
|||
equal to the shape of `self[indices]`. For more details, see use cases.
|
||||
|
||||
Note:
|
||||
If some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to self tensor.
|
||||
On GPU, if some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to self tensor. On CPU, if some values of
|
||||
the `indices` are out of bound, raising an index error. On Ascend, out of bound checking is
|
||||
not supported, if some values of the `indices` are out of bound, unknown errors may be caused.
|
||||
|
||||
Args:
|
||||
indices (Tensor): The index of input tensor whose data type is int32 or int64.
|
||||
|
@ -2598,8 +2600,10 @@ class Tensor(Tensor_):
|
|||
equal to the shape of `self[indices]`. For more details, see use cases.
|
||||
|
||||
Note:
|
||||
If some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to `input_x`, the variable `input_x` refers to self tensor.
|
||||
On GPU, if some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to self tensor. On CPU, if some values of
|
||||
the `indices` are out of bound, raising an index error. On Ascend, out of bound checking is
|
||||
not supported, if some values of the `indices` are out of bound, unknown errors may be caused.
|
||||
|
||||
Args:
|
||||
indices (Tensor): The index of input tensor whose data type is int32 or int64.
|
||||
|
|
|
@ -2311,8 +2311,10 @@ def tensor_scatter_add(input_x, indices, updates):
|
|||
equal to the shape of `input_x[indices]`. For more details, see use cases.
|
||||
|
||||
Note:
|
||||
If some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to `input_x`.
|
||||
On GPU, if some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to self tensor. On CPU, if some values of
|
||||
the `indices` are out of bound, raising an index error. On Ascend, out of bound checking is
|
||||
not supported, if some values of the `indices` are out of bound, unknown errors may be caused.
|
||||
|
||||
Args:
|
||||
- **input_x** (Tensor) - The target tensor. The dimension of input_x must be no less than indices.shape[-1].
|
||||
|
@ -2361,8 +2363,10 @@ def tensor_scatter_sub(input_x, indices, updates):
|
|||
equal to the shape of `input_x[indices]`. For more details, see use cases.
|
||||
|
||||
Note:
|
||||
If some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to `input_x`.
|
||||
On GPU, if some values of the `indices` are out of bound, instead of raising an index error,
|
||||
the corresponding `updates` will not be updated to self tensor. On CPU, if some values of
|
||||
the `indices` are out of bound, raising an index error. On Ascend, out of bound checking is
|
||||
not supported, if some values of the `indices` are out of bound, unknown errors may be caused.
|
||||
|
||||
Args:
|
||||
input_x (Tensor): The target tensor. The dimension of input_x must be no less than indices.shape[-1].
|
||||
|
|
|
@ -276,6 +276,26 @@ def test_tensor_scatter_arithmetic_type_check(func, data_type, index_type):
|
|||
compare_with_numpy(func, input_x, indices, updates)
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('func', ['add', 'sub', 'max', 'min'])
|
||||
@pytest.mark.parametrize('data_type', [mstype.int32])
|
||||
@pytest.mark.parametrize('index_type', [mstype.int32])
|
||||
def test_tensor_scatter_arithmetic_indices_check(func, data_type, index_type):
|
||||
"""
|
||||
Feature: TensorScatter* operators.
|
||||
Description: test cases for invalid indices.
|
||||
Expectation: raise RuntimeError.
|
||||
"""
|
||||
input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), data_type)
|
||||
indices = Tensor(np.array([[10, 10]]), index_type)
|
||||
updates = Tensor(np.array([1.0]), data_type)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
compare_with_numpy(func, input_x, indices, updates)
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.env_onecard
|
||||
|
|
Loading…
Reference in New Issue