From e3c68bde78ccc55f4be0d9519f3e7b9d67e929ab Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Thu, 22 Aug 2019 10:18:20 +0800 Subject: [PATCH] stronger the error message of tensor's mutable_data (#19303) * stronger the error message of tensor's mutable_data test=develop * update error message test=develop --- paddle/fluid/framework/tensor.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/framework/tensor.cc b/paddle/fluid/framework/tensor.cc index 565b7d9d16c..f8bf9c5dc78 100644 --- a/paddle/fluid/framework/tensor.cc +++ b/paddle/fluid/framework/tensor.cc @@ -40,7 +40,9 @@ void* Tensor::mutable_data(platform::Place place, proto::VarType::Type type, PADDLE_ENFORCE_GE(numel(), 0, "When calling this method, the Tensor's numel must be " "equal or larger than zero. " - "Please check Tensor::Resize has been called first."); + "Please check Tensor::dims, or Tensor::Resize has been " + "called first. The Tensor's shape is [", + dims(), "] now"); size_t size = numel() * SizeOfType(type); if (requested_size) { PADDLE_ENFORCE_GE(requested_size, size); @@ -57,8 +59,8 @@ void* Tensor::mutable_data(platform::Place place, proto::VarType::Type type, } void* Tensor::mutable_data(platform::Place place, size_t requested_size) { - PADDLE_ENFORCE(this->holder_ != nullptr, - "Cannot invoke mutable data if current hold nothing."); + PADDLE_ENFORCE_NOT_NULL( + this->holder_, "Cannot invoke mutable data if current hold nothing."); return mutable_data(place, type_, requested_size); } -- GitLab