Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paddle/api/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::vector<std::string> Evaluator::getNames() const {
double Evaluator::getValue(const std::string name) const {
paddle::Error err;
double v = m->rawPtr->getValue(name, &err);
if (err) {
if (!err.isOK()) {
throw std::runtime_error(err.msg());
}
return v;
Expand Down
4 changes: 2 additions & 2 deletions paddle/gserver/activations/ActivationFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ Error __must_check backward(Argument& act) {
argument_.value->setData(act.value->getData() + offset, 1UL, size);
argument_.grad->setData(act.grad->getData() + offset, 1UL, size);

Error status = softmax_.backward(argument_);
if (!status) return status;
Error err = softmax_.backward(argument_);
if (!err.isOK()) return err;
}
return Error();
}
Expand Down
13 changes: 4 additions & 9 deletions paddle/utils/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,18 @@ class Error {
}

/**
* @brief operator bool, return True if there is something error.
* @brief check this status by glog.
* @note It is a temp method used during cleaning Paddle code. It will be
* removed later.
*/
operator bool() const { return !this->isOK(); }
void check() const { CHECK(this->isOK()) << msg(); }

/**
* @brief isOK return True if there is no error.
* @return True if no error.
*/
bool isOK() const { return msg_ == nullptr; }

/**
* @brief check this status by glog.
* @note It is a temp method used during cleaning Paddle code. It will be
* removed later.
*/
void check() const { CHECK(this->isOK()) << msg(); }

private:
std::shared_ptr<std::string> msg_;
};
Expand Down
8 changes: 4 additions & 4 deletions paddle/utils/tests/test_Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ limitations under the License. */

TEST(Error, testAll) {
paddle::Error error;
ASSERT_FALSE(error);
ASSERT_TRUE(error.isOK());
error = paddle::Error("I'm the error");
ASSERT_TRUE(error);
ASSERT_FALSE(error.isOK());
ASSERT_STREQ("I'm the error", error.msg());

error = paddle::Error("error2");
ASSERT_TRUE(error);
ASSERT_FALSE(error.isOK());
ASSERT_STREQ("error2", error.msg());

int i = 3;
auto error3 = paddle::Error("error%d", i);
ASSERT_TRUE(error3);
ASSERT_FALSE(error3.isOK());
ASSERT_STREQ("error3", error3.msg());
}