Add travis sanitizers tests. (#3557)
* Add travis sanitizers tests. * Add gcc-7 in Travis. * Add SANITIZER_PATH for CMake. * Enable sanitizer tests in Travis. * Fix memory leaks in tests. * Fix all memory leaks reported by Address Sanitizer. * tests/cpp/helpers.h/CreateDMatrix now returns raw pointer.
This commit is contained in:
committed by
Rory Mitchell
parent
983cb0b374
commit
cf2d86a4f6
@@ -25,14 +25,14 @@ TEST(cpu_predictor, Test) {
|
||||
|
||||
// Test predict batch
|
||||
HostDeviceVector<float> out_predictions;
|
||||
cpu_predictor->PredictBatch(dmat.get(), &out_predictions, model, 0);
|
||||
cpu_predictor->PredictBatch((*dmat).get(), &out_predictions, model, 0);
|
||||
std::vector<float>& out_predictions_h = out_predictions.HostVector();
|
||||
for (int i = 0; i < out_predictions.Size(); i++) {
|
||||
ASSERT_EQ(out_predictions_h[i], 1.5);
|
||||
}
|
||||
|
||||
// Test predict instance
|
||||
auto batch = dmat->RowIterator()->Value();
|
||||
auto batch = (*dmat)->RowIterator()->Value();
|
||||
for (int i = 0; i < batch.Size(); i++) {
|
||||
std::vector<float> instance_out_predictions;
|
||||
cpu_predictor->PredictInstance(batch[i], &instance_out_predictions, model);
|
||||
@@ -41,22 +41,24 @@ TEST(cpu_predictor, Test) {
|
||||
|
||||
// Test predict leaf
|
||||
std::vector<float> leaf_out_predictions;
|
||||
cpu_predictor->PredictLeaf(dmat.get(), &leaf_out_predictions, model);
|
||||
cpu_predictor->PredictLeaf((*dmat).get(), &leaf_out_predictions, model);
|
||||
for (int i = 0; i < leaf_out_predictions.size(); i++) {
|
||||
ASSERT_EQ(leaf_out_predictions[i], 0);
|
||||
}
|
||||
|
||||
// Test predict contribution
|
||||
std::vector<float> out_contribution;
|
||||
cpu_predictor->PredictContribution(dmat.get(), &out_contribution, model);
|
||||
cpu_predictor->PredictContribution((*dmat).get(), &out_contribution, model);
|
||||
for (int i = 0; i < out_contribution.size(); i++) {
|
||||
ASSERT_EQ(out_contribution[i], 1.5);
|
||||
}
|
||||
|
||||
// Test predict contribution (approximate method)
|
||||
cpu_predictor->PredictContribution(dmat.get(), &out_contribution, model, true);
|
||||
cpu_predictor->PredictContribution((*dmat).get(), &out_contribution, model, true);
|
||||
for (int i = 0; i < out_contribution.size(); i++) {
|
||||
ASSERT_EQ(out_contribution[i], 1.5);
|
||||
}
|
||||
|
||||
delete dmat;
|
||||
}
|
||||
} // namespace xgboost
|
||||
|
||||
@@ -35,8 +35,8 @@ TEST(gpu_predictor, Test) {
|
||||
// Test predict batch
|
||||
HostDeviceVector<float> gpu_out_predictions;
|
||||
HostDeviceVector<float> cpu_out_predictions;
|
||||
gpu_predictor->PredictBatch(dmat.get(), &gpu_out_predictions, model, 0);
|
||||
cpu_predictor->PredictBatch(dmat.get(), &cpu_out_predictions, model, 0);
|
||||
gpu_predictor->PredictBatch((*dmat).get(), &gpu_out_predictions, model, 0);
|
||||
cpu_predictor->PredictBatch((*dmat).get(), &cpu_out_predictions, model, 0);
|
||||
std::vector<float>& gpu_out_predictions_h = gpu_out_predictions.HostVector();
|
||||
std::vector<float>& cpu_out_predictions_h = cpu_out_predictions.HostVector();
|
||||
float abs_tolerance = 0.001;
|
||||
@@ -45,7 +45,7 @@ TEST(gpu_predictor, Test) {
|
||||
abs_tolerance);
|
||||
}
|
||||
// Test predict instance
|
||||
auto batch = dmat->RowIterator()->Value();
|
||||
auto batch = (*dmat)->RowIterator()->Value();
|
||||
for (int i = 0; i < batch.Size(); i++) {
|
||||
std::vector<float> gpu_instance_out_predictions;
|
||||
std::vector<float> cpu_instance_out_predictions;
|
||||
@@ -59,8 +59,8 @@ TEST(gpu_predictor, Test) {
|
||||
// Test predict leaf
|
||||
std::vector<float> gpu_leaf_out_predictions;
|
||||
std::vector<float> cpu_leaf_out_predictions;
|
||||
cpu_predictor->PredictLeaf(dmat.get(), &cpu_leaf_out_predictions, model);
|
||||
gpu_predictor->PredictLeaf(dmat.get(), &gpu_leaf_out_predictions, model);
|
||||
cpu_predictor->PredictLeaf((*dmat).get(), &cpu_leaf_out_predictions, model);
|
||||
gpu_predictor->PredictLeaf((*dmat).get(), &gpu_leaf_out_predictions, model);
|
||||
for (int i = 0; i < gpu_leaf_out_predictions.size(); i++) {
|
||||
ASSERT_EQ(gpu_leaf_out_predictions[i], cpu_leaf_out_predictions[i]);
|
||||
}
|
||||
@@ -68,11 +68,13 @@ TEST(gpu_predictor, Test) {
|
||||
// Test predict contribution
|
||||
std::vector<float> gpu_out_contribution;
|
||||
std::vector<float> cpu_out_contribution;
|
||||
cpu_predictor->PredictContribution(dmat.get(), &cpu_out_contribution, model);
|
||||
gpu_predictor->PredictContribution(dmat.get(), &gpu_out_contribution, model);
|
||||
cpu_predictor->PredictContribution((*dmat).get(), &cpu_out_contribution, model);
|
||||
gpu_predictor->PredictContribution((*dmat).get(), &gpu_out_contribution, model);
|
||||
for (int i = 0; i < gpu_out_contribution.size(); i++) {
|
||||
ASSERT_EQ(gpu_out_contribution[i], cpu_out_contribution[i]);
|
||||
}
|
||||
|
||||
delete dmat;
|
||||
}
|
||||
} // namespace predictor
|
||||
} // namespace xgboost
|
||||
|
||||
Reference in New Issue
Block a user