| 99 | } |
| 100 | |
| 101 | void CheckObjFunctionImpl(std::unique_ptr<xgboost::ObjFunction> const& obj, |
| 102 | std::vector<xgboost::bst_float> preds, |
| 103 | std::vector<xgboost::bst_float> labels, |
| 104 | std::vector<xgboost::bst_float> weights, xgboost::MetaInfo const& info, |
| 105 | std::vector<xgboost::bst_float> out_grad, |
| 106 | std::vector<xgboost::bst_float> out_hess) { |
| 107 | xgboost::HostDeviceVector<xgboost::bst_float> in_preds(preds); |
| 108 | xgboost::linalg::Matrix<xgboost::GradientPair> out_gpair; |
| 109 | obj->GetGradient(in_preds, info, 0, &out_gpair); |
| 110 | std::vector<xgboost::GradientPair>& gpair = out_gpair.Data()->HostVector(); |
| 111 | |
| 112 | ASSERT_EQ(gpair.size(), in_preds.Size()); |
| 113 | for (int i = 0; i < static_cast<int>(gpair.size()); ++i) { |
| 114 | EXPECT_NEAR(gpair[i].GetGrad(), out_grad[i], 0.01) |
| 115 | << "Unexpected grad for pred=" << preds[i] << " label=" << labels[i] |
| 116 | << " weight=" << (weights.empty() ? 1.0 : weights[i]); |
| 117 | EXPECT_NEAR(gpair[i].GetHess(), out_hess[i], 0.01) |
| 118 | << "Unexpected hess for pred=" << preds[i] << " label=" << labels[i] |
| 119 | << " weight=" << (weights.empty() ? 1.0 : weights[i]); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void CheckObjFunction(std::unique_ptr<xgboost::ObjFunction> const& obj, |
| 124 | std::vector<xgboost::bst_float> preds, std::vector<xgboost::bst_float> labels, |