|
|
|
@ -26,6 +26,7 @@
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace framework {
|
|
|
|
|
|
|
|
|
|
#if defined(PADDLE_WITH_CUDA)
|
|
|
|
|
// Vector<T> implements the std::vector interface, and can get Data or
|
|
|
|
|
// MutableData from any place. The data will be synced implicitly inside.
|
|
|
|
|
template <typename T>
|
|
|
|
@ -379,5 +380,53 @@ class Vector {
|
|
|
|
|
size_t size_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
|
#else // PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
class CPUVector : public std::vector<T, std::allocator<T>> {
|
|
|
|
|
public:
|
|
|
|
|
CPUVector() : std::vector<T>() {}
|
|
|
|
|
CPUVector(size_t count, const T &value = T())
|
|
|
|
|
: std::vector<T>(count, value) {}
|
|
|
|
|
CPUVector(std::initializer_list<T> init) : std::vector<T>(init) {}
|
|
|
|
|
CPUVector(const std::vector<T> &other) : std::vector<T>(other) {}
|
|
|
|
|
explicit CPUVector(const CPUVector<T> &other) : std::vector<T>(other) {}
|
|
|
|
|
CPUVector(CPUVector<T> &&other) : std::vector<T>(std::move(other)) {}
|
|
|
|
|
CPUVector(std::vector<T> &&other) : std::vector<T>(std::move(other)) {}
|
|
|
|
|
CPUVector &operator=(const CPUVector &other) {
|
|
|
|
|
this->assign(other.begin(), other.end());
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
CPUVector &operator=(const std::vector<T> &other) {
|
|
|
|
|
this->assign(other.begin(), other.end());
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &os, const CPUVector<T> &other) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
for (auto v : other) {
|
|
|
|
|
os << v << " ";
|
|
|
|
|
}
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resize(size_t size) { this->resize(size); }
|
|
|
|
|
|
|
|
|
|
T &operator[](size_t id) { return this->at(id); }
|
|
|
|
|
|
|
|
|
|
const T &operator[](size_t id) const { return this->at(id); }
|
|
|
|
|
|
|
|
|
|
template <typename D>
|
|
|
|
|
void Extend(const D &begin, const D &end) {
|
|
|
|
|
this->reserve(this->size() + size_t(end - begin));
|
|
|
|
|
this->insert(this->end(), begin, end);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
using Vector = CPUVector<T>;
|
|
|
|
|
|
|
|
|
|
#endif // PADDLE_WITH_CUDA
|
|
|
|
|
|
|
|
|
|
}; // namespace framework
|
|
|
|
|
} // namespace paddle
|
|
|
|
|