提交 04f62508 编写于 作者: Y Yu Yang

Fix CI

上级 0439ba2f
...@@ -30,27 +30,36 @@ class Vector { ...@@ -30,27 +30,36 @@ class Vector {
public: public:
using value_type = T; using value_type = T;
Vector() { Vector() { InitEmpty(); }
size_ = 0;
flag_ = kDataInCPU;
}
explicit Vector(size_t count, const T& value = T()) { explicit Vector(size_t count, const T& value = T()) {
if (count == 0) {
InitEmpty();
} else {
resize(count); resize(count);
T* ptr = begin(); T* ptr = begin();
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
ptr[i] = value; ptr[i] = value;
} }
} }
}
Vector(std::initializer_list<T> init) { Vector(std::initializer_list<T> init) {
if (init.size() == 0) {
InitEmpty();
} else {
InitByIter(init.size(), init.begin(), init.end()); InitByIter(init.size(), init.begin(), init.end());
} }
}
template <typename U> template <typename U>
Vector(const std::vector<U>& dat) { // NOLINT Vector(const std::vector<U>& dat) { // NOLINT
if (dat.size() == 0) {
InitEmpty();
} else {
InitByIter(dat.size(), dat.begin(), dat.end()); InitByIter(dat.size(), dat.begin(), dat.end());
} }
}
Vector(const Vector<T>& other) { this->operator=(other); } Vector(const Vector<T>& other) { this->operator=(other); }
...@@ -58,8 +67,7 @@ class Vector { ...@@ -58,8 +67,7 @@ class Vector {
if (other.size() != 0) { if (other.size() != 0) {
this->InitByIter(other.size(), other.begin(), other.end()); this->InitByIter(other.size(), other.begin(), other.end());
} else { } else {
size_ = 0; InitEmpty();
flag_ = kDataInCPU;
} }
return *this; return *this;
} }
...@@ -218,6 +226,11 @@ class Vector { ...@@ -218,6 +226,11 @@ class Vector {
} }
private: private:
void InitEmpty() {
size_ = 0;
flag_ = kDataInCPU;
}
template <typename Iter> template <typename Iter>
void InitByIter(size_t size, Iter begin, Iter end) { void InitByIter(size_t size, Iter begin, Iter end) {
platform::Place cpu = platform::CPUPlace(); platform::Place cpu = platform::CPUPlace();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册