From cf205d0d43a82ef46cd9374218555be339dab5eb Mon Sep 17 00:00:00 2001 From: xutianbing Date: Tue, 22 Nov 2016 14:24:30 -0800 Subject: [PATCH] deepSwap --- paddle/math/BaseMatrix.cu | 6 ++++++ paddle/math/BaseMatrix.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/paddle/math/BaseMatrix.cu b/paddle/math/BaseMatrix.cu index 2f32b3fdd1a..a723ef7bc83 100644 --- a/paddle/math/BaseMatrix.cu +++ b/paddle/math/BaseMatrix.cu @@ -1240,6 +1240,12 @@ void BaseMatrixT::assignAtOffset(BaseMatrixT& b, int64_t columnOffset) { } } +DEFINE_MATRIX_BINARY_OP(DeepSwap, T tmp = a; a = b; b = tmp); +template +void BaseMatrixT::deepSwap(BaseMatrixT& b) { + applyBinary(binary::DeepSwap(), b); +} + template<> void BaseMatrixT::rowDotMul(size_t destCol, BaseMatrixT& b, diff --git a/paddle/math/BaseMatrix.h b/paddle/math/BaseMatrix.h index d41dcee682c..dbc217c30f2 100644 --- a/paddle/math/BaseMatrix.h +++ b/paddle/math/BaseMatrix.h @@ -455,6 +455,13 @@ public: */ void assign(T p); + /** + * @code + * swap(this, b) + * @endcode + */ + void deepSwap(BaseMatrixT& b); + /** * @code * this = this + p -- GitLab