未验证 提交 0021b05b 编写于 作者: Z Zeng Jinle 提交者: GitHub

Merge pull request #14993 from sneaxiy/fix_check_lod

Fix CheckLoD bug
...@@ -157,13 +157,8 @@ bool CheckLoD(const LoD &in, int tensor_height) { ...@@ -157,13 +157,8 @@ bool CheckLoD(const LoD &in, int tensor_height) {
if (level.size() < 2) return false; if (level.size() < 2) return false;
// check: the first offset(the begin offset) of each level should be 0. // check: the first offset(the begin offset) of each level should be 0.
if (level.front() != 0) return false; if (level.front() != 0) return false;
// check: all the offsets in a level should be ascending(no same items // check: all the offsets in a level should be ascending(allow same items)
// allows). if (!std::is_sorted(level.begin(), level.end())) {
if (!std::is_sorted(level.begin(), level.begin(), [](size_t a, size_t b) {
if (a < b) return true;
return false;
})) {
LOG(INFO) << "ascending error";
return false; return false;
} }
} }
......
...@@ -217,6 +217,11 @@ TEST(LoD, CheckLoD) { ...@@ -217,6 +217,11 @@ TEST(LoD, CheckLoD) {
// check with underlying tensor storage. // check with underlying tensor storage.
ASSERT_TRUE(CheckLoD(relative_lod, 5)); ASSERT_TRUE(CheckLoD(relative_lod, 5));
ASSERT_FALSE(CheckLoD(relative_lod, 9)); ASSERT_FALSE(CheckLoD(relative_lod, 9));
// check whether lod is ascending-sorted (allow same items)
ASSERT_TRUE(CheckLoD({{0, 1, 2, 3, 4, 5}}, 5));
ASSERT_TRUE(CheckLoD({{0, 1, 3, 3, 4, 5}}, 5));
ASSERT_FALSE(CheckLoD({{0, 1, 3, 2, 5}}, 5));
} }
TEST(LoD, CheckAbsLoD) { TEST(LoD, CheckAbsLoD) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册