diff --git a/paddle/fluid/framework/ddim.h b/paddle/fluid/framework/ddim.h index 295d09bbcac549d755690e928a050e3c05743a7a..123e227dc0423587b2f171bf3442352e1be63d4a 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);