From 04f625085d17f3ddd91aa9452617bad86cec675c Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Fri, 9 Feb 2018 12:52:28 +0800 Subject: [PATCH] Fix CI --- paddle/framework/mixed_vector.h | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/paddle/framework/mixed_vector.h b/paddle/framework/mixed_vector.h index 2a80079695..fe9d8a44a5 100644 --- a/paddle/framework/mixed_vector.h +++ b/paddle/framework/mixed_vector.h @@ -30,26 +30,35 @@ class Vector { public: using value_type = T; - Vector() { - size_ = 0; - flag_ = kDataInCPU; - } + Vector() { InitEmpty(); } explicit Vector(size_t count, const T& value = T()) { - resize(count); - T* ptr = begin(); - for (size_t i = 0; i < count; ++i) { - ptr[i] = value; + if (count == 0) { + InitEmpty(); + } else { + resize(count); + T* ptr = begin(); + for (size_t i = 0; i < count; ++i) { + ptr[i] = value; + } } } Vector(std::initializer_list init) { - InitByIter(init.size(), init.begin(), init.end()); + if (init.size() == 0) { + InitEmpty(); + } else { + InitByIter(init.size(), init.begin(), init.end()); + } } template Vector(const std::vector& dat) { // NOLINT - InitByIter(dat.size(), dat.begin(), dat.end()); + if (dat.size() == 0) { + InitEmpty(); + } else { + InitByIter(dat.size(), dat.begin(), dat.end()); + } } Vector(const Vector& other) { this->operator=(other); } @@ -58,8 +67,7 @@ class Vector { if (other.size() != 0) { this->InitByIter(other.size(), other.begin(), other.end()); } else { - size_ = 0; - flag_ = kDataInCPU; + InitEmpty(); } return *this; } @@ -218,6 +226,11 @@ class Vector { } private: + void InitEmpty() { + size_ = 0; + flag_ = kDataInCPU; + } + template void InitByIter(size_t size, Iter begin, Iter end) { platform::Place cpu = platform::CPUPlace(); -- GitLab