From 96d550093446e44d505361c51b304ff59b1977f7 Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Sat, 27 Oct 2018 20:58:37 +0800 Subject: [PATCH] optimize code --- paddle/fluid/operators/math/selected_rows_functor.cc | 6 +++--- paddle/fluid/operators/math/selected_rows_functor.cu | 6 +++--- paddle/fluid/operators/sum_op.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/math/selected_rows_functor.cc b/paddle/fluid/operators/math/selected_rows_functor.cc index 305743b082..7594674037 100644 --- a/paddle/fluid/operators/math/selected_rows_functor.cc +++ b/paddle/fluid/operators/math/selected_rows_functor.cc @@ -275,7 +275,7 @@ struct MergeAdd { } const framework::SelectedRows* has_value_input = nullptr; for (auto* in : inputs) { - if (!in->rows().empty()) { + if (in->rows().size() > 0) { has_value_input = in; break; } @@ -289,7 +289,7 @@ struct MergeAdd { framework::SelectedRows& out = *output; std::set merged_row_set; for (auto* input : inputs) { - if (input->rows().empty()) { + if (input->rows().size() == 0) { continue; } PADDLE_ENFORCE_EQ(input_width, input->value().dims()[1], @@ -319,7 +319,7 @@ struct MergeAdd { auto blas = math::GetBlas(context); for (auto* input : inputs) { - if (input->rows().empty()) { + if (input->rows().size() == 0) { continue; } auto* input_data = input->value().data(); diff --git a/paddle/fluid/operators/math/selected_rows_functor.cu b/paddle/fluid/operators/math/selected_rows_functor.cu index 7d94a45289..10f39822b9 100644 --- a/paddle/fluid/operators/math/selected_rows_functor.cu +++ b/paddle/fluid/operators/math/selected_rows_functor.cu @@ -311,7 +311,7 @@ struct MergeAdd { } const framework::SelectedRows* has_value_input = nullptr; for (auto* in : inputs) { - if (!in->rows().empty()) { + if (in->rows().size() > 0) { has_value_input = in; break; } @@ -325,7 +325,7 @@ struct MergeAdd { framework::SelectedRows& out = *output; std::set merged_row_set; for (auto* input : inputs) { - if (input->rows().empty()) { + if (input->rows().size() == 0) { continue; } PADDLE_ENFORCE_EQ(input_width, input->value().dims()[1], @@ -355,7 +355,7 @@ struct MergeAdd { dim3 threads(block_size, 1); for (auto* input : inputs) { - if (input->rows().empty()) { + if (input->rows().size() == 0) { continue; } auto* input_data = input->value().data(); diff --git a/paddle/fluid/operators/sum_op.h b/paddle/fluid/operators/sum_op.h index 69e619a530..84b418bd30 100644 --- a/paddle/fluid/operators/sum_op.h +++ b/paddle/fluid/operators/sum_op.h @@ -107,7 +107,7 @@ class SumKernel : public framework::OpKernel { } else { for (auto &in_var : in_vars) { auto &in = in_var->Get(); - if (!in.rows().empty()) { + if (in.rows().size() > 0) { inputs.push_back(&in_var->Get()); } } -- GitLab