Clang-tidy static analysis (#3222)

* Clang-tidy static analysis

* Modernise checks

* Google coding standard checks

* Identifier renaming according to Google style
This commit is contained in:
Rory Mitchell
2018-04-19 18:57:13 +12:00
committed by GitHub
parent 3242b0a378
commit ccf80703ef
97 changed files with 3407 additions and 3354 deletions

View File

@@ -12,9 +12,9 @@ TEST(MetaInfo, GetSet) {
info.SetInfo("root_index", double2, xgboost::kDouble, 2);
EXPECT_EQ(info.GetRoot(1), 2.0f);
EXPECT_EQ(info.labels.size(), 0);
EXPECT_EQ(info.labels_.size(), 0);
info.SetInfo("label", double2, xgboost::kFloat32, 2);
EXPECT_EQ(info.labels.size(), 2);
EXPECT_EQ(info.labels_.size(), 2);
float float2[2] = {1.0f, 2.0f};
EXPECT_EQ(info.GetWeight(1), 1.0f)
@@ -23,26 +23,26 @@ TEST(MetaInfo, GetSet) {
EXPECT_EQ(info.GetWeight(1), 2.0f);
uint32_t uint32_t2[2] = {1U, 2U};
EXPECT_EQ(info.base_margin.size(), 0);
EXPECT_EQ(info.base_margin_.size(), 0);
info.SetInfo("base_margin", uint32_t2, xgboost::kUInt32, 2);
EXPECT_EQ(info.base_margin.size(), 2);
EXPECT_EQ(info.base_margin_.size(), 2);
uint64_t uint64_t2[2] = {1U, 2U};
EXPECT_EQ(info.group_ptr.size(), 0);
EXPECT_EQ(info.group_ptr_.size(), 0);
info.SetInfo("group", uint64_t2, xgboost::kUInt64, 2);
ASSERT_EQ(info.group_ptr.size(), 3);
EXPECT_EQ(info.group_ptr[2], 3);
ASSERT_EQ(info.group_ptr_.size(), 3);
EXPECT_EQ(info.group_ptr_[2], 3);
info.Clear();
ASSERT_EQ(info.group_ptr.size(), 0);
ASSERT_EQ(info.group_ptr_.size(), 0);
}
TEST(MetaInfo, SaveLoadBinary) {
xgboost::MetaInfo info;
double vals[2] = {1.0, 2.0};
info.SetInfo("label", vals, xgboost::kDouble, 2);
info.num_row = 2;
info.num_col = 1;
info.num_row_ = 2;
info.num_col_ = 1;
std::string tmp_file = TempFileName();
dmlc::Stream * fs = dmlc::Stream::Create(tmp_file.c_str(), "w");
@@ -55,9 +55,9 @@ TEST(MetaInfo, SaveLoadBinary) {
fs = dmlc::Stream::Create(tmp_file.c_str(), "r");
xgboost::MetaInfo inforead;
inforead.LoadBinary(fs);
EXPECT_EQ(inforead.labels, info.labels);
EXPECT_EQ(inforead.num_col, info.num_col);
EXPECT_EQ(inforead.num_row, info.num_row);
EXPECT_EQ(inforead.labels_, info.labels_);
EXPECT_EQ(inforead.num_col_, info.num_col_);
EXPECT_EQ(inforead.num_row_, info.num_row_);
std::remove(tmp_file.c_str());
}

View File

@@ -14,9 +14,9 @@ TEST(SimpleCSRSource, SaveLoadBinary) {
xgboost::DMatrix * dmat_read = xgboost::DMatrix::Load(tmp_binfile, true, false);
std::remove(tmp_binfile.c_str());
EXPECT_EQ(dmat->info().num_col, dmat_read->info().num_col);
EXPECT_EQ(dmat->info().num_row, dmat_read->info().num_row);
EXPECT_EQ(dmat->info().num_row, dmat_read->info().num_row);
EXPECT_EQ(dmat->Info().num_col_, dmat_read->Info().num_col_);
EXPECT_EQ(dmat->Info().num_row_, dmat_read->Info().num_row_);
EXPECT_EQ(dmat->Info().num_row_, dmat_read->Info().num_row_);
dmlc::DataIter<xgboost::RowBatch> * row_iter = dmat->RowIterator();
dmlc::DataIter<xgboost::RowBatch> * row_iter_read = dmat_read->RowIterator();

View File

@@ -10,10 +10,10 @@ TEST(SimpleDMatrix, MetaInfo) {
std::remove(tmp_file.c_str());
// Test the metadata that was parsed
EXPECT_EQ(dmat->info().num_row, 2);
EXPECT_EQ(dmat->info().num_col, 5);
EXPECT_EQ(dmat->info().num_nonzero, 6);
EXPECT_EQ(dmat->info().labels.size(), dmat->info().num_row);
EXPECT_EQ(dmat->Info().num_row_, 2);
EXPECT_EQ(dmat->Info().num_col_, 5);
EXPECT_EQ(dmat->Info().num_nonzero_, 6);
EXPECT_EQ(dmat->Info().labels_.size(), dmat->Info().num_row_);
}
TEST(SimpleDMatrix, RowAccess) {
@@ -26,7 +26,7 @@ TEST(SimpleDMatrix, RowAccess) {
long row_count = 0;
row_iter->BeforeFirst();
while (row_iter->Next()) row_count += row_iter->Value().size;
EXPECT_EQ(row_count, dmat->info().num_row);
EXPECT_EQ(row_count, dmat->Info().num_row_);
// Test the data read into the first row
row_iter->BeforeFirst();
row_iter->Next();
@@ -43,15 +43,15 @@ TEST(SimpleDMatrix, ColAccessWithoutBatches) {
std::remove(tmp_file.c_str());
// Unsorted column access
const std::vector<bool> enable(dmat->info().num_col, true);
const std::vector<bool> enable(dmat->Info().num_col_, true);
EXPECT_EQ(dmat->HaveColAccess(false), false);
dmat->InitColAccess(enable, 1, dmat->info().num_row, false);
dmat->InitColAccess(enable, 1, dmat->Info().num_row_, false);
dmat->InitColAccess(enable, 0, 0, false); // Calling it again should not change it
ASSERT_EQ(dmat->HaveColAccess(false), true);
// Sorted column access
EXPECT_EQ(dmat->HaveColAccess(true), false);
dmat->InitColAccess(enable, 1, dmat->info().num_row, true);
dmat->InitColAccess(enable, 1, dmat->Info().num_row_, true);
dmat->InitColAccess(enable, 0, 0, true); // Calling it again should not change it
ASSERT_EQ(dmat->HaveColAccess(true), true);
@@ -67,7 +67,7 @@ TEST(SimpleDMatrix, ColAccessWithoutBatches) {
col_iter->BeforeFirst();
while (col_iter->Next()) {
num_col_batch += 1;
EXPECT_EQ(col_iter->Value().size, dmat->info().num_col)
EXPECT_EQ(col_iter->Value().size, dmat->Info().num_col_)
<< "Expected batch size = number of cells as #batches is 1.";
for (int i = 0; i < static_cast<int>(col_iter->Value().size); ++i) {
EXPECT_EQ(col_iter->Value()[i].length, dmat->GetColSize(i))
@@ -94,7 +94,7 @@ TEST(SimpleDMatrix, ColAccessWithBatches) {
std::remove(tmp_file.c_str());
// Unsorted column access
const std::vector<bool> enable(dmat->info().num_col, true);
const std::vector<bool> enable(dmat->Info().num_col_, true);
EXPECT_EQ(dmat->HaveColAccess(false), false);
dmat->InitColAccess(enable, 1, 1, false);
dmat->InitColAccess(enable, 0, 0, false); // Calling it again should not change it
@@ -118,20 +118,20 @@ TEST(SimpleDMatrix, ColAccessWithBatches) {
col_iter->BeforeFirst();
while (col_iter->Next()) {
num_col_batch += 1;
EXPECT_EQ(col_iter->Value().size, dmat->info().num_col)
EXPECT_EQ(col_iter->Value().size, dmat->Info().num_col_)
<< "Expected batch size = num_cols as max_row_perbatch is 1.";
for (int i = 0; i < static_cast<int>(col_iter->Value().size); ++i) {
EXPECT_LE(col_iter->Value()[i].length, 1)
<< "Expected length of each colbatch <=1 as max_row_perbatch is 1.";
}
}
EXPECT_EQ(num_col_batch, dmat->info().num_row)
EXPECT_EQ(num_col_batch, dmat->Info().num_row_)
<< "Expected num batches = num_rows as max_row_perbatch is 1";
col_iter = nullptr;
// The iterator feats should ignore any numbers larger than the num_col
std::vector<xgboost::bst_uint> sub_feats = {
4, 3, static_cast<unsigned int>(dmat->info().num_col + 1)};
4, 3, static_cast<unsigned int>(dmat->Info().num_col_ + 1)};
dmlc::DataIter<xgboost::ColBatch> * sub_col_iter = dmat->ColIterator(sub_feats);
// Loop over the batches and assert the data is as expected
sub_col_iter->BeforeFirst();

View File

@@ -12,10 +12,10 @@ TEST(SparsePageDMatrix, MetaInfo) {
EXPECT_TRUE(FileExists(tmp_file + ".cache"));
// Test the metadata that was parsed
EXPECT_EQ(dmat->info().num_row, 2);
EXPECT_EQ(dmat->info().num_col, 5);
EXPECT_EQ(dmat->info().num_nonzero, 6);
EXPECT_EQ(dmat->info().labels.size(), dmat->info().num_row);
EXPECT_EQ(dmat->Info().num_row_, 2);
EXPECT_EQ(dmat->Info().num_col_, 5);
EXPECT_EQ(dmat->Info().num_nonzero_, 6);
EXPECT_EQ(dmat->Info().labels_.size(), dmat->Info().num_row_);
// Clean up of external memory files
std::remove((tmp_file + ".cache").c_str());
@@ -34,7 +34,7 @@ TEST(SparsePageDMatrix, RowAccess) {
long row_count = 0;
row_iter->BeforeFirst();
while (row_iter->Next()) row_count += row_iter->Value().size;
EXPECT_EQ(row_count, dmat->info().num_row);
EXPECT_EQ(row_count, dmat->Info().num_row_);
// Test the data read into the first row
row_iter->BeforeFirst();
row_iter->Next();
@@ -57,7 +57,7 @@ TEST(SparsePageDMatrix, ColAcess) {
EXPECT_FALSE(FileExists(tmp_file + ".cache.col.page"));
EXPECT_EQ(dmat->HaveColAccess(true), false);
const std::vector<bool> enable(dmat->info().num_col, true);
const std::vector<bool> enable(dmat->Info().num_col_, true);
dmat->InitColAccess(enable, 1, 1, true); // Max 1 row per patch
ASSERT_EQ(dmat->HaveColAccess(true), true);
EXPECT_TRUE(FileExists(tmp_file + ".cache.col.page"));
@@ -73,10 +73,10 @@ TEST(SparsePageDMatrix, ColAcess) {
col_iter->BeforeFirst();
while (col_iter->Next()) {
num_col_batch += 1;
EXPECT_EQ(col_iter->Value().size, dmat->info().num_col)
EXPECT_EQ(col_iter->Value().size, dmat->Info().num_col_)
<< "Expected batch size to be same as num_cols as max_row_perbatch is 1.";
}
EXPECT_EQ(num_col_batch, dmat->info().num_row)
EXPECT_EQ(num_col_batch, dmat->Info().num_row_)
<< "Expected num batches to be same as num_rows as max_row_perbatch is 1";
col_iter = nullptr;