From 68d91cd59455ece3146bb857467e71a04f8bfb97 Mon Sep 17 00:00:00 2001 From: sneaxiy Date: Tue, 25 Dec 2018 02:29:25 +0000 Subject: [PATCH] add copy ctor test=develop --- paddle/fluid/framework/ddim.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/paddle/fluid/framework/ddim.h b/paddle/fluid/framework/ddim.h index 295d09bbc..123e227dc 100644 --- a/paddle/fluid/framework/ddim.h +++ b/paddle/fluid/framework/ddim.h @@ -60,6 +60,8 @@ class DDim { DDim() : rank_(1) { dim_[0] = 0; } + DDim(const DDim& ddim) { this->CopyFrom(ddim); } + DDim(const int* d, int n) : rank_(n) { dynamic_dim_assign(d, dim_.GetMutable(), n); } @@ -138,6 +140,12 @@ class DDim { return *reinterpret_cast*>(p); } + inline void CopyFrom(const DDim& ddim) { + rank_ = ddim.rank_; + PADDLE_VISIT_DDIM(rank_, + (void)(UnsafeCast() = ddim.UnsafeCast())); + } + friend DDim slice_ddim(const DDim& dim, int begin, int end); friend DDim stride(const DDim& ddim); friend DDim stride_numel(const DDim& ddim); -- GitLab