diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_add_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_add_cpu_kernel.cc index 59c02b19df8..c7ee7ae2d49 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_add_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_add_cpu_kernel.cc @@ -62,7 +62,8 @@ void SparseDenseCwiseAddCpuKernelMod::ComputeAdd(const std::vector & for (int64_t i = 0; i < index_num; i++) { for (int64_t j = 0; j < dimension; j++) { - if (indices_data[static_cast(i * dimension + j)] >= sparse_shape_data[static_cast(j)]) { + if (indices_data[static_cast(i * dimension + j)] >= sparse_shape_data[static_cast(j)] || + indices_data[i * static_cast(dimension) + j] < 0) { MS_EXCEPTION(ValueError) << "For SparseDenseCwiseAdd, the indices cannot go out of bounds."; } } diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_div_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_div_cpu_kernel.cc index 92460124e3f..2b70a41637b 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_div_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_div_cpu_kernel.cc @@ -64,7 +64,8 @@ void SparseDenseCwiseDivCpuKernelMod::ComputeDiv(const std::vector & for (size_t i = 0; i < static_cast(index_num); i++) { for (size_t j = 0; j < static_cast(dimension); j++) { - if (indices_data[i * static_cast(dimension) + j] >= sparse_shape_data[j]) { + if (indices_data[i * static_cast(dimension) + j] >= sparse_shape_data[j] || + indices_data[i * static_cast(dimension) + j] < 0) { MS_EXCEPTION(ValueError) << "For SparseDenseCwiseDiv, the indices cannot go out of bounds."; } } diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_mul_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_mul_cpu_kernel.cc index 45fa6eaacaa..537d00bcc79 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_mul_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/sparse_dense_cwise_mul_cpu_kernel.cc @@ -62,7 +62,8 @@ void SparseDenseCwiseMulCpuKernelMod::ComputeMul(const std::vector & for (int64_t i = 0; i < index_num; i++) { for (int64_t j = 0; j < dimension; j++) { - if (indices_data[i * dimension + j] >= sparse_shape_data[j]) { + if (indices_data[i * dimension + j] >= sparse_shape_data[j] || + indices_data[i * static_cast(dimension) + j] < 0) { MS_EXCEPTION(ValueError) << "For SparseDenseCwiseMul, the indices cannot go out of bounds."; } }