From 2acd4637e17e4e6be667c74d68eddc98780074f0 Mon Sep 17 00:00:00 2001 From: wuxuejian Date: Sun, 6 Dec 2020 09:38:59 +0800 Subject: [PATCH] support divide zero of RealDiv --- .../cpu/arithmetic_cpu_kernel.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc index 1030a6163d..2a8a174a16 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc @@ -57,11 +57,21 @@ void ArithmeticCPUKernel::RealDiv(const T *input1, const T *input2, T *out, size for (size_t i = start; i < end; i++) { std::vector idx; GenIndex(i, &idx); - auto div_number = input2[idx[1]]; - if (div_number == 0) { - MS_LOG(EXCEPTION) << "Cannot divided by 0!"; + auto dividend = input1[idx[0]]; + auto divisor = input2[idx[1]]; + if (divisor == 0) { + if (dividend == 0) { + out[i] = std::numeric_limits::quiet_NaN(); + continue; + } + if (std::numeric_limits::has_infinity) { + out[i] = dividend > 0 ? std::numeric_limits::infinity() : -std::numeric_limits::infinity(); + } else { + out[i] = dividend > 0 ? std::numeric_limits::max() : std::numeric_limits::min(); + } + continue; } - out[i] = input1[idx[0]] / div_number; + out[i] = dividend / divisor; } }