From 54f09620cf6ee80224270cbf400cdbbcbdd19697 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Tue, 5 Dec 2017 08:43:08 +0800 Subject: [PATCH] code refine --- paddle/operators/elementwise_op_function.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/paddle/operators/elementwise_op_function.h b/paddle/operators/elementwise_op_function.h index 09ab42b501..14da42a786 100644 --- a/paddle/operators/elementwise_op_function.h +++ b/paddle/operators/elementwise_op_function.h @@ -70,9 +70,7 @@ struct RowwiseTransformIterator { RowwiseTransformIterator& operator++() { ++i_; - if (i_ == n_) { - i_ = 0; - } + i_ %= n_; return *this; } @@ -90,7 +88,7 @@ struct RowwiseTransformIterator { const T* ptr_; int i_; - int n_; + int64_t n_; }; template @@ -99,14 +97,7 @@ struct MidWiseTransformIterator { : ptr_(ptr), i_(0), j_(0), n_(n), post_(post) {} MidWiseTransformIterator& operator++() { - ++j_; - if (j_ == post_) { - j_ = 0; - ++i_; - if (i_ == n_) { - i_ = 0; - } - } + i_ = ++j_ / post_ % n_; return *this; } @@ -124,8 +115,8 @@ struct MidWiseTransformIterator { const T* ptr_; int i_; - int j_; - int n_; + int64_t j_; + int64_t n_; int post_; }; -- GitLab