diff --git a/paddle/fluid/framework/ddim.cc b/paddle/fluid/framework/ddim.cc index 37544e97eb655287860f8b113e0e1f1ed298474b..e7a6df57e538164969bc101ced4b91de8f75ca56 100644 --- a/paddle/fluid/framework/ddim.cc +++ b/paddle/fluid/framework/ddim.cc @@ -131,8 +131,6 @@ DDim slice_ddim(const DDim& dim, int begin, int end) { int arity(const DDim& d) { return d.size(); } -/// \cond HIDDEN - struct DDimPrinter { std::ostream& os; explicit DDimPrinter(std::ostream& os_) : os(os_) {} @@ -143,8 +141,6 @@ struct DDimPrinter { } }; -/// \endcond - std::ostream& operator<<(std::ostream& os, const DDim& ddim) { ddim.apply_visitor(DDimPrinter(os)); return os; diff --git a/paddle/fluid/framework/ddim.h b/paddle/fluid/framework/ddim.h index 452072a58762d9a5668e351e98eb6e7c8e38f4b3..295d09bbcac549d755690e928a050e3c05743a7a 100644 --- a/paddle/fluid/framework/ddim.h +++ b/paddle/fluid/framework/ddim.h @@ -126,7 +126,9 @@ class DDim { private: template inline Dim& UnsafeCast() { - return const_cast&>(const_cast(this)->UnsafeCast()); + static_assert(D >= 0 && D <= kMaxRank, "Invalid rank"); + auto* p = static_cast(&dim_); + return *reinterpret_cast*>(p); } template