class Xgboost < Formula desc "Scalable, Portable and Distributed Gradient Boosting Library" homepage "https://xgboost.ai/" url "https://github.com/dmlc/xgboost/releases/download/v3.1.2/xgboost-src-3.1.2.tar.gz" sha256 "12f2d6f735fa71e007c40171fd926c12306276dd299dc48f6c923e4f3891c33e" license "Apache-2.0" livecheck do url :stable strategy :github_latest end bottle do sha256 cellar: :any, arm64_tahoe: "69a8d50686d1e7a9a1891cce69e0dfae6a481c19750c24405b069d8fbda93df3" sha256 cellar: :any, arm64_sequoia: "41ca8720cb5d93af050049cc686050f3c3923e9f157ad8c89f2213af3c4aec04" sha256 cellar: :any, arm64_sonoma: "19e16791812ee2a3bdd303d8bdf4141d4d8f93750948873e69209c12c0730969" sha256 cellar: :any, sonoma: "44f257577c7abf343a002edb4294793ae46e19cd4675da7feeecf4415d35ee20" sha256 cellar: :any_skip_relocation, arm64_linux: "5a2f627e7df7fddb9e6dc1480b9a664954c11405c060f8887766b786ee278772" sha256 cellar: :any_skip_relocation, x86_64_linux: "8d37e6667cdac436dd23aea5d57548fc8c24566fc503942cc2c27b2721fc5101" end depends_on "cmake" => :build on_macos do depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1100 depends_on "libomp" end fails_with :clang do build 1100 cause <<~EOS clang: error: unable to execute command: Segmentation fault: 11 clang: error: clang frontend command failed due to signal (use -v to see invocation) make[2]: *** [src/CMakeFiles/objxgboost.dir/tree/updater_quantile_hist.cc.o] Error 254 EOS end def install ENV.llvm_clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1100) system "cmake", "-S", ".", "-B", "build", *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" pkgshare.install "demo" end test do cp_r (pkgshare/"demo"), testpath (testpath/"test.cpp").write <<~CPP #include #include int main() { std::string train_data = "#{testpath}/demo/data/agaricus.txt.train?format=libsvm"; DMatrixHandle dtrain; if (XGDMatrixCreateFromFile(train_data.c_str(), 0, &dtrain) != 0) { std::cerr << "Failed to load training data: " << train_data << std::endl; std::cerr << "Last error message: " << XGBGetLastError() << std::endl; return 1; } // Create booster and set parameters BoosterHandle booster; if (XGBoosterCreate(&dtrain, 1, &booster) != 0) { std::cerr << "Failed to create booster" << std::endl; return 1; } if (XGBoosterSetParam(booster, "max_depth", "2") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } if (XGBoosterSetParam(booster, "eta", "1") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } if (XGBoosterSetParam(booster, "objective", "binary:logistic") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } // Train the model for (int iter = 0; iter < 10; ++iter) { if (XGBoosterUpdateOneIter(booster, iter, dtrain) != 0) { std::cerr << "Failed to update booster" << std::endl; return 1; } } // Free resources XGBoosterFree(booster); XGDMatrixFree(dtrain); std::cout << "Test completed successfully" << std::endl; return 0; } CPP system ENV.cxx, "test.cpp", "-I#{include}", "-L#{lib}", "-lxgboost", "-o", "test" system "./test" end end