From 34beec0f7a645ee4c5c0ce47592619c5ed05facc Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Fri, 14 Jul 2017 19:32:01 +0800 Subject: [PATCH] update tensor.h --- paddle/framework/tensor.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/paddle/framework/tensor.h b/paddle/framework/tensor.h index 8b2a65dca9a..d98706e6ed8 100644 --- a/paddle/framework/tensor.h +++ b/paddle/framework/tensor.h @@ -33,7 +33,7 @@ class Tensor { template const T* data() const { - CheckDimsValidity(); + CheckDims(); return reinterpret_cast( reinterpret_cast(holder_->ptr()) + offset_); } @@ -62,7 +62,7 @@ class Tensor { template void ShareDataFrom(const Tensor& src) { - src.CheckDimsValidity(); + src.CheckDims(); holder_ = src.holder_; set_dims(src.dims()); offset_ = src.offset_; @@ -73,7 +73,7 @@ class Tensor { PADDLE_ENFORCE(platform::is_cpu_place(src.holder_->place()) && platform::is_cpu_place(dst_place), "Tensor::CopyFrom only support CPU now."); - src.CheckDimsValidity(); + src.CheckDims(); size_t size = src.numel_ * sizeof(T); set_dims(src.dims()); const void* src_ptr = static_cast(src.data()); @@ -83,7 +83,7 @@ class Tensor { template Tensor Slice(const int& begin_idx, const int& end_idx) const { - CheckDimsValidity(); + CheckDims(); PADDLE_ENFORCE(begin_idx >= 0 && end_idx <= dims_[0], "Slice index is less than zero or out of bound."); PADDLE_ENFORCE(begin_idx < end_idx, @@ -109,7 +109,6 @@ class Tensor { } dims_ = dims; numel_ = product(dims_); - return; } DDim dims() const { return dims_; } @@ -155,10 +154,10 @@ class Tensor { }; template - inline void CheckDimsValidity() const { + inline void CheckDims() const { PADDLE_ENFORCE(holder_ != nullptr, "Tenosr holds no memory. Call Tensor::mutable_data first."); - PADDLE_ENFORCE(holder_->size() > numel_ * sizeof(T) + offset_, + PADDLE_ENFORCE(holder_->size() >= numel_ * sizeof(T) + offset_, "Tensor's dims_ is out of bound. Call Tensor::mutable_data " "first to re-allocate memory."); } -- GitLab