From 8711a9a22aaf2ed4d4711089d0136da133c1826d Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Wed, 6 Dec 2017 11:19:16 +0800 Subject: [PATCH] refine code --- paddle/operators/elementwise_add_op.h | 2 +- paddle/operators/elementwise_op_function.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/paddle/operators/elementwise_add_op.h b/paddle/operators/elementwise_add_op.h index 3a198c167..921dc5f6a 100644 --- a/paddle/operators/elementwise_add_op.h +++ b/paddle/operators/elementwise_add_op.h @@ -21,7 +21,7 @@ namespace operators { template struct AddFunctor { - HOSTDEVICE T operator()(T a, T b) const { return a + b; } + inline HOSTDEVICE T operator()(T a, T b) const { return a + b; } }; template diff --git a/paddle/operators/elementwise_op_function.h b/paddle/operators/elementwise_op_function.h index ec448a9e9..ca3542e78 100644 --- a/paddle/operators/elementwise_op_function.h +++ b/paddle/operators/elementwise_op_function.h @@ -71,7 +71,9 @@ class RowwiseTransformIterator { RowwiseTransformIterator& operator++() { ++i_; - i_ %= n_; + if (UNLIKELY(i_ == n_)) { + i_ = 0; + } return *this; } @@ -100,7 +102,12 @@ class MidWiseTransformIterator { : ptr_(ptr), i_(0), j_(0), n_(n), post_(post) {} MidWiseTransformIterator& operator++() { - i_ = (++j_ / post_) % n_; + ++j_; + i_ = j_ / post_; + if (UNLIKELY(i_ == n_)) { + j_ = 0; + i_ = 0; + } return *this; } -- GitLab