From c9cc4797ad57cdce703f8fa48856552f0a7aa24b Mon Sep 17 00:00:00 2001 From: XinWang2021 <2021202010045@whu.edu.cn> Date: Sat, 17 Dec 2022 16:56:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3SparseDenseCwiseAdd,SparseDen?= =?UTF-8?q?seCwiseDiv,SparseDenseCwiseMul=E5=BD=93=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E4=B8=BA=E8=B4=9F=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/cpu/kernel/sparse_dense_cwise_add_cpu_kernel.cc | 3 ++- .../device/cpu/kernel/sparse_dense_cwise_div_cpu_kernel.cc | 3 ++- .../device/cpu/kernel/sparse_dense_cwise_mul_cpu_kernel.cc | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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."; } }