未验证 提交 a1e73879 编写于 作者: Y yiicy 提交者: GitHub

Variable error message enhancement, test=develop (#23548)

上级 93aa6690
...@@ -30,11 +30,13 @@ class Variable { ...@@ -30,11 +30,13 @@ class Variable {
static_assert( static_assert(
IsRegisteredVarType<T>(), IsRegisteredVarType<T>(),
"Not registered type. Please register T inside var_type_traits.h"); "Not registered type. Please register T inside var_type_traits.h");
PADDLE_ENFORCE(holder_ != nullptr, "Variable is not initialized."); PADDLE_ENFORCE_NOT_NULL(
PADDLE_ENFORCE(holder_->Type() == VarTypeTrait<T>::kId, holder_, platform::errors::NotFound("Variable is not initialized."));
PADDLE_ENFORCE_EQ(
holder_->Type(), VarTypeTrait<T>::kId,
platform::errors::InvalidArgument(
"The Variable type must be %s, but the type it holds is %s.", "The Variable type must be %s, but the type it holds is %s.",
ToTypeName(VarTypeTrait<T>::kId), ToTypeName(VarTypeTrait<T>::kId), ToTypeName(holder_->Type())));
ToTypeName(holder_->Type()));
return *static_cast<const T*>(holder_->Ptr()); return *static_cast<const T*>(holder_->Ptr());
} }
...@@ -45,10 +47,11 @@ class Variable { ...@@ -45,10 +47,11 @@ class Variable {
if (!holder_) { if (!holder_) {
holder_.reset(new PlaceholderImpl<T>()); holder_.reset(new PlaceholderImpl<T>());
} else { } else {
PADDLE_ENFORCE( PADDLE_ENFORCE_EQ(
holder_->Type() == VarTypeTrait<T>::kId, holder_->Type(), VarTypeTrait<T>::kId,
platform::errors::InvalidArgument(
"The Variable type must be %s, but the type it holds is %s.", "The Variable type must be %s, but the type it holds is %s.",
ToTypeName(VarTypeTrait<T>::kId), ToTypeName(holder_->Type())); ToTypeName(VarTypeTrait<T>::kId), ToTypeName(holder_->Type())));
} }
return static_cast<T*>(holder_->Ptr()); return static_cast<T*>(holder_->Ptr());
} }
...@@ -61,7 +64,8 @@ class Variable { ...@@ -61,7 +64,8 @@ class Variable {
void Clear() { holder_.reset(); } void Clear() { holder_.reset(); }
int Type() const { int Type() const {
PADDLE_ENFORCE(holder_ != nullptr, "Variable is not initialized."); PADDLE_ENFORCE_NOT_NULL(
holder_, platform::errors::NotFound("Variable is not initialized."));
return holder_->Type(); return holder_->Type();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册