提交 f4e57b4b 编写于 作者: Y Yu Yang

Fix bug in SequenceSoftmax

Also remove operator bool in Error. The Error should be removed
later because it is not necessary for Paddle. We are now using Enforce
to handle error.
上级 afe7bf61
...@@ -37,7 +37,7 @@ std::vector<std::string> Evaluator::getNames() const { ...@@ -37,7 +37,7 @@ std::vector<std::string> Evaluator::getNames() const {
double Evaluator::getValue(const std::string name) const { double Evaluator::getValue(const std::string name) const {
paddle::Error err; paddle::Error err;
double v = m->rawPtr->getValue(name, &err); double v = m->rawPtr->getValue(name, &err);
if (err) { if (!err.isOK()) {
throw std::runtime_error(err.msg()); throw std::runtime_error(err.msg());
} }
return v; return v;
......
...@@ -207,8 +207,8 @@ Error __must_check backward(Argument& act) { ...@@ -207,8 +207,8 @@ Error __must_check backward(Argument& act) {
argument_.value->setData(act.value->getData() + offset, 1UL, size); argument_.value->setData(act.value->getData() + offset, 1UL, size);
argument_.grad->setData(act.grad->getData() + offset, 1UL, size); argument_.grad->setData(act.grad->getData() + offset, 1UL, size);
Error status = softmax_.backward(argument_); Error err = softmax_.backward(argument_);
if (!status) return status; if (!err.isOK()) return err;
} }
return Error(); return Error();
} }
......
...@@ -126,9 +126,11 @@ public: ...@@ -126,9 +126,11 @@ public:
} }
/** /**
* @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. * @brief isOK return True if there is no error.
...@@ -136,13 +138,6 @@ public: ...@@ -136,13 +138,6 @@ public:
*/ */
bool isOK() const { return msg_ == nullptr; } 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: private:
std::shared_ptr<std::string> msg_; std::shared_ptr<std::string> msg_;
}; };
......
...@@ -18,17 +18,17 @@ limitations under the License. */ ...@@ -18,17 +18,17 @@ limitations under the License. */
TEST(Error, testAll) { TEST(Error, testAll) {
paddle::Error error; paddle::Error error;
ASSERT_FALSE(error); ASSERT_TRUE(error.isOK());
error = paddle::Error("I'm the error"); error = paddle::Error("I'm the error");
ASSERT_TRUE(error); ASSERT_FALSE(error.isOK());
ASSERT_STREQ("I'm the error", error.msg()); ASSERT_STREQ("I'm the error", error.msg());
error = paddle::Error("error2"); error = paddle::Error("error2");
ASSERT_TRUE(error); ASSERT_FALSE(error.isOK());
ASSERT_STREQ("error2", error.msg()); ASSERT_STREQ("error2", error.msg());
int i = 3; int i = 3;
auto error3 = paddle::Error("error%d", i); auto error3 = paddle::Error("error%d", i);
ASSERT_TRUE(error3); ASSERT_FALSE(error3.isOK());
ASSERT_STREQ("error3", error3.msg()); ASSERT_STREQ("error3", error3.msg());
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册