use std::is_sorted

fix comment
test=develop
revert-15207-remove_op_handle_lock_and_fix_var
sneaxiy 6 years ago
parent b8051e7927
commit a30c5373eb

@ -157,19 +157,11 @@ bool CheckLoD(const LoD &in, int tensor_height) {
if (level.size() < 2) return false;
// check: the first offset(the begin offset) of each level should be 0.
if (level.front() != 0) return false;
// check: all the offsets in a level should be ascending(no same items
// allows).
auto beg = level.begin();
auto end = level.end();
// Do not use std::is_sorted, because we need strictly sorted lod
if (beg != end) {
for (auto it = beg + 1; it != end; ++it) {
if (*(it - 1) >= *it) {
// check: all the offsets in a level should be ascending(allow same items)
if (!std::is_sorted(level.begin(), level.end())) {
return false;
}
}
}
}
// check: the lowest level's last offset should equals `tensor_height` if
// tensor_height>0.
if (tensor_height > 0 && (size_t)tensor_height != in.back().back())

@ -218,9 +218,10 @@ TEST(LoD, CheckLoD) {
ASSERT_TRUE(CheckLoD(relative_lod, 5));
ASSERT_FALSE(CheckLoD(relative_lod, 9));
// check strictly sorted lod
// check whether lod is ascending-sorted (allow same items)
ASSERT_TRUE(CheckLoD({{0, 1, 2, 3, 4, 5}}, 5));
ASSERT_FALSE(CheckLoD({{0, 1, 3, 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) {

Loading…
Cancel
Save