From 62eaa1fbabaf2ae751bc40d6be5c8cb3f7c2f291 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Thu, 1 Dec 2016 20:38:33 +0800 Subject: [PATCH] Move one line with identical value across loops out of the loop. --- paddle/gserver/layers/CRFLayer.cpp | 2 +- paddle/gserver/tests/test_CRFLayerGrad.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/gserver/layers/CRFLayer.cpp b/paddle/gserver/layers/CRFLayer.cpp index fa434cda002..b9fb7e54bdb 100644 --- a/paddle/gserver/layers/CRFLayer.cpp +++ b/paddle/gserver/layers/CRFLayer.cpp @@ -91,8 +91,8 @@ void CRFLayer::backward(const UpdateCallback& callback) { const int* starts = label.sequenceStartPositions->getData(false); int numSequences = label.sequenceStartPositions->getSize() - 1; + bool needWGrad = weight_->getWGrad() ? true : false; for (int i = 0; i < numSequences; ++i) { - bool needWGrad = weight_->getWGrad() ? true : false; crfs_[i].backward(output.value->getData() + numClasses_ * starts[i], label.ids->getData() + starts[i], starts[i + 1] - starts[i], needWGrad); diff --git a/paddle/gserver/tests/test_CRFLayerGrad.cpp b/paddle/gserver/tests/test_CRFLayerGrad.cpp index bc1d5f3061d..ad5149306ca 100644 --- a/paddle/gserver/tests/test_CRFLayerGrad.cpp +++ b/paddle/gserver/tests/test_CRFLayerGrad.cpp @@ -108,7 +108,7 @@ TEST(CRFLayer, cost) { } inline real epsilon() { - return typeid(real) == typeid(double) ? 1e-10 : 0.05; + return typeid(real) == typeid(double) ? 1e-10 : 0.06; } TestConfig initTestConfig(size_t numClasses, bool withWeight) { -- GitLab