From 5cf2b2e81cab838833911c3f54c033fb3dacdf62 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Tue, 23 May 2017 18:18:38 +0800 Subject: [PATCH] compress code --- paddle/parameter/FirstOrderOptimizer.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/paddle/parameter/FirstOrderOptimizer.cpp b/paddle/parameter/FirstOrderOptimizer.cpp index d8292601629..5938b2210c7 100644 --- a/paddle/parameter/FirstOrderOptimizer.cpp +++ b/paddle/parameter/FirstOrderOptimizer.cpp @@ -308,17 +308,10 @@ void OptimizerWithGradientClipping::update(const VectorPtr vecs[], real globalThreshold = optConfig_.gradient_clipping_threshold(); real localThreshold = config.gradient_clipping_threshold(); - real threshold; - std::string field; // Use local gradient clipping threshold if it's enabled, // otherwise using the global one. - if (localThreshold > 0.0f) { - threshold = localThreshold; - field = "local"; - } else { - threshold = globalThreshold; - field = "global"; - } + real threshold = localThreshold > 0.0f ? localThreshold : globalThreshold; + std::string field = localThreshold > 0.0f ? "local" : "global"; real maxAbsGrad = vecs[PARAMETER_GRADIENT]->getAbsMax(); if (maxAbsGrad > threshold) { -- GitLab