From e470fbf2bce53f62f08912778cb8ab8c398d0929 Mon Sep 17 00:00:00 2001 From: fary86 Date: Thu, 23 Jul 2020 00:59:02 +0800 Subject: [PATCH] Fix float max value compare --- .../jit/static_analysis/program_specialize.cc | 1 + mindspore/core/ir/value.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc index fe5871fe5e4..f696e9963b1 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/program_specialize.cc @@ -115,6 +115,7 @@ AnfNodePtr FuncGraphSpecializer::ReplicateDisconnectedNode(const AnfNodePtr &nod std::shared_ptr specializer = shared_from_this(); while (fg != nullptr && fg != specializer->func_graph_) { specializer = specializer->parent_; + MS_EXCEPTION_IF_NULL(specializer); } // If had replicated, just return that. auto iter = specializer->repl_node_->find(node); diff --git a/mindspore/core/ir/value.cc b/mindspore/core/ir/value.cc index 92535bc2e96..560247b8ce7 100644 --- a/mindspore/core/ir/value.cc +++ b/mindspore/core/ir/value.cc @@ -130,7 +130,12 @@ bool FP32Imm::operator==(const Value &other) const { return false; } } -bool FP32Imm::operator==(const FP32Imm &other) const { return fabs(v_ - other.v_) < FLT_EPSILON; } +bool FP32Imm::operator==(const FP32Imm &other) const { + if (std::isinf(v_) && std::isinf(other.v_)) { + return true; + } + return fabs(v_ - other.v_) < FLT_EPSILON; +} bool FP64Imm::operator==(const Value &other) const { if (other.isa()) { auto other_ = static_cast(other); @@ -179,7 +184,12 @@ std::string ValueSequeue::DumpText() const { return oss.str(); } -bool FP64Imm::operator==(const FP64Imm &other) const { return fabs(v_ - other.v_) < DBL_EPSILON; } +bool FP64Imm::operator==(const FP64Imm &other) const { + if (std::isinf(v_) && std::isinf(other.v_)) { + return true; + } + return fabs(v_ - other.v_) < DBL_EPSILON; +} bool StringImm::operator==(const Value &other) const { if (other.isa()) { auto other_ = static_cast(other);