From 892cc28c7b7c77ead20f17d5644a4e9482906404 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Sun, 11 Feb 2018 20:03:07 +0800 Subject: [PATCH] Fix bug --- paddle/fluid/framework/mixed_vector.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/mixed_vector.h b/paddle/fluid/framework/mixed_vector.h index a06e34d5511..6e5ceefadd7 100644 --- a/paddle/fluid/framework/mixed_vector.h +++ b/paddle/fluid/framework/mixed_vector.h @@ -106,9 +106,11 @@ class Vector { // std::vector iterator methods. Based on CPU data access method size_t size() const { return size_; } - T* begin() { return size() == 0 ? &EmptyDummy() : &this->operator[](0); } + T* begin() { return capacity() == 0 ? &EmptyDummy() : &this->operator[](0); } - T* end() { return size() == 0 ? &EmptyDummy() : &this->operator[](size()); } + T* end() { + return capacity() == 0 ? &EmptyDummy() : &this->operator[](size()); + } T& front() { return *begin(); } @@ -119,11 +121,11 @@ class Vector { } const T* begin() const { - return size() == 0 ? &EmptyDummy() : &this->operator[](0); + return capacity() == 0 ? &EmptyDummy() : &this->operator[](0); } const T* end() const { - return size() == 0 ? &EmptyDummy() : &this->operator[](size()); + return capacity() == 0 ? &EmptyDummy() : &this->operator[](size()); } const T* cbegin() const { return begin(); } -- GitLab