From b6ac64a36bf260780d18dc6722f6ccdd0c96aba0 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Thu, 23 Feb 2017 15:06:30 +0800 Subject: [PATCH] Remove unnecessary error default value. --- paddle/gserver/evaluators/Evaluator.cpp | 8 +------ paddle/gserver/evaluators/Evaluator.h | 21 +++++++------------ .../gradientmachines/NeuralNetwork.cpp | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/paddle/gserver/evaluators/Evaluator.cpp b/paddle/gserver/evaluators/Evaluator.cpp index 8fce8df8a3b..6c1c2f62be2 100644 --- a/paddle/gserver/evaluators/Evaluator.cpp +++ b/paddle/gserver/evaluators/Evaluator.cpp @@ -781,9 +781,7 @@ real PrecisionRecallEvaluator::getValue(const std::string& name, paddle::str::split(name, '.', &buffers); auto it = this->values_.find(buffers[buffers.size() - 1]); if (it == this->values_.end()) { // not found - if (err != nullptr) { - *err = Error("No such key %s", name.c_str()); - } + *err = Error("No such key %s", name.c_str()); return .0f; } @@ -792,10 +790,6 @@ real PrecisionRecallEvaluator::getValue(const std::string& name, std::string PrecisionRecallEvaluator::getType(const std::string& name, Error* err) const { - Error localErr; - if (err == nullptr) { - err = &localErr; - } this->getValue(name, err); if (!err->isOK()) { return ""; diff --git a/paddle/gserver/evaluators/Evaluator.h b/paddle/gserver/evaluators/Evaluator.h index eb19e6f4dde..6a122704ea3 100644 --- a/paddle/gserver/evaluators/Evaluator.h +++ b/paddle/gserver/evaluators/Evaluator.h @@ -141,16 +141,13 @@ public: * @brief getValue will return the current evaluate value of one field. * * @param name: The field name of current evaluator. - * @param err [out]: The error state. nullptr means don't care. + * @param err [out]: The error state. * * @return The evaluate value(metric). */ - virtual real getValue(const std::string& name, - paddle::Error* err = nullptr) const { + virtual real getValue(const std::string& name, paddle::Error* err) const { if (name != config_.name()) { - if (err != nullptr) { - *err = paddle::Error("no such name of evaluator %s", name.c_str()); - } + *err = paddle::Error("no such name of evaluator %s", name.c_str()); return .0f; } return this->getValueImpl(); @@ -168,8 +165,8 @@ public: * @return the evaluator type string. */ virtual std::string getType(const std::string& name, - paddle::Error* err = nullptr) const { - if (name != config_.name() && err != nullptr) { + paddle::Error* err) const { + if (name != config_.name()) { *err = paddle::Error("no such name of evaluator %s", name.c_str()); return std::string(); } @@ -212,15 +209,11 @@ public: void getNames(std::vector* names) {} real getValue(const std::string& name, Error* err) const { - if (err != nullptr) { - *err = Error("Not implemented"); - } + *err = Error("Not implemented"); return .0f; } std::string getType(const std::string& name, Error* err) const { - if (err != nullptr) { - *err = Error("Not implemented"); - } + *err = Error("Not implemented"); return ""; } }; diff --git a/paddle/gserver/gradientmachines/NeuralNetwork.cpp b/paddle/gserver/gradientmachines/NeuralNetwork.cpp index 4d2bdf0dc99..273a9111c35 100644 --- a/paddle/gserver/gradientmachines/NeuralNetwork.cpp +++ b/paddle/gserver/gradientmachines/NeuralNetwork.cpp @@ -391,7 +391,7 @@ private: return callback(eval); } } - if (err != nullptr) *err = Error("No such key %s", name.c_str()); + *err = Error("No such key %s", name.c_str()); return T(); } }; -- GitLab