提交 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 {
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;
......
......@@ -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();
}
......
......@@ -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.
......@@ -136,13 +138,6 @@ public:
*/
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_;
};
......
......@@ -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());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册