From 6fa5dc8f060e4a2de1171d7e09a3b8b38fda2f05 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 21 Jun 2024 10:26:35 -0500 Subject: [PATCH 1/5] [ci] [docs] fix link-checks job (#6495) --- .github/workflows/linkchecker.yml | 1 + docs/FAQ.rst | 4 ++-- docs/GPU-Windows.rst | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linkchecker.yml b/.github/workflows/linkchecker.yml index 5055d5ca9399..42391bb31da0 100644 --- a/.github/workflows/linkchecker.yml +++ b/.github/workflows/linkchecker.yml @@ -8,6 +8,7 @@ on: - cron: '0 8 * * *' env: + COMPILER: gcc OS_NAME: 'linux' PYTHON_VERSION: '3.12' TASK: 'check-links' diff --git a/docs/FAQ.rst b/docs/FAQ.rst index 8f0024b45730..43141480cff5 100644 --- a/docs/FAQ.rst +++ b/docs/FAQ.rst @@ -149,7 +149,7 @@ and copy memory as required by creating new processes instead of forking (or, us Cloud platform container services may cause LightGBM to hang, if they use Linux fork to run multiple containers on a single instance. For example, LightGBM hangs in AWS Batch array jobs, which `use the ECS agent -`__ to manage multiple running jobs. Setting ``nthreads=1`` mitigates the issue. +`__ to manage multiple running jobs. Setting ``nthreads=1`` mitigates the issue. 12. Why is early stopping not enabled by default in LightGBM? ------------------------------------------------------------- @@ -321,7 +321,7 @@ We are doing our best to provide universal wheels which have high running speed However, sometimes it's just impossible to guarantee the possibility of usage of LightGBM in any specific environment (see `Microsoft/LightGBM#1743 `__). Therefore, the first thing you should try in case of segfaults is **compiling from the source** using ``pip install --no-binary lightgbm lightgbm``. -For the OS-specific prerequisites see `this guide `__. +For the OS-specific prerequisites see https://github.com/microsoft/LightGBM/blob/master/python-package/README.rst. Also, feel free to post a new issue in our GitHub repository. We always look at each case individually and try to find a root cause. diff --git a/docs/GPU-Windows.rst b/docs/GPU-Windows.rst index c4c2ca818433..8536f49d6731 100644 --- a/docs/GPU-Windows.rst +++ b/docs/GPU-Windows.rst @@ -602,9 +602,9 @@ And open an issue in GitHub `here`_ with that log. .. _Boost: https://www.boost.org/users/history/ -.. _Prebuilt Boost x86_64: https://www.rpmfind.net/linux/fedora/linux/releases/38/Everything/x86_64/os/Packages/m/mingw64-boost-static-1.78.0-4.fc38.noarch.rpm +.. _Prebuilt Boost x86_64: https://www.rpmfind.net/linux/fedora/linux/releases/40/Everything/x86_64/os/Packages/m/mingw64-boost-static-1.78.0-9.fc40.noarch.rpm -.. _Prebuilt Boost i686: https://www.rpmfind.net/linux/fedora/linux/releases/38/Everything/x86_64/os/Packages/m/mingw32-boost-static-1.78.0-4.fc38.noarch.rpm +.. _Prebuilt Boost i686: https://www.rpmfind.net/linux/fedora/linux/releases/40/Everything/x86_64/os/Packages/m/mingw32-boost-static-1.78.0-9.fc40.noarch.rpm .. _7zip: https://www.7-zip.org/download.html From c4e70f3ce1005eeb084e571020a5941f977b87f7 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 21 Jun 2024 10:27:16 -0500 Subject: [PATCH 2/5] [ci] remove OpenMP / MKL workaround in CI jobs (#6496) --- .ci/test.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.ci/test.sh b/.ci/test.sh index d950f01e989f..b73d7ea64189 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -163,11 +163,6 @@ source activate $CONDA_ENV cd $BUILD_DIRECTORY -if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then - # fix "OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized." (OpenMP library conflict due to conda's MKL) - for LIBOMP_ALIAS in libgomp.dylib libiomp5.dylib libomp.dylib; do sudo ln -sf "$(brew --cellar libomp)"/*/lib/libomp.dylib $CONDA_PREFIX/lib/$LIBOMP_ALIAS || exit 1; done -fi - if [[ $TASK == "sdist" ]]; then cd $BUILD_DIRECTORY && sh ./build-python.sh sdist || exit 1 sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 From fd8f79944955cf83fcefb9ed598b9e0bcd07ad09 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 21 Jun 2024 10:28:47 -0500 Subject: [PATCH 3/5] [docs] [R-package] update cran-comments.md (#6499) --- R-package/cran-comments.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R-package/cran-comments.md b/R-package/cran-comments.md index 137df4912c04..32916a0c827e 100644 --- a/R-package/cran-comments.md +++ b/R-package/cran-comments.md @@ -1,11 +1,15 @@ # CRAN Submission History -## v4.4.0 - Submission 1 - (TBD) +## v4.4.0 - Submission 1 - (June 14, 2024) ### CRAN response +Accepted to CRAN + ### Maintainer Notes +This was a standard release of `{lightgbm}`, not intended to fix any particular R-specific issues. + ## v4.3.0 - Submission 1 - (January 18, 2024) ### CRAN response From bf2641d8cb37abf9db6eba760b3d11f3fb43c873 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 21 Jun 2024 12:16:41 -0500 Subject: [PATCH 4/5] [ci] reduce repetition of BUILD_DIRECTORY in CI scripts (#6497) --- .ci/test.sh | 145 ++++++++++++++++++++++-------------------- .ci/test_r_package.sh | 4 +- .ci/test_windows.ps1 | 25 ++++---- 3 files changed, 88 insertions(+), 86 deletions(-) diff --git a/.ci/test.sh b/.ci/test.sh index b73d7ea64189..6e862ba0248f 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -11,7 +11,7 @@ SANITIZERS=${SANITIZERS:-""} ARCH=$(uname -m) -LGB_VER=$(head -n 1 ${BUILD_DIRECTORY}/VERSION.txt) +LGB_VER=$(head -n 1 "${BUILD_DIRECTORY}/VERSION.txt") if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "gcc" ]]; then export CXX=g++-11 @@ -43,7 +43,7 @@ else fi if [[ "${TASK}" == "r-package" ]] || [[ "${TASK}" == "r-rchk" ]]; then - bash ${BUILD_DIRECTORY}/.ci/test_r_package.sh || exit 1 + bash "${BUILD_DIRECTORY}/.ci/test_r_package.sh" || exit 1 exit 0 fi @@ -70,27 +70,31 @@ if [[ $TASK == "if-else" ]]; then source activate $CONDA_ENV cmake -B build -S . || exit 1 cmake --build build --target lightgbm -j4 || exit 1 - cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit 1 - cd $BUILD_DIRECTORY/tests/cpp_tests && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit 1 + cd "$BUILD_DIRECTORY/tests/cpp_tests" + ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp + ../../lightgbm config=predict.conf output_result=origin.pred + ../../lightgbm config=predict.conf output_result=ifelse.pred + python test.py exit 0 fi +cd "${BUILD_DIRECTORY}" + if [[ $TASK == "swig" ]]; then cmake -B build -S . -DUSE_SWIG=ON cmake --build build -j4 || exit 1 if [[ $OS_NAME == "linux" ]] && [[ $COMPILER == "gcc" ]]; then - objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit 1 - objdump -T $BUILD_DIRECTORY/lib_lightgbm_swig.so >> $BUILD_DIRECTORY/objdump.log || exit 1 - python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit 1 + objdump -T ./lib_lightgbm.so > ./objdump.log || exit 1 + objdump -T ./lib_lightgbm_swig.so >> ./objdump.log || exit 1 + python ./helpers/check_dynamic_dependencies.py ./objdump.log || exit 1 fi if [[ $PRODUCES_ARTIFACTS == "true" ]]; then - cp $BUILD_DIRECTORY/build/lightgbmlib.jar $BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_$OS_NAME.jar + cp ./build/lightgbmlib.jar $BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_$OS_NAME.jar fi exit 0 fi if [[ $TASK == "lint" ]]; then - cd ${BUILD_DIRECTORY} mamba create -q -y -n $CONDA_ENV \ ${CONDA_PYTHON_REQUIREMENT} \ 'cmakelint>=1.4.2' \ @@ -102,16 +106,16 @@ if [[ $TASK == "lint" ]]; then 'r-lintr>=3.1.2' source activate $CONDA_ENV echo "Linting Python code" - bash ${BUILD_DIRECTORY}/.ci/lint-python.sh || exit 1 + bash ./.ci/lint-python.sh || exit 1 echo "Linting R code" - Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit 1 + Rscript ./.ci/lint_r_code.R "${BUILD_DIRECTORY}" || exit 1 echo "Linting C++ code" - bash ${BUILD_DIRECTORY}/.ci/lint-cpp.sh || exit 1 + bash ./.ci/lint-cpp.sh || exit 1 exit 0 fi if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then - cd $BUILD_DIRECTORY/docs + cd "${BUILD_DIRECTORY}/docs" mamba env create \ -n $CONDA_ENV \ --file ./env.yml || exit 1 @@ -123,9 +127,9 @@ if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then 'rstcheck>=6.2.0' || exit 1 source activate $CONDA_ENV # check reStructuredText formatting - cd $BUILD_DIRECTORY/python-package + cd "${BUILD_DIRECTORY}/python-package" rstcheck --report-level warning $(find . -type f -name "*.rst") || exit 1 - cd $BUILD_DIRECTORY/docs + cd "${BUILD_DIRECTORY}/docs" rstcheck --report-level warning --ignore-directives=autoclass,autofunction,autosummary,doxygenfile $(find . -type f -name "*.rst") || exit 1 # build docs make html || exit 1 @@ -136,11 +140,12 @@ if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then exit 0 fi # check the consistency of parameters' descriptions and other stuff - cp $BUILD_DIRECTORY/docs/Parameters.rst $BUILD_DIRECTORY/docs/Parameters-backup.rst - cp $BUILD_DIRECTORY/src/io/config_auto.cpp $BUILD_DIRECTORY/src/io/config_auto-backup.cpp - python $BUILD_DIRECTORY/helpers/parameter_generator.py || exit 1 - diff $BUILD_DIRECTORY/docs/Parameters-backup.rst $BUILD_DIRECTORY/docs/Parameters.rst || exit 1 - diff $BUILD_DIRECTORY/src/io/config_auto-backup.cpp $BUILD_DIRECTORY/src/io/config_auto.cpp || exit 1 + cd "${BUILD_DIRECTORY}" + cp ./docs/Parameters.rst ./docs/Parameters-backup.rst + cp ./src/io/config_auto.cpp ./src/io/config_auto-backup.cpp + python ./helpers/parameter_generator.py || exit 1 + diff ./docs/Parameters-backup.rst ./docs/Parameters.rst || exit 1 + diff ./src/io/config_auto-backup.cpp ./src/io/config_auto.cpp || exit 1 exit 0 fi @@ -161,21 +166,21 @@ mamba create \ source activate $CONDA_ENV -cd $BUILD_DIRECTORY +cd "${BUILD_DIRECTORY}" if [[ $TASK == "sdist" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh sdist || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 - pip install $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER.tar.gz -v || exit 1 + sh ./build-python.sh sdist || exit 1 + sh .ci/check_python_dists.sh ./dist || exit 1 + pip install ./dist/lightgbm-$LGB_VER.tar.gz -v || exit 1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then - cp $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER.tar.gz $BUILD_ARTIFACTSTAGINGDIRECTORY || exit 1 + cp ./dist/lightgbm-$LGB_VER.tar.gz $BUILD_ARTIFACTSTAGINGDIRECTORY || exit 1 fi - pytest $BUILD_DIRECTORY/tests/python_package_test || exit 1 + pytest ./tests/python_package_test || exit 1 exit 0 elif [[ $TASK == "bdist" ]]; then if [[ $OS_NAME == "macos" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh bdist_wheel || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 + sh ./build-python.sh bdist_wheel || exit 1 + sh .ci/check_python_dists.sh ./dist || exit 1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp dist/lightgbm-$LGB_VER-py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY || exit 1 fi @@ -185,88 +190,88 @@ elif [[ $TASK == "bdist" ]]; then else PLATFORM="manylinux2014_$ARCH" fi - cd $BUILD_DIRECTORY && sh ./build-python.sh bdist_wheel --integrated-opencl || exit 1 + sh ./build-python.sh bdist_wheel --integrated-opencl || exit 1 mv \ ./dist/*.whl \ ./dist/tmp.whl || exit 1 mv \ ./dist/tmp.whl \ ./dist/lightgbm-$LGB_VER-py3-none-$PLATFORM.whl || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 + sh .ci/check_python_dists.sh ./dist || exit 1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp dist/lightgbm-$LGB_VER-py3-none-$PLATFORM.whl $BUILD_ARTIFACTSTAGINGDIRECTORY || exit 1 fi # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py export LIGHTGBM_TEST_DUAL_CPU_GPU=1 fi - pip install -v $BUILD_DIRECTORY/dist/*.whl || exit 1 - pytest $BUILD_DIRECTORY/tests || exit 1 + pip install -v ./dist/*.whl || exit 1 + pytest ./tests || exit 1 exit 0 fi if [[ $TASK == "gpu" ]]; then - sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' $BUILD_DIRECTORY/include/LightGBM/config.h - grep -q 'std::string device_type = "gpu"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit 1 # make sure that changes were really done + sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' ./include/LightGBM/config.h + grep -q 'std::string device_type = "gpu"' ./include/LightGBM/config.h || exit 1 # make sure that changes were really done if [[ $METHOD == "pip" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh sdist || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 + sh ./build-python.sh sdist || exit 1 + sh .ci/check_python_dists.sh ./dist || exit 1 pip install \ -v \ --config-settings=cmake.define.USE_GPU=ON \ - $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER.tar.gz \ + ./dist/lightgbm-$LGB_VER.tar.gz \ || exit 1 - pytest $BUILD_DIRECTORY/tests/python_package_test || exit 1 + pytest ./tests/python_package_test || exit 1 exit 0 elif [[ $METHOD == "wheel" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh bdist_wheel --gpu || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 - pip install $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER*.whl -v || exit 1 - pytest $BUILD_DIRECTORY/tests || exit 1 + sh ./build-python.sh bdist_wheel --gpu || exit 1 + sh ./.ci/check_python_dists.sh ./dist || exit 1 + pip install ./dist/lightgbm-$LGB_VER*.whl -v || exit 1 + pytest ./tests || exit 1 exit 0 elif [[ $METHOD == "source" ]]; then cmake -B build -S . -DUSE_GPU=ON fi elif [[ $TASK == "cuda" ]]; then - sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' $BUILD_DIRECTORY/include/LightGBM/config.h - grep -q 'std::string device_type = "cuda"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit 1 # make sure that changes were really done + sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' ./include/LightGBM/config.h + grep -q 'std::string device_type = "cuda"' ./include/LightGBM/config.h || exit 1 # make sure that changes were really done # by default ``gpu_use_dp=false`` for efficiency. change to ``true`` here for exact results in ci tests - sed -i'.bak' 's/gpu_use_dp = false;/gpu_use_dp = true;/' $BUILD_DIRECTORY/include/LightGBM/config.h - grep -q 'gpu_use_dp = true' $BUILD_DIRECTORY/include/LightGBM/config.h || exit 1 # make sure that changes were really done + sed -i'.bak' 's/gpu_use_dp = false;/gpu_use_dp = true;/' ./include/LightGBM/config.h + grep -q 'gpu_use_dp = true' ./include/LightGBM/config.h || exit 1 # make sure that changes were really done if [[ $METHOD == "pip" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh sdist || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 + sh ./build-python.sh sdist || exit 1 + sh ./.ci/check_python_dists.sh ./dist || exit 1 pip install \ -v \ --config-settings=cmake.define.USE_CUDA=ON \ - $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER.tar.gz \ + ./dist/lightgbm-$LGB_VER.tar.gz \ || exit 1 - pytest $BUILD_DIRECTORY/tests/python_package_test || exit 1 + pytest ./tests/python_package_test || exit 1 exit 0 elif [[ $METHOD == "wheel" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh bdist_wheel --cuda || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 - pip install $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER*.whl -v || exit 1 - pytest $BUILD_DIRECTORY/tests || exit 1 + sh ./build-python.sh bdist_wheel --cuda || exit 1 + sh ./.ci/check_python_dists.sh ./dist || exit 1 + pip install ./dist/lightgbm-$LGB_VER*.whl -v || exit 1 + pytest ./tests || exit 1 exit 0 elif [[ $METHOD == "source" ]]; then cmake -B build -S . -DUSE_CUDA=ON fi elif [[ $TASK == "mpi" ]]; then if [[ $METHOD == "pip" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh sdist || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 + sh ./build-python.sh sdist || exit 1 + sh ./.ci/check_python_dists.sh ./dist || exit 1 pip install \ -v \ --config-settings=cmake.define.USE_MPI=ON \ - $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER.tar.gz \ + ./dist/lightgbm-$LGB_VER.tar.gz \ || exit 1 - pytest $BUILD_DIRECTORY/tests/python_package_test || exit 1 + pytest ./tests/python_package_test || exit 1 exit 0 elif [[ $METHOD == "wheel" ]]; then - cd $BUILD_DIRECTORY && sh ./build-python.sh bdist_wheel --mpi || exit 1 - sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/dist || exit 1 - pip install $BUILD_DIRECTORY/dist/lightgbm-$LGB_VER*.whl -v || exit 1 - pytest $BUILD_DIRECTORY/tests || exit 1 + sh ./build-python.sh bdist_wheel --mpi || exit 1 + sh ./.ci/check_python_dists.sh ./dist || exit 1 + pip install ./dist/lightgbm-$LGB_VER*.whl -v || exit 1 + pytest ./tests || exit 1 exit 0 elif [[ $METHOD == "source" ]]; then cmake -B build -S . -DUSE_MPI=ON -DUSE_DEBUG=ON @@ -277,22 +282,22 @@ fi cmake --build build --target _lightgbm -j4 || exit 1 -cd $BUILD_DIRECTORY && sh ./build-python.sh install --precompile || exit 1 -pytest $BUILD_DIRECTORY/tests || exit 1 +sh ./build-python.sh install --precompile || exit 1 +pytest ./tests || exit 1 if [[ $TASK == "regular" ]]; then if [[ $PRODUCES_ARTIFACTS == "true" ]]; then if [[ $OS_NAME == "macos" ]]; then - cp $BUILD_DIRECTORY/lib_lightgbm.dylib $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.dylib + cp ./lib_lightgbm.dylib $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.dylib else if [[ $COMPILER == "gcc" ]]; then - objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit 1 - python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit 1 + objdump -T ./lib_lightgbm.so > ./objdump.log || exit 1 + python ./helpers/check_dynamic_dependencies.py ./objdump.log || exit 1 fi - cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.so + cp ./lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.so fi fi - cd $BUILD_DIRECTORY/examples/python-guide + cd "$BUILD_DIRECTORY/examples/python-guide" sed -i'.bak' '/import lightgbm as lgb/a\ import matplotlib\ matplotlib.use\(\"Agg\"\)\ @@ -304,7 +309,7 @@ matplotlib.use\(\"Agg\"\)\ 'ipywidgets>=8.1.2' \ 'notebook>=7.1.2' for f in *.py **/*.py; do python $f || exit 1; done # run all examples - cd $BUILD_DIRECTORY/examples/python-guide/notebooks + cd "$BUILD_DIRECTORY/examples/python-guide/notebooks" sed -i'.bak' 's/INTERACTIVE = False/assert False, \\"Interactive mode disabled\\"/' interactive_plot_example.ipynb jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb || exit 1 # run all notebooks diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index 0ed581b9bf75..6c4ac4b73833 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -136,7 +136,7 @@ if [[ $OS_NAME == "macos" ]]; then fi Rscript --vanilla -e "options(install.packages.compile.from.source = '${compile_from_source}'); install.packages(${packages}, repos = '${CRAN_MIRROR}', lib = '${R_LIB_PATH}', dependencies = c('Depends', 'Imports', 'LinkingTo'), Ncpus = parallel::detectCores())" || exit 1 -cd ${BUILD_DIRECTORY} +cd "${BUILD_DIRECTORY}" PKG_TARBALL="lightgbm_*.tar.gz" LOG_FILE_NAME="lightgbm.Rcheck/00check.log" @@ -147,7 +147,7 @@ elif [[ $R_BUILD_TYPE == "cran" ]]; then # on Linux, we recreate configure in CI to test if # a change in a PR has changed configure.ac if [[ $OS_NAME == "linux" ]]; then - ${BUILD_DIRECTORY}/R-package/recreate-configure.sh + ./R-package/recreate-configure.sh num_files_changed=$( git diff --name-only | wc -l diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 8ee20a245b38..3a130e1af6da 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -10,7 +10,7 @@ $env:CONDA_ENV = "test-env" $env:LGB_VER = (Get-Content $env:BUILD_SOURCESDIRECTORY\VERSION.txt).trim() if ($env:TASK -eq "r-package") { - & $env:BUILD_SOURCESDIRECTORY\.ci\test_r_package_windows.ps1 ; Check-Output $? + & .\.ci\test_r_package_windows.ps1 ; Check-Output $? Exit 0 } @@ -31,7 +31,7 @@ if ($env:TASK -eq "swig") { cmake -B build -S . -A x64 -DUSE_SWIG=ON ; Check-Output $? cmake --build build --target ALL_BUILD --config Release ; Check-Output $? if ($env:AZURE -eq "true") { - cp $env:BUILD_SOURCESDIRECTORY/build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar ; Check-Output $? + cp ./build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar ; Check-Output $? } Exit 0 } @@ -60,18 +60,17 @@ if ($env:TASK -ne "bdist") { conda activate $env:CONDA_ENV } +cd $env:BUILD_SOURCESDIRECTORY if ($env:TASK -eq "regular") { cmake -B build -S . -A x64 ; Check-Output $? cmake --build build --target ALL_BUILD --config Release ; Check-Output $? - cd $env:BUILD_SOURCESDIRECTORY - sh $env:BUILD_SOURCESDIRECTORY/build-python.sh install --precompile ; Check-Output $? - cp $env:BUILD_SOURCESDIRECTORY/Release/lib_lightgbm.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY - cp $env:BUILD_SOURCESDIRECTORY/Release/lightgbm.exe $env:BUILD_ARTIFACTSTAGINGDIRECTORY + sh ./build-python.sh install --precompile ; Check-Output $? + cp ./Release/lib_lightgbm.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY + cp ./Release/lightgbm.exe $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif ($env:TASK -eq "sdist") { - cd $env:BUILD_SOURCESDIRECTORY - sh $env:BUILD_SOURCESDIRECTORY/build-python.sh sdist ; Check-Output $? - sh $env:BUILD_SOURCESDIRECTORY/.ci/check_python_dists.sh $env:BUILD_SOURCESDIRECTORY/dist ; Check-Output $? + sh ./build-python.sh sdist ; Check-Output $? + sh ./.ci/check_python_dists.sh ./dist ; Check-Output $? cd dist; pip install @(Get-ChildItem *.gz) -v ; Check-Output $? } elseif ($env:TASK -eq "bdist") { @@ -85,17 +84,15 @@ elseif ($env:TASK -eq "bdist") { Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors conda activate $env:CONDA_ENV - cd $env:BUILD_SOURCESDIRECTORY sh "build-python.sh" bdist_wheel --integrated-opencl ; Check-Output $? - sh $env:BUILD_SOURCESDIRECTORY/.ci/check_python_dists.sh $env:BUILD_SOURCESDIRECTORY/dist ; Check-Output $? + sh ./.ci/check_python_dists.sh ./dist ; Check-Output $? cd dist; pip install @(Get-ChildItem *py3-none-win_amd64.whl) ; Check-Output $? cp @(Get-ChildItem *py3-none-win_amd64.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { - cd $env:BUILD_SOURCESDIRECTORY if ($env:COMPILER -eq "MINGW") { - sh $env:BUILD_SOURCESDIRECTORY/build-python.sh install --mingw ; Check-Output $? + sh ./build-python.sh install --mingw ; Check-Output $? } else { - sh $env:BUILD_SOURCESDIRECTORY/build-python.sh install; Check-Output $? + sh ./build-python.sh install; Check-Output $? } } From e9a6c798071632f0e9bdf4c5fa2fdf16bfd5eb36 Mon Sep 17 00:00:00 2001 From: david-cortes Date: Fri, 21 Jun 2024 20:14:28 +0200 Subject: [PATCH 5/5] [R-package] Use `Rf_`-prefixed versions of protect/unprotect (#6502) --- R-package/src/lightgbm_R.cpp | 188 +++++++++++++++++------------------ 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/R-package/src/lightgbm_R.cpp b/R-package/src/lightgbm_R.cpp index 4bef9cefe1e9..e8383c5c366e 100644 --- a/R-package/src/lightgbm_R.cpp +++ b/R-package/src/lightgbm_R.cpp @@ -53,24 +53,24 @@ void delete_cpp_char_vec(SEXP R_ptr) { #ifndef LGB_NO_ALTREP SEXP make_altrepped_raw_vec(void *void_ptr) { std::unique_ptr> *ptr_to_cpp_vec = static_cast>*>(void_ptr); - SEXP R_ptr = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); - SEXP R_raw = PROTECT(R_new_altrep(lgb_altrepped_char_vec, R_NilValue, R_NilValue)); + SEXP R_ptr = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP R_raw = Rf_protect(R_new_altrep(lgb_altrepped_char_vec, R_NilValue, R_NilValue)); R_SetExternalPtrAddr(R_ptr, ptr_to_cpp_vec->get()); R_RegisterCFinalizerEx(R_ptr, delete_cpp_char_vec, TRUE); ptr_to_cpp_vec->release(); R_set_altrep_data1(R_raw, R_ptr); - UNPROTECT(2); + Rf_unprotect(2); return R_raw; } #else SEXP make_r_raw_vec(void *void_ptr) { std::unique_ptr> *ptr_to_cpp_vec = static_cast>*>(void_ptr); R_xlen_t len = ptr_to_cpp_vec->get()->size(); - SEXP out = PROTECT(Rf_allocVector(RAWSXP, len)); + SEXP out = Rf_protect(Rf_allocVector(RAWSXP, len)); std::copy(ptr_to_cpp_vec->get()->begin(), ptr_to_cpp_vec->get()->end(), reinterpret_cast(RAW(out))); - UNPROTECT(1); + Rf_unprotect(1); return out; } #define make_altrepped_raw_vec make_r_raw_vec @@ -132,9 +132,9 @@ template SEXP make_altrepped_vec_from_arr(void *void_ptr) { T *arr = static_cast*>(void_ptr)->arr; uint64_t len = static_cast*>(void_ptr)->len; - SEXP R_ptr = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); - SEXP R_len = PROTECT(Rf_allocVector(REALSXP, 1)); - SEXP R_vec = PROTECT(R_new_altrep(get_altrep_class_for_type(), R_NilValue, R_NilValue)); + SEXP R_ptr = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP R_len = Rf_protect(Rf_allocVector(REALSXP, 1)); + SEXP R_vec = Rf_protect(R_new_altrep(get_altrep_class_for_type(), R_NilValue, R_NilValue)); REAL(R_len)[0] = static_cast(len); R_SetExternalPtrAddr(R_ptr, arr); @@ -142,7 +142,7 @@ SEXP make_altrepped_vec_from_arr(void *void_ptr) { R_set_altrep_data1(R_vec, R_ptr); R_set_altrep_data2(R_vec, R_len); - UNPROTECT(3); + Rf_unprotect(3); return R_vec; } #else @@ -150,9 +150,9 @@ template SEXP make_R_vec_from_arr(void *void_ptr) { T *arr = static_cast*>(void_ptr)->arr; uint64_t len = static_cast*>(void_ptr)->len; - SEXP out = PROTECT(Rf_allocVector(get_sexptype_class_for_type(), len)); + SEXP out = Rf_protect(Rf_allocVector(get_sexptype_class_for_type(), len)); std::copy(arr, arr + len, get_r_vec_ptr(out)); - UNPROTECT(1); + Rf_unprotect(1); return out; } #define make_altrepped_vec_from_arr make_R_vec_from_arr @@ -288,18 +288,18 @@ SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, SEXP parameters, SEXP reference) { R_API_BEGIN(); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); DatasetHandle handle = nullptr; DatasetHandle ref = nullptr; if (!Rf_isNull(reference)) { ref = R_ExternalPtrAddr(reference); } - const char* filename_ptr = CHAR(PROTECT(Rf_asChar(filename))); - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + const char* filename_ptr = CHAR(Rf_protect(Rf_asChar(filename))); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); CHECK_CALL(LGBM_DatasetCreateFromFile(filename_ptr, parameters_ptr, ref, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _DatasetFinalizer, TRUE); - UNPROTECT(3); + Rf_unprotect(3); return ret; R_API_END(); } @@ -313,14 +313,14 @@ SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, SEXP parameters, SEXP reference) { R_API_BEGIN(); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); const int* p_indptr = INTEGER(indptr); const int* p_indices = INTEGER(indices); const double* p_data = REAL(data); int64_t nindptr = static_cast(Rf_asInteger(num_indptr)); int64_t ndata = static_cast(Rf_asInteger(nelem)); int64_t nrow = static_cast(Rf_asInteger(num_row)); - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); DatasetHandle handle = nullptr; DatasetHandle ref = nullptr; if (!Rf_isNull(reference)) { @@ -331,7 +331,7 @@ SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, nrow, parameters_ptr, ref, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _DatasetFinalizer, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } @@ -342,11 +342,11 @@ SEXP LGBM_DatasetCreateFromMat_R(SEXP data, SEXP parameters, SEXP reference) { R_API_BEGIN(); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); int32_t nrow = static_cast(Rf_asInteger(num_row)); int32_t ncol = static_cast(Rf_asInteger(num_col)); double* p_mat = REAL(data); - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); DatasetHandle handle = nullptr; DatasetHandle ref = nullptr; if (!Rf_isNull(reference)) { @@ -356,7 +356,7 @@ SEXP LGBM_DatasetCreateFromMat_R(SEXP data, parameters_ptr, ref, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _DatasetFinalizer, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } @@ -367,7 +367,7 @@ SEXP LGBM_DatasetGetSubset_R(SEXP handle, SEXP parameters) { R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); int32_t len = static_cast(Rf_asInteger(len_used_row_indices)); std::unique_ptr idxvec(new int32_t[len]); // convert from one-based to zero-based index @@ -378,14 +378,14 @@ SEXP LGBM_DatasetGetSubset_R(SEXP handle, for (int32_t i = 0; i < len; ++i) { idxvec[i] = static_cast(used_row_indices_[i] - 1); } - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); DatasetHandle res = nullptr; CHECK_CALL(LGBM_DatasetGetSubset(R_ExternalPtrAddr(handle), idxvec.get(), len, parameters_ptr, &res)); R_SetExternalPtrAddr(ret, res); R_RegisterCFinalizerEx(ret, _DatasetFinalizer, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } @@ -394,7 +394,7 @@ SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, SEXP feature_names) { R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); - auto vec_names = Split(CHAR(PROTECT(Rf_asChar(feature_names))), '\t'); + auto vec_names = Split(CHAR(Rf_protect(Rf_asChar(feature_names))), '\t'); int len = static_cast(vec_names.size()); std::unique_ptr vec_sptr(new const char*[len]); for (int i = 0; i < len; ++i) { @@ -402,13 +402,13 @@ SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, } CHECK_CALL(LGBM_DatasetSetFeatureNames(R_ExternalPtrAddr(handle), vec_sptr.get(), len)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); SEXP feature_names; @@ -446,11 +446,11 @@ SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle) { ptr_names.data())); } CHECK_EQ(len, out_len); - feature_names = PROTECT(safe_R_string(static_cast(len), &cont_token)); + feature_names = Rf_protect(safe_R_string(static_cast(len), &cont_token)); for (int i = 0; i < len; ++i) { SET_STRING_ELT(feature_names, i, safe_R_mkChar(ptr_names[i], &cont_token)); } - UNPROTECT(2); + Rf_unprotect(2); return feature_names; R_API_END(); } @@ -459,10 +459,10 @@ SEXP LGBM_DatasetSaveBinary_R(SEXP handle, SEXP filename) { R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); - const char* filename_ptr = CHAR(PROTECT(Rf_asChar(filename))); + const char* filename_ptr = CHAR(Rf_protect(Rf_asChar(filename))); CHECK_CALL(LGBM_DatasetSaveBinary(R_ExternalPtrAddr(handle), filename_ptr)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -484,7 +484,7 @@ SEXP LGBM_DatasetSetField_R(SEXP handle, R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); int len = Rf_asInteger(num_element); - const char* name = CHAR(PROTECT(Rf_asChar(field_name))); + const char* name = CHAR(Rf_protect(Rf_asChar(field_name))); if (!strcmp("group", name) || !strcmp("query", name)) { CHECK_CALL(LGBM_DatasetSetField(R_ExternalPtrAddr(handle), name, INTEGER(field_data), len, C_API_DTYPE_INT32)); } else if (!strcmp("init_score", name)) { @@ -494,7 +494,7 @@ SEXP LGBM_DatasetSetField_R(SEXP handle, std::copy(REAL(field_data), REAL(field_data) + len, vec.get()); CHECK_CALL(LGBM_DatasetSetField(R_ExternalPtrAddr(handle), name, vec.get(), len, C_API_DTYPE_FLOAT32)); } - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -504,7 +504,7 @@ SEXP LGBM_DatasetGetField_R(SEXP handle, SEXP field_data) { R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); - const char* name = CHAR(PROTECT(Rf_asChar(field_name))); + const char* name = CHAR(Rf_protect(Rf_asChar(field_name))); int out_len = 0; int out_type = 0; const void* res; @@ -526,7 +526,7 @@ SEXP LGBM_DatasetGetField_R(SEXP handle, auto p_data = reinterpret_cast(res); std::copy(p_data, p_data + out_len, REAL(field_data)); } - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -536,7 +536,7 @@ SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, SEXP out) { R_API_BEGIN(); _AssertDatasetHandleNotNull(handle); - const char* name = CHAR(PROTECT(Rf_asChar(field_name))); + const char* name = CHAR(Rf_protect(Rf_asChar(field_name))); int out_len = 0; int out_type = 0; const void* res; @@ -545,7 +545,7 @@ SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, out_len -= 1; } INTEGER(out)[0] = out_len; - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -553,10 +553,10 @@ SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, SEXP LGBM_DatasetUpdateParamChecking_R(SEXP old_params, SEXP new_params) { R_API_BEGIN(); - const char* old_params_ptr = CHAR(PROTECT(Rf_asChar(old_params))); - const char* new_params_ptr = CHAR(PROTECT(Rf_asChar(new_params))); + const char* old_params_ptr = CHAR(Rf_protect(Rf_asChar(old_params))); + const char* new_params_ptr = CHAR(Rf_protect(Rf_asChar(new_params))); CHECK_CALL(LGBM_DatasetUpdateParamChecking(old_params_ptr, new_params_ptr)); - UNPROTECT(2); + Rf_unprotect(2); return R_NilValue; R_API_END(); } @@ -613,34 +613,34 @@ SEXP LGBM_BoosterCreate_R(SEXP train_data, SEXP parameters) { R_API_BEGIN(); _AssertDatasetHandleNotNull(train_data); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreate(R_ExternalPtrAddr(train_data), parameters_ptr, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _BoosterFinalizer, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename) { R_API_BEGIN(); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); int out_num_iterations = 0; - const char* filename_ptr = CHAR(PROTECT(Rf_asChar(filename))); + const char* filename_ptr = CHAR(Rf_protect(Rf_asChar(filename))); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreateFromModelfile(filename_ptr, &out_num_iterations, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _BoosterFinalizer, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str) { R_API_BEGIN(); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); SEXP temp = NULL; int n_protected = 1; int out_num_iterations = 0; @@ -655,7 +655,7 @@ SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str) { break; } case STRSXP: { - temp = PROTECT(STRING_ELT(model_str, 0)); + temp = Rf_protect(STRING_ELT(model_str, 0)); n_protected++; model_str_ptr = reinterpret_cast(CHAR(temp)); } @@ -664,7 +664,7 @@ SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str) { CHECK_CALL(LGBM_BoosterLoadModelFromString(model_str_ptr, &out_num_iterations, &handle)); R_SetExternalPtrAddr(ret, handle); R_RegisterCFinalizerEx(ret, _BoosterFinalizer, TRUE); - UNPROTECT(n_protected); + Rf_unprotect(n_protected); return ret; R_API_END(); } @@ -703,9 +703,9 @@ SEXP LGBM_BoosterResetParameter_R(SEXP handle, SEXP parameters) { R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); - const char* parameters_ptr = CHAR(PROTECT(Rf_asChar(parameters))); + const char* parameters_ptr = CHAR(Rf_protect(Rf_asChar(parameters))); CHECK_CALL(LGBM_BoosterResetParameter(R_ExternalPtrAddr(handle), parameters_ptr)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -795,7 +795,7 @@ SEXP LGBM_BoosterGetLowerBoundValue_R(SEXP handle, } SEXP LGBM_BoosterGetEvalNames_R(SEXP handle) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); SEXP eval_names; @@ -834,11 +834,11 @@ SEXP LGBM_BoosterGetEvalNames_R(SEXP handle) { ptr_names.data())); } CHECK_EQ(out_len, len); - eval_names = PROTECT(safe_R_string(static_cast(len), &cont_token)); + eval_names = Rf_protect(safe_R_string(static_cast(len), &cont_token)); for (int i = 0; i < len; ++i) { SET_STRING_ELT(eval_names, i, safe_R_mkChar(ptr_names[i], &cont_token)); } - UNPROTECT(2); + Rf_unprotect(2); return eval_names; R_API_END(); } @@ -908,14 +908,14 @@ SEXP LGBM_BoosterPredictForFile_R(SEXP handle, SEXP result_filename) { R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); - const char* data_filename_ptr = CHAR(PROTECT(Rf_asChar(data_filename))); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); - const char* result_filename_ptr = CHAR(PROTECT(Rf_asChar(result_filename))); + const char* data_filename_ptr = CHAR(Rf_protect(Rf_asChar(data_filename))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); + const char* result_filename_ptr = CHAR(Rf_protect(Rf_asChar(result_filename))); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); CHECK_CALL(LGBM_BoosterPredictForFile(R_ExternalPtrAddr(handle), data_filename_ptr, Rf_asInteger(data_has_header), pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, result_filename_ptr)); - UNPROTECT(3); + Rf_unprotect(3); return R_NilValue; R_API_END(); } @@ -964,12 +964,12 @@ SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, int64_t nrow = static_cast(Rf_asInteger(num_row)); double* ptr_ret = REAL(out_result); int64_t out_len; - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); CHECK_CALL(LGBM_BoosterPredictForCSC(R_ExternalPtrAddr(handle), p_indptr, C_API_DTYPE_INT32, p_indices, p_data, C_API_DTYPE_FLOAT64, nindptr, ndata, nrow, pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, &out_len, ptr_ret)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -989,7 +989,7 @@ SEXP LGBM_BoosterPredictForCSR_R(SEXP handle, R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); int64_t out_len; CHECK_CALL(LGBM_BoosterPredictForCSR(R_ExternalPtrAddr(handle), INTEGER(indptr), C_API_DTYPE_INT32, INTEGER(indices), @@ -997,7 +997,7 @@ SEXP LGBM_BoosterPredictForCSR_R(SEXP handle, Rf_xlength(indptr), Rf_xlength(data), Rf_asInteger(ncols), pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, &out_len, REAL(out_result))); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -1016,7 +1016,7 @@ SEXP LGBM_BoosterPredictForCSRSingleRow_R(SEXP handle, R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); int nnz = static_cast(Rf_xlength(data)); const int indptr[] = {0, nnz}; int64_t out_len; @@ -1026,7 +1026,7 @@ SEXP LGBM_BoosterPredictForCSRSingleRow_R(SEXP handle, 2, nnz, Rf_asInteger(ncols), pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, &out_len, REAL(out_result))); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -1046,8 +1046,8 @@ SEXP LGBM_BoosterPredictForCSRSingleRowFastInit_R(SEXP handle, R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); FastConfigHandle out_fastConfig; CHECK_CALL(LGBM_BoosterPredictForCSRSingleRowFastInit(R_ExternalPtrAddr(handle), pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), @@ -1055,7 +1055,7 @@ SEXP LGBM_BoosterPredictForCSRSingleRowFastInit_R(SEXP handle, parameter_ptr, &out_fastConfig)); R_SetExternalPtrAddr(ret, out_fastConfig); R_RegisterCFinalizerEx(ret, LGBM_FastConfigFree_wrapped, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } @@ -1095,12 +1095,12 @@ SEXP LGBM_BoosterPredictForMat_R(SEXP handle, int32_t ncol = static_cast(Rf_asInteger(num_col)); const double* p_mat = REAL(data); double* ptr_ret = REAL(out_result); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); int64_t out_len; CHECK_CALL(LGBM_BoosterPredictForMat(R_ExternalPtrAddr(handle), p_mat, C_API_DTYPE_FLOAT64, nrow, ncol, COL_MAJOR, pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, &out_len, ptr_ret)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -1128,12 +1128,12 @@ SEXP LGBM_BoosterPredictSparseOutput_R(SEXP handle, SEXP start_iteration, SEXP num_iteration, SEXP parameter) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); const char* out_names[] = {"indptr", "indices", "data", ""}; - SEXP out = PROTECT(Rf_mkNamed(VECSXP, out_names)); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + SEXP out = Rf_protect(Rf_mkNamed(VECSXP, out_names)); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); int64_t out_len[2]; void *out_indptr; @@ -1179,7 +1179,7 @@ SEXP LGBM_BoosterPredictSparseOutput_R(SEXP handle, static_cast(&data_str), throw_R_memerr, &cont_token, cont_token)); pointers_struct->data = nullptr; - UNPROTECT(3); + Rf_unprotect(3); return out; R_API_END(); } @@ -1196,14 +1196,14 @@ SEXP LGBM_BoosterPredictForMatSingleRow_R(SEXP handle, R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); double* ptr_ret = REAL(out_result); int64_t out_len; CHECK_CALL(LGBM_BoosterPredictForMatSingleRow(R_ExternalPtrAddr(handle), REAL(data), C_API_DTYPE_FLOAT64, Rf_xlength(data), 1, pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), parameter_ptr, &out_len, ptr_ret)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -1219,8 +1219,8 @@ SEXP LGBM_BoosterPredictForMatSingleRowFastInit_R(SEXP handle, R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); - SEXP ret = PROTECT(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); - const char* parameter_ptr = CHAR(PROTECT(Rf_asChar(parameter))); + SEXP ret = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue)); + const char* parameter_ptr = CHAR(Rf_protect(Rf_asChar(parameter))); FastConfigHandle out_fastConfig; CHECK_CALL(LGBM_BoosterPredictForMatSingleRowFastInit(R_ExternalPtrAddr(handle), pred_type, Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), @@ -1228,7 +1228,7 @@ SEXP LGBM_BoosterPredictForMatSingleRowFastInit_R(SEXP handle, parameter_ptr, &out_fastConfig)); R_SetExternalPtrAddr(ret, out_fastConfig); R_RegisterCFinalizerEx(ret, LGBM_FastConfigFree_wrapped, TRUE); - UNPROTECT(2); + Rf_unprotect(2); return ret; R_API_END(); } @@ -1251,9 +1251,9 @@ SEXP LGBM_BoosterSaveModel_R(SEXP handle, SEXP start_iteration) { R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); - const char* filename_ptr = CHAR(PROTECT(Rf_asChar(filename))); + const char* filename_ptr = CHAR(Rf_protect(Rf_asChar(filename))); CHECK_CALL(LGBM_BoosterSaveModel(R_ExternalPtrAddr(handle), Rf_asInteger(start_iteration), Rf_asInteger(num_iteration), Rf_asInteger(feature_importance_type), filename_ptr)); - UNPROTECT(1); + Rf_unprotect(1); return R_NilValue; R_API_END(); } @@ -1266,7 +1266,7 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, SEXP num_iteration, SEXP feature_importance_type, SEXP start_iteration) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int64_t out_len = 0; @@ -1281,7 +1281,7 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, CHECK_CALL(LGBM_BoosterSaveModelToString(R_ExternalPtrAddr(handle), start_iter, num_iter, importance_type, out_len, &out_len, inner_char_buf->data())); } SEXP out = R_UnwindProtect(make_altrepped_raw_vec, &inner_char_buf, throw_R_memerr, &cont_token, cont_token); - UNPROTECT(1); + Rf_unprotect(1); return out; R_API_END(); } @@ -1290,7 +1290,7 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, SEXP num_iteration, SEXP feature_importance_type, SEXP start_iteration) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); int64_t out_len = 0; @@ -1300,14 +1300,14 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, int importance_type = Rf_asInteger(feature_importance_type); std::vector inner_char_buf(buf_len); CHECK_CALL(LGBM_BoosterSaveModelToString(R_ExternalPtrAddr(handle), start_iter, num_iter, importance_type, buf_len, &out_len, inner_char_buf.data())); - SEXP model_str = PROTECT(safe_R_raw(out_len, &cont_token)); + SEXP model_str = Rf_protect(safe_R_raw(out_len, &cont_token)); // if the model string was larger than the initial buffer, call the function again, writing directly to the R object if (out_len > buf_len) { CHECK_CALL(LGBM_BoosterSaveModelToString(R_ExternalPtrAddr(handle), start_iter, num_iter, importance_type, out_len, &out_len, reinterpret_cast(RAW(model_str)))); } else { std::copy(inner_char_buf.begin(), inner_char_buf.begin() + out_len, reinterpret_cast(RAW(model_str))); } - UNPROTECT(2); + Rf_unprotect(2); return model_str; R_API_END(); } @@ -1317,7 +1317,7 @@ SEXP LGBM_BoosterDumpModel_R(SEXP handle, SEXP num_iteration, SEXP feature_importance_type, SEXP start_iteration) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); SEXP model_str; @@ -1333,15 +1333,15 @@ SEXP LGBM_BoosterDumpModel_R(SEXP handle, inner_char_buf.resize(out_len); CHECK_CALL(LGBM_BoosterDumpModel(R_ExternalPtrAddr(handle), start_iter, num_iter, importance_type, out_len, &out_len, inner_char_buf.data())); } - model_str = PROTECT(safe_R_string(static_cast(1), &cont_token)); + model_str = Rf_protect(safe_R_string(static_cast(1), &cont_token)); SET_STRING_ELT(model_str, 0, safe_R_mkChar(inner_char_buf.data(), &cont_token)); - UNPROTECT(2); + Rf_unprotect(2); return model_str; R_API_END(); } SEXP LGBM_DumpParamAliases_R() { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); SEXP aliases_str; int64_t out_len = 0; @@ -1353,15 +1353,15 @@ SEXP LGBM_DumpParamAliases_R() { inner_char_buf.resize(out_len); CHECK_CALL(LGBM_DumpParamAliases(out_len, &out_len, inner_char_buf.data())); } - aliases_str = PROTECT(safe_R_string(static_cast(1), &cont_token)); + aliases_str = Rf_protect(safe_R_string(static_cast(1), &cont_token)); SET_STRING_ELT(aliases_str, 0, safe_R_mkChar(inner_char_buf.data(), &cont_token)); - UNPROTECT(2); + Rf_unprotect(2); return aliases_str; R_API_END(); } SEXP LGBM_BoosterGetLoadedParam_R(SEXP handle) { - SEXP cont_token = PROTECT(R_MakeUnwindCont()); + SEXP cont_token = Rf_protect(R_MakeUnwindCont()); R_API_BEGIN(); _AssertBoosterHandleNotNull(handle); SEXP params_str; @@ -1374,9 +1374,9 @@ SEXP LGBM_BoosterGetLoadedParam_R(SEXP handle) { inner_char_buf.resize(out_len); CHECK_CALL(LGBM_BoosterGetLoadedParam(R_ExternalPtrAddr(handle), out_len, &out_len, inner_char_buf.data())); } - params_str = PROTECT(safe_R_string(static_cast(1), &cont_token)); + params_str = Rf_protect(safe_R_string(static_cast(1), &cont_token)); SET_STRING_ELT(params_str, 0, safe_R_mkChar(inner_char_buf.data(), &cont_token)); - UNPROTECT(2); + Rf_unprotect(2); return params_str; R_API_END(); }