From c3980db2dd97cc7222f55293b0560476f25efafc Mon Sep 17 00:00:00 2001 From: He Wei Date: Thu, 16 Dec 2021 17:30:44 +0800 Subject: [PATCH] Fix a bug in AbstractBase::operator==() If both abstracts are "undetermined", they should considered equal. This bug was introduced by a previous refectoring of operator==(). --- mindspore/core/abstract/abstract_value.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mindspore/core/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc index 33e34a1e395..6f95149c0ce 100644 --- a/mindspore/core/abstract/abstract_value.cc +++ b/mindspore/core/abstract/abstract_value.cc @@ -94,10 +94,21 @@ bool AbstractBase::operator==(const AbstractBase &other) const { // Same object. return true; } - return tid() == other.tid() && // c++ type equal and - IsEqual(type_, other.type_) && // type equal and - IsEqual(shape_, other.shape_) && // shape equal and - IsEqual(value_, other.value_); // value equal. + // Check C++ type. + if (tid() != other.tid()) { + return false; + } + // Check data type. + if (!IsEqual(type_, other.type_)) { + return false; + } + // If both are "undetermined" type, they are considered equal. + if (type_ == kAnyType && BuildType()->type_id() == kObjectTypeUndeterminedType && + other.BuildType()->type_id() == kObjectTypeUndeterminedType) { + return true; + } + // Check shape and value. + return IsEqual(shape_, other.shape_) && IsEqual(value_, other.value_); } ValuePtr AbstractBase::BuildValue() const {