From f7475d732d964db1c63e11e0ac51c076ce189fb2 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 29 Feb 2020 10:01:55 -0600 Subject: [PATCH 01/28] [R-package] started cutting over from custom R-to-C interface to R.h --- CMakeLists.txt | 2 + src/lightgbm_R.cpp | 373 +++++++++++++++++++++++---------------------- 2 files changed, 189 insertions(+), 186 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 895f2dd26fce..7bae453b0dd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,8 @@ if(USE_DEBUG) ADD_DEFINITIONS(-DDEBUG) endif(USE_DEBUG) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/Library/Frameworks/R.framework/Versions/3.6/Resources/include") + if(USE_MPI) find_package(MPI REQUIRED) ADD_DEFINITIONS(-DUSE_MPI) diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index 1c8c52324661..f4b22bf2ad33 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -20,6 +20,7 @@ #define R_API_BEGIN() \ try { + #define R_API_END() } \ catch(std::exception& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.what()); return call_state;} \ catch(std::string& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.c_str()); return call_state; } \ @@ -36,7 +37,7 @@ using LightGBM::Common::Join; using LightGBM::Common::Split; using LightGBM::Log; -LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actual_len, size_t str_len) { +SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_t str_len) { if (str_len > INT32_MAX) { Log::Fatal("Don't support large string in R-package"); } @@ -49,15 +50,15 @@ LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actua return dest; } -LGBM_SE LGBM_GetLastError_R(LGBM_SE buf_len, LGBM_SE actual_len, LGBM_SE err_msg) { +SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg) { return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1); } -LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromFile_R(EXP filename, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); DatasetHandle handle = nullptr; CHECK_CALL(LGBM_DatasetCreateFromFile(R_CHAR_PTR(filename), R_CHAR_PTR(parameters), @@ -66,16 +67,16 @@ LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, R_API_END(); } -LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE num_indptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, + SEXP indices, + SEXP data, + SEXP num_indptr, + SEXP nelem, + SEXP num_row, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); const int* p_indptr = R_INT_PTR(indptr); const int* p_indices = R_INT_PTR(indices); @@ -92,13 +93,13 @@ LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, R_API_END(); } -LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, - LGBM_SE num_row, - LGBM_SE num_col, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromMat_R(SEXP data, + SEXP num_row, + SEXP num_col, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int32_t nrow = static_cast(R_AS_INT(num_row)); int32_t ncol = static_cast(R_AS_INT(num_col)); @@ -110,12 +111,12 @@ LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, R_API_END(); } -LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, - LGBM_SE used_row_indices, - LGBM_SE len_used_row_indices, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetSubset_R(SEXP handle, + SEXP used_row_indices, + SEXP len_used_row_indices, + SEXP parameters, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int len = R_AS_INT(len_used_row_indices); std::vector idxvec(len); @@ -132,9 +133,9 @@ LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, - LGBM_SE feature_names, - LGBM_SE call_state) { +SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, + SEXP feature_names, + SEXP call_state) { R_API_BEGIN(); auto vec_names = Split(R_CHAR_PTR(feature_names), '\t'); std::vector vec_sptr; @@ -147,11 +148,11 @@ LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE feature_names, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP feature_names, + SEXP call_state) { R_API_BEGIN(); int len = 0; CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &len)); @@ -170,17 +171,17 @@ LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSaveBinary_R(LGBM_SE handle, - LGBM_SE filename, - LGBM_SE call_state) { +SEXP LGBM_DatasetSaveBinary_R(SEXP handle, + SEXP filename, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetSaveBinary(R_GET_PTR(handle), R_CHAR_PTR(filename))); R_API_END(); } -LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_DatasetFree_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_DatasetFree(R_GET_PTR(handle))); @@ -189,11 +190,11 @@ LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE num_element, - LGBM_SE call_state) { +SEXP LGBM_DatasetSetField_R(SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP num_element, + SEXP call_state) { R_API_BEGIN(); int len = static_cast(R_AS_INT(num_element)); const char* name = R_CHAR_PTR(field_name); @@ -217,10 +218,10 @@ LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetField_R(SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -251,10 +252,10 @@ LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, + SEXP field_name, + SEXP out, + SEXP call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -268,16 +269,16 @@ LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetUpdateParamChecking_R(LGBM_SE old_params, - LGBM_SE new_params, - LGBM_SE call_state) { +SEXP LGBM_DatasetUpdateParamChecking_R(SEXP old_params, + SEXP new_params, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetUpdateParamChecking(R_CHAR_PTR(old_params), R_CHAR_PTR(new_params))); R_API_END(); } -LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, + SEXP call_state) { int nrow; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumData(R_GET_PTR(handle), &nrow)); @@ -285,9 +286,9 @@ LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, R_API_END(); } -LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, + SEXP out, + SEXP call_state) { int nfeature; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &nfeature)); @@ -297,8 +298,8 @@ LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, // --- start Booster interfaces -LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterFree_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_BoosterFree(R_GET_PTR(handle))); @@ -307,10 +308,10 @@ LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterCreate_R(SEXP train_data, + SEXP parameters, + SEXP out, + SEXP call_state) { R_API_BEGIN(); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreate(R_GET_PTR(train_data), R_CHAR_PTR(parameters), &handle)); @@ -318,9 +319,9 @@ LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, R_API_END(); } -LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -329,9 +330,9 @@ LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, R_API_END(); } -LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -340,41 +341,41 @@ LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, R_API_END(); } -LGBM_SE LGBM_BoosterMerge_R(LGBM_SE handle, - LGBM_SE other_handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterMerge_R(SEXP handle, + SEXP other_handle, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterMerge(R_GET_PTR(handle), R_GET_PTR(other_handle))); R_API_END(); } -LGBM_SE LGBM_BoosterAddValidData_R(LGBM_SE handle, - LGBM_SE valid_data, - LGBM_SE call_state) { +SEXP LGBM_BoosterAddValidData_R(SEXP handle, + SEXP valid_data, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterAddValidData(R_GET_PTR(handle), R_GET_PTR(valid_data))); R_API_END(); } -LGBM_SE LGBM_BoosterResetTrainingData_R(LGBM_SE handle, - LGBM_SE train_data, - LGBM_SE call_state) { +SEXP LGBM_BoosterResetTrainingData_R(SEXP handle, + SEXP train_data, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetTrainingData(R_GET_PTR(handle), R_GET_PTR(train_data))); R_API_END(); } -LGBM_SE LGBM_BoosterResetParameter_R(LGBM_SE handle, - LGBM_SE parameters, - LGBM_SE call_state) { +SEXP LGBM_BoosterResetParameter_R(SEXP handle, + SEXP parameters, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetParameter(R_GET_PTR(handle), R_CHAR_PTR(parameters))); R_API_END(); } -LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, + SEXP out, + SEXP call_state) { int num_class; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetNumClasses(R_GET_PTR(handle), &num_class)); @@ -382,19 +383,19 @@ LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterUpdateOneIter_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterUpdateOneIter_R(SEXP handle, + SEXP call_state) { int is_finished = 0; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterUpdateOneIter(R_GET_PTR(handle), &is_finished)); R_API_END(); } -LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, - LGBM_SE grad, - LGBM_SE hess, - LGBM_SE len, - LGBM_SE call_state) { +SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, + SEXP grad, + SEXP hess, + SEXP len, + SEXP call_state) { int is_finished = 0; R_API_BEGIN(); int int_len = R_AS_INT(len); @@ -408,16 +409,16 @@ LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterRollbackOneIter_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterRollbackOneIter(R_GET_PTR(handle))); R_API_END(); } -LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, + SEXP out, + SEXP call_state) { int out_iteration; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetCurrentIteration(R_GET_PTR(handle), &out_iteration)); @@ -425,29 +426,29 @@ LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetUpperBoundValue_R(LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetUpperBoundValue_R(SEXP handle, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetUpperBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -LGBM_SE LGBM_BoosterGetLowerBoundValue_R(LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetLowerBoundValue_R(SEXP handle, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetLowerBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE eval_names, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP eval_names, + SEXP call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -475,10 +476,10 @@ LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetEval_R(SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -489,10 +490,10 @@ LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, + SEXP data_idx, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int64_t len; CHECK_CALL(LGBM_BoosterGetNumPredict(R_GET_PTR(handle), R_AS_INT(data_idx), &len)); @@ -500,10 +501,10 @@ LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetPredict_R(SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); int64_t out_len; @@ -511,7 +512,7 @@ LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, R_API_END(); } -int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontrib) { +int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { int pred_type = C_API_PREDICT_NORMAL; if (R_AS_INT(is_rawscore)) { pred_type = C_API_PREDICT_RAW_SCORE; @@ -525,16 +526,16 @@ int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontr return pred_type; } -LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, - LGBM_SE data_filename, - LGBM_SE data_has_header, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE result_filename, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForFile_R(SEXP handle, + SEXP data_filename, + SEXP data_has_header, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP result_filename, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); CHECK_CALL(LGBM_BoosterPredictForFile(R_GET_PTR(handle), R_CHAR_PTR(data_filename), @@ -543,14 +544,14 @@ LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE out_len, - LGBM_SE call_state) { +SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP out_len, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); int64_t len = 0; @@ -560,20 +561,20 @@ LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE num_indptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, + SEXP indptr, + SEXP indices, + SEXP data, + SEXP num_indptr, + SEXP nelem, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -593,17 +594,17 @@ LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, - LGBM_SE data, - LGBM_SE num_row, - LGBM_SE num_col, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForMat_R(SEXP handle, + SEXP data, + SEXP num_row, + SEXP num_col, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -620,21 +621,21 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterSaveModel_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE filename, - LGBM_SE call_state) { +SEXP LGBM_BoosterSaveModel_R(SEXP handle, + SEXP num_iteration, + SEXP filename, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_CHAR_PTR(filename))); R_API_END(); } -LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state) { +SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); @@ -643,12 +644,12 @@ LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state) { +SEXP LGBM_BoosterDumpModel_R(SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); From 874a2591326dc735a7c63651d0ab97ac0810cc33 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 10 Mar 2020 20:13:51 -0500 Subject: [PATCH 02/28] replaced LGBM_SE with SEXP --- include/LightGBM/R_object_helper.h | 8 +- include/LightGBM/lightgbm_R.h | 456 ++++++++++++++--------------- 2 files changed, 232 insertions(+), 232 deletions(-) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index 1464c0a7083f..f760cbb83c72 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -144,7 +144,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(LGBM_SE x, void* ptr) { + inline void R_SET_PTR(SEXP x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int64_t)(NULL); } else { @@ -152,7 +152,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(LGBM_SE x) { + inline void* R_GET_PTR(SEXP x) { if (R_IS_NULL(x)) { return nullptr; } else { @@ -168,7 +168,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(LGBM_SE x, void* ptr) { + inline void R_SET_PTR(SEXP x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int32_t)(NULL); } else { @@ -176,7 +176,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(LGBM_SE x) { + inline void* R_GET_PTR(SEXP x) { if (R_IS_NULL(x)) { return nullptr; } else { diff --git a/include/LightGBM/lightgbm_R.h b/include/LightGBM/lightgbm_R.h index 076ea2946384..6d898be38ef4 100644 --- a/include/LightGBM/lightgbm_R.h +++ b/include/LightGBM/lightgbm_R.h @@ -15,10 +15,10 @@ * \return err_msg error information * \return error information */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE err_msg +LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( + SEXP buf_len, + SEXP actual_len, + SEXP err_msg ); // --- start Dataset interface @@ -31,12 +31,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( - LGBM_SE filename, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( + SEXP filename, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -52,17 +52,17 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE nindptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( + SEXP indptr, + SEXP indices, + SEXP data, + SEXP nindptr, + SEXP nelem, + SEXP num_row, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -75,14 +75,14 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( - LGBM_SE data, - LGBM_SE nrow, - LGBM_SE ncol, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( + SEXP data, + SEXP nrow, + SEXP ncol, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -94,13 +94,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( - LGBM_SE handle, - LGBM_SE used_row_indices, - LGBM_SE len_used_row_indices, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( + SEXP handle, + SEXP used_row_indices, + SEXP len_used_row_indices, + SEXP parameters, + SEXP out, + SEXP call_state ); /*! @@ -109,10 +109,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( - LGBM_SE handle, - LGBM_SE feature_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( + SEXP handle, + SEXP feature_names, + SEXP call_state ); /*! @@ -121,12 +121,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( - LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE feature_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( + SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP feature_names, + SEXP call_state ); /*! @@ -135,10 +135,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( - LGBM_SE handle, - LGBM_SE filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( + SEXP handle, + SEXP filename, + SEXP call_state ); /*! @@ -146,9 +146,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( * \param handle an instance of dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( + SEXP handle, + SEXP call_state ); /*! @@ -161,12 +161,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( * \param num_element number of element in field_data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE num_element, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( + SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP num_element, + SEXP call_state ); /*! @@ -176,11 +176,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( * \param out size of info vector from dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( + SEXP handle, + SEXP field_name, + SEXP out, + SEXP call_state ); /*! @@ -190,11 +190,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( * \param field_data pointer to vector * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( + SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP call_state ); /*! @@ -203,10 +203,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( * \param new_params New dataset parameters * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( - LGBM_SE old_params, - LGBM_SE new_params, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( + SEXP old_params, + SEXP new_params, + SEXP call_state ); /*! @@ -215,10 +215,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( * \param out The address to hold number of data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -227,10 +227,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( * \param out The output of number of features * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( + SEXP handle, + SEXP out, + SEXP call_state ); // --- start Booster interfaces @@ -242,11 +242,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( - LGBM_SE train_data, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( + SEXP train_data, + SEXP parameters, + SEXP out, + SEXP call_state ); /*! @@ -254,9 +254,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( * \param handle handle to be freed * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( + SEXP handle, + SEXP call_state ); /*! @@ -265,10 +265,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( - LGBM_SE filename, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( + SEXP filename, + SEXP out, + SEXP call_state ); /*! @@ -277,10 +277,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( - LGBM_SE model_str, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( + SEXP model_str, + SEXP out, + SEXP call_state ); /*! @@ -289,10 +289,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( * \param other_handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( - LGBM_SE handle, - LGBM_SE other_handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( + SEXP handle, + SEXP other_handle, + SEXP call_state ); /*! @@ -301,10 +301,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( * \param valid_data validation data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( - LGBM_SE handle, - LGBM_SE valid_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( + SEXP handle, + SEXP valid_data, + SEXP call_state ); /*! @@ -313,10 +313,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( * \param train_data training data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( - LGBM_SE handle, - LGBM_SE train_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( + SEXP handle, + SEXP train_data, + SEXP call_state ); /*! @@ -325,10 +325,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( * \param parameters format: 'key1=value1 key2=value2' * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( - LGBM_SE handle, - LGBM_SE parameters, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( + SEXP handle, + SEXP parameters, + SEXP call_state ); /*! @@ -337,10 +337,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( * \param out number of classes * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -348,9 +348,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( + SEXP handle, + SEXP call_state ); /*! @@ -362,12 +362,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( * \param len length of grad/hess * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( - LGBM_SE handle, - LGBM_SE grad, - LGBM_SE hess, - LGBM_SE len, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( + SEXP handle, + SEXP grad, + SEXP hess, + SEXP len, + SEXP call_state ); /*! @@ -375,9 +375,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( + SEXP handle, + SEXP call_state ); /*! @@ -385,10 +385,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( * \param out iteration of boosting rounds * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -397,10 +397,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( * \param[out] out_results Result pointing to max value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( - LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( + SEXP handle, + SEXP out_result, + SEXP call_state ); /*! @@ -409,10 +409,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( * \param[out] out_results Result pointing to min value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( - LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( + SEXP handle, + SEXP out_result, + SEXP call_state ); /*! @@ -420,12 +420,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( * \param eval_names eval names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( - LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE eval_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( + SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP eval_names, + SEXP call_state ); /*! @@ -435,11 +435,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( * \param out_result float array contains result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( + SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state ); /*! @@ -449,11 +449,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( * \param out size of predict * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( + SEXP handle, + SEXP data_idx, + SEXP out, + SEXP call_state ); /*! @@ -464,11 +464,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( * \param out_result, used to store predict result, should pre-allocate memory * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( + SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state ); /*! @@ -482,17 +482,17 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( * \return 0 when succeed, -1 when failure happens * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( - LGBM_SE handle, - LGBM_SE data_filename, - LGBM_SE data_has_header, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE result_filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( + SEXP handle, + SEXP data_filename, + SEXP data_has_header, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP result_filename, + SEXP call_state ); /*! @@ -505,15 +505,15 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( * \param out_len length of prediction * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( - LGBM_SE handle, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE out_len, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( + SEXP handle, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP out_len, + SEXP call_state ); /*! @@ -534,21 +534,21 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( - LGBM_SE handle, - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE nindptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( + SEXP handle, + SEXP indptr, + SEXP indices, + SEXP data, + SEXP nindptr, + SEXP nelem, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state ); /*! @@ -566,18 +566,18 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( - LGBM_SE handle, - LGBM_SE data, - LGBM_SE nrow, - LGBM_SE ncol, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( + SEXP handle, + SEXP data, + SEXP nrow, + SEXP ncol, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state ); /*! @@ -587,11 +587,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( + SEXP handle, + SEXP num_iteration, + SEXP filename, + SEXP call_state ); /*! @@ -601,13 +601,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( * \param out_str string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( + SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state ); /*! @@ -617,13 +617,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( * \param out_str json format string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R( + SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state ); #endif // LIGHTGBM_R_H_ From 42eca157a7d7bb5a3980ed6d67a632bc9602a858 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 10 Mar 2020 20:28:15 -0500 Subject: [PATCH 03/28] fixed error about ocnflicting definitions of length --- include/LightGBM/R_object_helper.h | 4 ++++ src/lightgbm_R.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index f760cbb83c72..6951db82a89a 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -13,6 +13,10 @@ #ifndef R_OBJECT_HELPER_H_ #define R_OBJECT_HELPER_H_ +// https://github.com/nimble-dev/nimble/issues/307#issue-224932135 +#define R_NO_REMAP +#include + #include #define TYPE_BITS 5 diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index f4b22bf2ad33..108515c7cea3 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -54,7 +54,7 @@ SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg) { return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1); } -SEXP LGBM_DatasetCreateFromFile_R(EXP filename, +SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, SEXP parameters, SEXP reference, SEXP out, From 0960dd6682ab14661388ea266104e32cc47a7208 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 00:47:20 -0500 Subject: [PATCH 04/28] got linking working --- CMakeLists.txt | 4 ++++ include/LightGBM/R_object_helper.h | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bae453b0dd2..3706d4ca83cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,10 @@ OPTION(USE_TIMETAG "Set to ON to output time costs" OFF) OPTION(USE_DEBUG "Set to ON for Debug mode" OFF) OPTION(BUILD_FOR_R "Set to ON if building lib_lightgbm for use with the R package" OFF) +list(APPEND CMAKE_MODULE_PATH "${lightgbm_SOURCE_DIR}/cmake/modules") +find_package(LibR REQUIRED) +message(STATUS "LIBR_CORE_LIBRARY " ${LIBR_CORE_LIBRARY}) + if(APPLE) OPTION(APPLE_OUTPUT_DYLIB "Output dylib shared library" OFF) endif(APPLE) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index 6951db82a89a..fee2ea4f157a 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -13,11 +13,13 @@ #ifndef R_OBJECT_HELPER_H_ #define R_OBJECT_HELPER_H_ +#include +#include + // https://github.com/nimble-dev/nimble/issues/307#issue-224932135 #define R_NO_REMAP #include - -#include +//#include #define TYPE_BITS 5 // use .Internal(internalsID()) to uuid @@ -63,6 +65,7 @@ }; typedef int xlen_t; + #endif // R_VER_ABOVE_35 struct lgbm_primsxp { @@ -111,7 +114,7 @@ typedef struct LGBM_SER { struct lgbm_closxp closxp; struct lgbm_promsxp promsxp; } u; -} LGBM_SER, *LGBM_SE; +} LGBM_SER; struct lgbm_vecsxp { xlen_t length; @@ -141,7 +144,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_AS_INT64(x) (*(reinterpret_cast DATAPTR(x))) -#define R_IS_NULL(x) ((*reinterpret_cast(x)).sxpinfo.type == 0) +// #define R_IS_NULL(x) ((*reinterpret_cast(x)).sxpinfo.type == 0) // 64bit pointer #if INTPTR_MAX == INT64_MAX @@ -157,7 +160,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } inline void* R_GET_PTR(SEXP x) { - if (R_IS_NULL(x)) { + if (R_ExternalPtrAddr(x) == NULL) { return nullptr; } else { auto ret = reinterpret_cast(R_ADDR(x)[0]); @@ -181,7 +184,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } inline void* R_GET_PTR(SEXP x) { - if (R_IS_NULL(x)) { + if (R_ExternalPtrAddr(x) == NULL) { return nullptr; } else { auto ret = reinterpret_cast(R_ADDR(x)[0]); From d08b960a7498b90930e1d92cbed4aaf1cf2f7cde Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 01:01:43 -0500 Subject: [PATCH 05/28] more stuff --- CMakeLists.txt | 4 ---- include/LightGBM/R_object_helper.h | 9 +++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3706d4ca83cd..7bae453b0dd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,6 @@ OPTION(USE_TIMETAG "Set to ON to output time costs" OFF) OPTION(USE_DEBUG "Set to ON for Debug mode" OFF) OPTION(BUILD_FOR_R "Set to ON if building lib_lightgbm for use with the R package" OFF) -list(APPEND CMAKE_MODULE_PATH "${lightgbm_SOURCE_DIR}/cmake/modules") -find_package(LibR REQUIRED) -message(STATUS "LIBR_CORE_LIBRARY " ${LIBR_CORE_LIBRARY}) - if(APPLE) OPTION(APPLE_OUTPUT_DYLIB "Output dylib shared library" OFF) endif(APPLE) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index fee2ea4f157a..543ec84d9b93 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -146,6 +146,11 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; // #define R_IS_NULL(x) ((*reinterpret_cast(x)).sxpinfo.type == 0) +// https://stackoverflow.com/questions/26666614/how-do-i-check-if-an-externalptr-is-null-from-within-r +SEXP R_IS_NULL(SEXP pointer) { + return ScalarLogical(!R_ExternalPtrAddr(pointer)); +} + // 64bit pointer #if INTPTR_MAX == INT64_MAX @@ -160,7 +165,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } inline void* R_GET_PTR(SEXP x) { - if (R_ExternalPtrAddr(x) == NULL) { + if (R_IS_NULL(x)) { return nullptr; } else { auto ret = reinterpret_cast(R_ADDR(x)[0]); @@ -184,7 +189,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } inline void* R_GET_PTR(SEXP x) { - if (R_ExternalPtrAddr(x) == NULL) { + if (R_IS_NULL(x)) { return nullptr; } else { auto ret = reinterpret_cast(R_ADDR(x)[0]); From d1dac984bffda548c3df12f1d52979cd3ff4a684 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 21:29:12 -0500 Subject: [PATCH 06/28] eliminated R CMD CHECK note about printing --- include/LightGBM/R_object_helper.h | 23 +- include/LightGBM/lightgbm_R.h | 456 ++++++++++++++--------------- src/lightgbm_R.cpp | 373 ++++++++++++----------- 3 files changed, 420 insertions(+), 432 deletions(-) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index 543ec84d9b93..a3cf2f32ea77 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -13,14 +13,8 @@ #ifndef R_OBJECT_HELPER_H_ #define R_OBJECT_HELPER_H_ -#include #include -// https://github.com/nimble-dev/nimble/issues/307#issue-224932135 -#define R_NO_REMAP -#include -//#include - #define TYPE_BITS 5 // use .Internal(internalsID()) to uuid #define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327" @@ -114,7 +108,7 @@ typedef struct LGBM_SER { struct lgbm_closxp closxp; struct lgbm_promsxp promsxp; } u; -} LGBM_SER; +} LGBM_SER, *LGBM_SE; struct lgbm_vecsxp { xlen_t length; @@ -144,19 +138,14 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_AS_INT64(x) (*(reinterpret_cast DATAPTR(x))) -// #define R_IS_NULL(x) ((*reinterpret_cast(x)).sxpinfo.type == 0) - -// https://stackoverflow.com/questions/26666614/how-do-i-check-if-an-externalptr-is-null-from-within-r -SEXP R_IS_NULL(SEXP pointer) { - return ScalarLogical(!R_ExternalPtrAddr(pointer)); -} +#define R_IS_NULL(x) ((*reinterpret_cast(x)).sxpinfo.type == 0) // 64bit pointer #if INTPTR_MAX == INT64_MAX #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(SEXP x, void* ptr) { + inline void R_SET_PTR(LGBM_SE x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int64_t)(NULL); } else { @@ -164,7 +153,7 @@ SEXP R_IS_NULL(SEXP pointer) { } } - inline void* R_GET_PTR(SEXP x) { + inline void* R_GET_PTR(LGBM_SE x) { if (R_IS_NULL(x)) { return nullptr; } else { @@ -180,7 +169,7 @@ SEXP R_IS_NULL(SEXP pointer) { #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(SEXP x, void* ptr) { + inline void R_SET_PTR(LGBM_SE x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int32_t)(NULL); } else { @@ -188,7 +177,7 @@ SEXP R_IS_NULL(SEXP pointer) { } } - inline void* R_GET_PTR(SEXP x) { + inline void* R_GET_PTR(LGBM_SE x) { if (R_IS_NULL(x)) { return nullptr; } else { diff --git a/include/LightGBM/lightgbm_R.h b/include/LightGBM/lightgbm_R.h index 6d898be38ef4..076ea2946384 100644 --- a/include/LightGBM/lightgbm_R.h +++ b/include/LightGBM/lightgbm_R.h @@ -15,10 +15,10 @@ * \return err_msg error information * \return error information */ -LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( - SEXP buf_len, - SEXP actual_len, - SEXP err_msg +LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE err_msg ); // --- start Dataset interface @@ -31,12 +31,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( - SEXP filename, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( + LGBM_SE filename, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -52,17 +52,17 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( - SEXP indptr, - SEXP indices, - SEXP data, - SEXP nindptr, - SEXP nelem, - SEXP num_row, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE nindptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -75,14 +75,14 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( - SEXP data, - SEXP nrow, - SEXP ncol, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( + LGBM_SE data, + LGBM_SE nrow, + LGBM_SE ncol, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -94,13 +94,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( - SEXP handle, - SEXP used_row_indices, - SEXP len_used_row_indices, - SEXP parameters, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( + LGBM_SE handle, + LGBM_SE used_row_indices, + LGBM_SE len_used_row_indices, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -109,10 +109,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( - SEXP handle, - SEXP feature_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( + LGBM_SE handle, + LGBM_SE feature_names, + LGBM_SE call_state ); /*! @@ -121,12 +121,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( - SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP feature_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( + LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE feature_names, + LGBM_SE call_state ); /*! @@ -135,10 +135,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( - SEXP handle, - SEXP filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( + LGBM_SE handle, + LGBM_SE filename, + LGBM_SE call_state ); /*! @@ -146,9 +146,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( * \param handle an instance of dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -161,12 +161,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( * \param num_element number of element in field_data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( - SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP num_element, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE num_element, + LGBM_SE call_state ); /*! @@ -176,11 +176,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( * \param out size of info vector from dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( - SEXP handle, - SEXP field_name, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -190,11 +190,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( * \param field_data pointer to vector * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( - SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE call_state ); /*! @@ -203,10 +203,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( * \param new_params New dataset parameters * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( - SEXP old_params, - SEXP new_params, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( + LGBM_SE old_params, + LGBM_SE new_params, + LGBM_SE call_state ); /*! @@ -215,10 +215,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( * \param out The address to hold number of data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -227,10 +227,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( * \param out The output of number of features * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); // --- start Booster interfaces @@ -242,11 +242,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( - SEXP train_data, - SEXP parameters, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( + LGBM_SE train_data, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -254,9 +254,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( * \param handle handle to be freed * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -265,10 +265,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( - SEXP filename, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( + LGBM_SE filename, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -277,10 +277,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( - SEXP model_str, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( + LGBM_SE model_str, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -289,10 +289,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( * \param other_handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( - SEXP handle, - SEXP other_handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( + LGBM_SE handle, + LGBM_SE other_handle, + LGBM_SE call_state ); /*! @@ -301,10 +301,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( * \param valid_data validation data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( - SEXP handle, - SEXP valid_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( + LGBM_SE handle, + LGBM_SE valid_data, + LGBM_SE call_state ); /*! @@ -313,10 +313,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( * \param train_data training data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( - SEXP handle, - SEXP train_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( + LGBM_SE handle, + LGBM_SE train_data, + LGBM_SE call_state ); /*! @@ -325,10 +325,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( * \param parameters format: 'key1=value1 key2=value2' * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( - SEXP handle, - SEXP parameters, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( + LGBM_SE handle, + LGBM_SE parameters, + LGBM_SE call_state ); /*! @@ -337,10 +337,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( * \param out number of classes * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -348,9 +348,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -362,12 +362,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( * \param len length of grad/hess * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( - SEXP handle, - SEXP grad, - SEXP hess, - SEXP len, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( + LGBM_SE handle, + LGBM_SE grad, + LGBM_SE hess, + LGBM_SE len, + LGBM_SE call_state ); /*! @@ -375,9 +375,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -385,10 +385,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( * \param out iteration of boosting rounds * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -397,10 +397,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( * \param[out] out_results Result pointing to max value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( - SEXP handle, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( + LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -409,10 +409,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( * \param[out] out_results Result pointing to min value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( - SEXP handle, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( + LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -420,12 +420,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( * \param eval_names eval names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( - SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP eval_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( + LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE eval_names, + LGBM_SE call_state ); /*! @@ -435,11 +435,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( * \param out_result float array contains result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( - SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -449,11 +449,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( * \param out size of predict * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( - SEXP handle, - SEXP data_idx, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -464,11 +464,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( * \param out_result, used to store predict result, should pre-allocate memory * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( - SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -482,17 +482,17 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( * \return 0 when succeed, -1 when failure happens * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( - SEXP handle, - SEXP data_filename, - SEXP data_has_header, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP result_filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( + LGBM_SE handle, + LGBM_SE data_filename, + LGBM_SE data_has_header, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE result_filename, + LGBM_SE call_state ); /*! @@ -505,15 +505,15 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( * \param out_len length of prediction * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( - SEXP handle, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP out_len, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( + LGBM_SE handle, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE out_len, + LGBM_SE call_state ); /*! @@ -534,21 +534,21 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( - SEXP handle, - SEXP indptr, - SEXP indices, - SEXP data, - SEXP nindptr, - SEXP nelem, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( + LGBM_SE handle, + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE nindptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -566,18 +566,18 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( - SEXP handle, - SEXP data, - SEXP nrow, - SEXP ncol, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( + LGBM_SE handle, + LGBM_SE data, + LGBM_SE nrow, + LGBM_SE ncol, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -587,11 +587,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( - SEXP handle, - SEXP num_iteration, - SEXP filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE filename, + LGBM_SE call_state ); /*! @@ -601,13 +601,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( * \param out_str string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( - SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state ); /*! @@ -617,13 +617,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( * \param out_str json format string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R( - SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state ); #endif // LIGHTGBM_R_H_ diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index 108515c7cea3..1c8c52324661 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -20,7 +20,6 @@ #define R_API_BEGIN() \ try { - #define R_API_END() } \ catch(std::exception& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.what()); return call_state;} \ catch(std::string& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.c_str()); return call_state; } \ @@ -37,7 +36,7 @@ using LightGBM::Common::Join; using LightGBM::Common::Split; using LightGBM::Log; -SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_t str_len) { +LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actual_len, size_t str_len) { if (str_len > INT32_MAX) { Log::Fatal("Don't support large string in R-package"); } @@ -50,15 +49,15 @@ SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_ return dest; } -SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg) { +LGBM_SE LGBM_GetLastError_R(LGBM_SE buf_len, LGBM_SE actual_len, LGBM_SE err_msg) { return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1); } -SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); DatasetHandle handle = nullptr; CHECK_CALL(LGBM_DatasetCreateFromFile(R_CHAR_PTR(filename), R_CHAR_PTR(parameters), @@ -67,16 +66,16 @@ SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, R_API_END(); } -SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, - SEXP indices, - SEXP data, - SEXP num_indptr, - SEXP nelem, - SEXP num_row, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE num_indptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); const int* p_indptr = R_INT_PTR(indptr); const int* p_indices = R_INT_PTR(indices); @@ -93,13 +92,13 @@ SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, R_API_END(); } -SEXP LGBM_DatasetCreateFromMat_R(SEXP data, - SEXP num_row, - SEXP num_col, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, + LGBM_SE num_row, + LGBM_SE num_col, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int32_t nrow = static_cast(R_AS_INT(num_row)); int32_t ncol = static_cast(R_AS_INT(num_col)); @@ -111,12 +110,12 @@ SEXP LGBM_DatasetCreateFromMat_R(SEXP data, R_API_END(); } -SEXP LGBM_DatasetGetSubset_R(SEXP handle, - SEXP used_row_indices, - SEXP len_used_row_indices, - SEXP parameters, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, + LGBM_SE used_row_indices, + LGBM_SE len_used_row_indices, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int len = R_AS_INT(len_used_row_indices); std::vector idxvec(len); @@ -133,9 +132,9 @@ SEXP LGBM_DatasetGetSubset_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, - SEXP feature_names, - SEXP call_state) { +LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, + LGBM_SE feature_names, + LGBM_SE call_state) { R_API_BEGIN(); auto vec_names = Split(R_CHAR_PTR(feature_names), '\t'); std::vector vec_sptr; @@ -148,11 +147,11 @@ SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP feature_names, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE feature_names, + LGBM_SE call_state) { R_API_BEGIN(); int len = 0; CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &len)); @@ -171,17 +170,17 @@ SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSaveBinary_R(SEXP handle, - SEXP filename, - SEXP call_state) { +LGBM_SE LGBM_DatasetSaveBinary_R(LGBM_SE handle, + LGBM_SE filename, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetSaveBinary(R_GET_PTR(handle), R_CHAR_PTR(filename))); R_API_END(); } -SEXP LGBM_DatasetFree_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_DatasetFree(R_GET_PTR(handle))); @@ -190,11 +189,11 @@ SEXP LGBM_DatasetFree_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSetField_R(SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP num_element, - SEXP call_state) { +LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE num_element, + LGBM_SE call_state) { R_API_BEGIN(); int len = static_cast(R_AS_INT(num_element)); const char* name = R_CHAR_PTR(field_name); @@ -218,10 +217,10 @@ SEXP LGBM_DatasetSetField_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetField_R(SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -252,10 +251,10 @@ SEXP LGBM_DatasetGetField_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, - SEXP field_name, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -269,16 +268,16 @@ SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetUpdateParamChecking_R(SEXP old_params, - SEXP new_params, - SEXP call_state) { +LGBM_SE LGBM_DatasetUpdateParamChecking_R(LGBM_SE old_params, + LGBM_SE new_params, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetUpdateParamChecking(R_CHAR_PTR(old_params), R_CHAR_PTR(new_params))); R_API_END(); } -SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, + LGBM_SE call_state) { int nrow; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumData(R_GET_PTR(handle), &nrow)); @@ -286,9 +285,9 @@ SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, R_API_END(); } -SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int nfeature; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &nfeature)); @@ -298,8 +297,8 @@ SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, // --- start Booster interfaces -SEXP LGBM_BoosterFree_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_BoosterFree(R_GET_PTR(handle))); @@ -308,10 +307,10 @@ SEXP LGBM_BoosterFree_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterCreate_R(SEXP train_data, - SEXP parameters, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreate(R_GET_PTR(train_data), R_CHAR_PTR(parameters), &handle)); @@ -319,9 +318,9 @@ SEXP LGBM_BoosterCreate_R(SEXP train_data, R_API_END(); } -SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -330,9 +329,9 @@ SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, R_API_END(); } -SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -341,41 +340,41 @@ SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, R_API_END(); } -SEXP LGBM_BoosterMerge_R(SEXP handle, - SEXP other_handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterMerge_R(LGBM_SE handle, + LGBM_SE other_handle, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterMerge(R_GET_PTR(handle), R_GET_PTR(other_handle))); R_API_END(); } -SEXP LGBM_BoosterAddValidData_R(SEXP handle, - SEXP valid_data, - SEXP call_state) { +LGBM_SE LGBM_BoosterAddValidData_R(LGBM_SE handle, + LGBM_SE valid_data, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterAddValidData(R_GET_PTR(handle), R_GET_PTR(valid_data))); R_API_END(); } -SEXP LGBM_BoosterResetTrainingData_R(SEXP handle, - SEXP train_data, - SEXP call_state) { +LGBM_SE LGBM_BoosterResetTrainingData_R(LGBM_SE handle, + LGBM_SE train_data, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetTrainingData(R_GET_PTR(handle), R_GET_PTR(train_data))); R_API_END(); } -SEXP LGBM_BoosterResetParameter_R(SEXP handle, - SEXP parameters, - SEXP call_state) { +LGBM_SE LGBM_BoosterResetParameter_R(LGBM_SE handle, + LGBM_SE parameters, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetParameter(R_GET_PTR(handle), R_CHAR_PTR(parameters))); R_API_END(); } -SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int num_class; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetNumClasses(R_GET_PTR(handle), &num_class)); @@ -383,19 +382,19 @@ SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterUpdateOneIter_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterUpdateOneIter_R(LGBM_SE handle, + LGBM_SE call_state) { int is_finished = 0; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterUpdateOneIter(R_GET_PTR(handle), &is_finished)); R_API_END(); } -SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, - SEXP grad, - SEXP hess, - SEXP len, - SEXP call_state) { +LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, + LGBM_SE grad, + LGBM_SE hess, + LGBM_SE len, + LGBM_SE call_state) { int is_finished = 0; R_API_BEGIN(); int int_len = R_AS_INT(len); @@ -409,16 +408,16 @@ SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterRollbackOneIter_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterRollbackOneIter(R_GET_PTR(handle))); R_API_END(); } -SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int out_iteration; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetCurrentIteration(R_GET_PTR(handle), &out_iteration)); @@ -426,29 +425,29 @@ SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetUpperBoundValue_R(SEXP handle, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetUpperBoundValue_R(LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetUpperBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -SEXP LGBM_BoosterGetLowerBoundValue_R(SEXP handle, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetLowerBoundValue_R(LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetLowerBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP eval_names, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE eval_names, + LGBM_SE call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -476,10 +475,10 @@ SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetEval_R(SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -490,10 +489,10 @@ SEXP LGBM_BoosterGetEval_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, - SEXP data_idx, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int64_t len; CHECK_CALL(LGBM_BoosterGetNumPredict(R_GET_PTR(handle), R_AS_INT(data_idx), &len)); @@ -501,10 +500,10 @@ SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetPredict_R(SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); int64_t out_len; @@ -512,7 +511,7 @@ SEXP LGBM_BoosterGetPredict_R(SEXP handle, R_API_END(); } -int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { +int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontrib) { int pred_type = C_API_PREDICT_NORMAL; if (R_AS_INT(is_rawscore)) { pred_type = C_API_PREDICT_RAW_SCORE; @@ -526,16 +525,16 @@ int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { return pred_type; } -SEXP LGBM_BoosterPredictForFile_R(SEXP handle, - SEXP data_filename, - SEXP data_has_header, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP result_filename, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, + LGBM_SE data_filename, + LGBM_SE data_has_header, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE result_filename, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); CHECK_CALL(LGBM_BoosterPredictForFile(R_GET_PTR(handle), R_CHAR_PTR(data_filename), @@ -544,14 +543,14 @@ SEXP LGBM_BoosterPredictForFile_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP out_len, - SEXP call_state) { +LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE out_len, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); int64_t len = 0; @@ -561,20 +560,20 @@ SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, - SEXP indptr, - SEXP indices, - SEXP data, - SEXP num_indptr, - SEXP nelem, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE num_indptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -594,17 +593,17 @@ SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterPredictForMat_R(SEXP handle, - SEXP data, - SEXP num_row, - SEXP num_col, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, + LGBM_SE data, + LGBM_SE num_row, + LGBM_SE num_col, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -621,21 +620,21 @@ SEXP LGBM_BoosterPredictForMat_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterSaveModel_R(SEXP handle, - SEXP num_iteration, - SEXP filename, - SEXP call_state) { +LGBM_SE LGBM_BoosterSaveModel_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE filename, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_CHAR_PTR(filename))); R_API_END(); } -SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state) { +LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); @@ -644,12 +643,12 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterDumpModel_R(SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state) { +LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); From 08520231ade98bdeb9aed8dc6d8b9d91a91ed03b Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 21:47:17 -0500 Subject: [PATCH 07/28] switched from hard-coded include dir to the one from FindLibR.cmake --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bae453b0dd2..c05b833262f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,8 +89,6 @@ if(USE_DEBUG) ADD_DEFINITIONS(-DDEBUG) endif(USE_DEBUG) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/Library/Frameworks/R.framework/Versions/3.6/Resources/include") - if(USE_MPI) find_package(MPI REQUIRED) ADD_DEFINITIONS(-DUSE_MPI) @@ -274,9 +272,9 @@ if(USE_SWIG) COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) else() add_custom_command(TARGET _lightgbm_swig POST_BUILD - COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java - COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64 - COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) + COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java + COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64 + COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) endif() endif(USE_SWIG) From b459a96bffdafd97682b992293adb1ab39a0bd28 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 22:47:02 -0500 Subject: [PATCH 08/28] commented-out everything in CI that does not touch R --- .travis.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index bbd72bb9b207..a998ce6cf04e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,16 +14,16 @@ env: global: # default values - PYTHON_VERSION=3.7 matrix: - - TASK=regular PYTHON_VERSION=3.6 - - TASK=sdist PYTHON_VERSION=2.7 - - TASK=bdist - - TASK=if-else - - TASK=lint - - TASK=check-docs - - TASK=mpi METHOD=source - - TASK=mpi METHOD=pip - - TASK=gpu METHOD=source PYTHON_VERSION=3.5 - - TASK=gpu METHOD=pip PYTHON_VERSION=3.6 + # - TASK=regular PYTHON_VERSION=3.6 + # - TASK=sdist PYTHON_VERSION=2.7 + # - TASK=bdist + # - TASK=if-else + # - TASK=lint + # - TASK=check-docs + # - TASK=mpi METHOD=source + # - TASK=mpi METHOD=pip + # - TASK=gpu METHOD=source PYTHON_VERSION=3.5 + # - TASK=gpu METHOD=pip PYTHON_VERSION=3.6 - TASK=r-package matrix: From c278fa997745f546eb95c42037aa45ce1902953a Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 22:47:18 -0500 Subject: [PATCH 09/28] more changes --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a998ce6cf04e..2f3c7c0cacfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: # - TASK=sdist PYTHON_VERSION=2.7 # - TASK=bdist # - TASK=if-else - # - TASK=lint + - TASK=lint # - TASK=check-docs # - TASK=mpi METHOD=source # - TASK=mpi METHOD=pip From c2084e1d8a871c861bbf4ead04189f4c64843ad0 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 23:09:38 -0500 Subject: [PATCH 10/28] trying to get better logs --- .ci/test_r_package.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index 0e660ba8581b..8828451650bf 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -84,7 +84,9 @@ export _R_CHECK_FORCE_SUGGESTS_=0 # R CMD CHECK R CMD check ${PKG_TARBALL} \ --as-cran \ -|| exit -1 +|| cat /home/travis/build/jameslamb/LightGBM/lightgbm.Rcheck/00install.out + +exit -1 if grep -q -R "WARNING" "$LOG_FILE_NAME"; then echo "WARNINGS have been found by R CMD check!" From 3ffa91b6b506aef1adccf2ce5443fdb316ec283f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 23:55:09 -0500 Subject: [PATCH 11/28] tried ignoring --- R-package/.Rbuildignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R-package/.Rbuildignore b/R-package/.Rbuildignore index 309a82858cbc..6f9097d231d6 100644 --- a/R-package/.Rbuildignore +++ b/R-package/.Rbuildignore @@ -12,6 +12,8 @@ # Code copied in at build time ^src/CMakeLists.txt$ +^CMakeCache.txt$ +^src/CMakeCache.txt$ # unnecessary files from submodules ^src/compute/.appveyor.yml$ From 1875977754a2db9cedb0a038f7c7c62a78d0d7e9 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 00:17:32 -0500 Subject: [PATCH 12/28] added error message to confirm a suspicion --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2f3c7c0cacfd..a998ce6cf04e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: # - TASK=sdist PYTHON_VERSION=2.7 # - TASK=bdist # - TASK=if-else - - TASK=lint + # - TASK=lint # - TASK=check-docs # - TASK=mpi METHOD=source # - TASK=mpi METHOD=pip From 5a56d5e3379b078d009c53d90b5f7e2ab9efe41c Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 09:49:01 -0500 Subject: [PATCH 13/28] restore full CI --- .ci/test_r_package.sh | 4 +--- .travis.yml | 20 ++++++++++---------- R-package/.Rbuildignore | 2 -- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index 8828451650bf..0e660ba8581b 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -84,9 +84,7 @@ export _R_CHECK_FORCE_SUGGESTS_=0 # R CMD CHECK R CMD check ${PKG_TARBALL} \ --as-cran \ -|| cat /home/travis/build/jameslamb/LightGBM/lightgbm.Rcheck/00install.out - -exit -1 +|| exit -1 if grep -q -R "WARNING" "$LOG_FILE_NAME"; then echo "WARNINGS have been found by R CMD check!" diff --git a/.travis.yml b/.travis.yml index a998ce6cf04e..bbd72bb9b207 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,16 +14,16 @@ env: global: # default values - PYTHON_VERSION=3.7 matrix: - # - TASK=regular PYTHON_VERSION=3.6 - # - TASK=sdist PYTHON_VERSION=2.7 - # - TASK=bdist - # - TASK=if-else - # - TASK=lint - # - TASK=check-docs - # - TASK=mpi METHOD=source - # - TASK=mpi METHOD=pip - # - TASK=gpu METHOD=source PYTHON_VERSION=3.5 - # - TASK=gpu METHOD=pip PYTHON_VERSION=3.6 + - TASK=regular PYTHON_VERSION=3.6 + - TASK=sdist PYTHON_VERSION=2.7 + - TASK=bdist + - TASK=if-else + - TASK=lint + - TASK=check-docs + - TASK=mpi METHOD=source + - TASK=mpi METHOD=pip + - TASK=gpu METHOD=source PYTHON_VERSION=3.5 + - TASK=gpu METHOD=pip PYTHON_VERSION=3.6 - TASK=r-package matrix: diff --git a/R-package/.Rbuildignore b/R-package/.Rbuildignore index 6f9097d231d6..309a82858cbc 100644 --- a/R-package/.Rbuildignore +++ b/R-package/.Rbuildignore @@ -12,8 +12,6 @@ # Code copied in at build time ^src/CMakeLists.txt$ -^CMakeCache.txt$ -^src/CMakeCache.txt$ # unnecessary files from submodules ^src/compute/.appveyor.yml$ From 2eefb1821f5257fe4360d18634892b7105c78c11 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 11 Mar 2020 22:42:30 -0500 Subject: [PATCH 14/28] [R-package] started adding routine registration in R package --- src/lightgbm_R.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index 1c8c52324661..04018417a928 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -656,3 +656,16 @@ LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, EncodeChar(out_str, inner_char_buf.data(), buffer_len, actual_len, static_cast(out_len)); R_API_END(); } + +// .Call() calls +#include + +static const R_CallMethodDef CallEntries[] = { + {"LGBM_BoosterDumpModel_R", (DL_FUNC) &LGBM_BoosterDumpModel_R, 6}, + {NULL, NULL, 0} +}; + +void R_init_lightgbm(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} From 34f04e959ceec5479f2cc358e460caa4ca76e310 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 14:17:57 -0500 Subject: [PATCH 15/28] more registrations --- CMakeLists.txt | 9 ++++++++- R-package/.Rbuildignore | 1 + src/lightgbm_R.cpp | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c05b833262f1..ea296f97bad4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,7 +235,14 @@ file(GLOB SOURCES ) add_executable(lightgbm src/main.cpp ${SOURCES}) -add_library(_lightgbm SHARED src/c_api.cpp src/lightgbm_R.cpp ${SOURCES}) + +# Only build the R part of the library if building for +# use with the R package +if(BUILD_FOR_R) + add_library(_lightgbm SHARED src/c_api.cpp src/lightgbm_R.cpp ${SOURCES}) +else() + add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES}) +endif(BUILD_FOR_R) if(MSVC) set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") diff --git a/R-package/.Rbuildignore b/R-package/.Rbuildignore index 309a82858cbc..f40fc91f7b71 100644 --- a/R-package/.Rbuildignore +++ b/R-package/.Rbuildignore @@ -12,6 +12,7 @@ # Code copied in at build time ^src/CMakeLists.txt$ +^Makefile$ # unnecessary files from submodules ^src/compute/.appveyor.yml$ diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index 04018417a928..e12d0a071a7d 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -661,6 +661,7 @@ LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, #include static const R_CallMethodDef CallEntries[] = { + {"LGBM_BoosterSaveModelToString_R", (DL_FUNC) &LGBM_BoosterSaveModelToString_R, 6} {"LGBM_BoosterDumpModel_R", (DL_FUNC) &LGBM_BoosterDumpModel_R, 6}, {NULL, NULL, 0} }; From 3031bf285cf5e06402c4814d9b6a5ae8276f9dab Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 20:21:44 -0500 Subject: [PATCH 16/28] added all functions --- src/lightgbm_R.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index e12d0a071a7d..e06d32ccc210 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -661,8 +661,47 @@ LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, #include static const R_CallMethodDef CallEntries[] = { - {"LGBM_BoosterSaveModelToString_R", (DL_FUNC) &LGBM_BoosterSaveModelToString_R, 6} - {"LGBM_BoosterDumpModel_R", (DL_FUNC) &LGBM_BoosterDumpModel_R, 6}, + {"LGBM_GetLastError_R" , (DL_FUNC) &LGBM_GetLastError_R , 3}, + {"LGBM_DatasetCreateFromFile_R" , (DL_FUNC) &LGBM_DatasetCreateFromFile_R , 5}, + {"LGBM_DatasetCreateFromCSC_R" , (DL_FUNC) &LGBM_DatasetCreateFromCSC_R , 10}, + {"LGBM_DatasetCreateFromMat_R" , (DL_FUNC) &LGBM_DatasetCreateFromMat_R , 7}, + {"LGBM_DatasetGetSubset_R" , (DL_FUNC) &LGBM_DatasetGetSubset_R , 6}, + {"LGBM_DatasetSetFeatureNames_R" , (DL_FUNC) &LGBM_DatasetSetFeatureNames_R , 3}, + {"LGBM_DatasetGetFeatureNames_R" , (DL_FUNC) &LGBM_DatasetGetFeatureNames_R , 5}, + {"LGBM_DatasetSaveBinary_R" , (DL_FUNC) &LGBM_DatasetSaveBinary_R , 3}, + {"LGBM_DatasetFree_R" , (DL_FUNC) &LGBM_DatasetFree_R , 2}, + {"LGBM_DatasetSetField_R" , (DL_FUNC) &LGBM_DatasetSetField_R , 5}, + {"LGBM_DatasetGetFieldSize_R" , (DL_FUNC) &LGBM_DatasetGetFieldSize_R , 4}, + {"LGBM_DatasetGetField_R" , (DL_FUNC) &LGBM_DatasetGetField_R , 4}, + {"LGBM_DatasetUpdateParamChecking_R", (DL_FUNC) &LGBM_DatasetUpdateParamChecking_R, 3}, + {"LGBM_DatasetGetNumData_R" , (DL_FUNC) &LGBM_DatasetGetNumData_R , 3}, + {"LGBM_DatasetGetNumFeature_R" , (DL_FUNC) &LGBM_DatasetGetNumFeature_R , 3}, + {"LGBM_BoosterCreate_R" , (DL_FUNC) &LGBM_BoosterCreate_R , 4}, + {"LGBM_BoosterFree_R" , (DL_FUNC) &LGBM_BoosterFree_R , 2}, + {"LGBM_BoosterCreateFromModelfile_R", (DL_FUNC) &LGBM_BoosterCreateFromModelfile_R, 3}, + {"LGBM_BoosterLoadModelFromString_R", (DL_FUNC) &LGBM_BoosterLoadModelFromString_R, 3}, + {"LGBM_BoosterMerge_R" , (DL_FUNC) &LGBM_BoosterMerge_R , 3}, + {"LGBM_BoosterAddValidData_R" , (DL_FUNC) &LGBM_BoosterAddValidData_R , 3}, + {"LGBM_BoosterResetTrainingData_R" , (DL_FUNC) &LGBM_BoosterResetTrainingData_R , 3}, + {"LGBM_BoosterResetParameter_R" , (DL_FUNC) &LGBM_BoosterResetParameter_R , 3}, + {"LGBM_BoosterGetNumClasses_R" , (DL_FUNC) &LGBM_BoosterGetNumClasses_R , 3}, + {"LGBM_BoosterUpdateOneIter_R" , (DL_FUNC) &LGBM_BoosterUpdateOneIter_R , 2}, + {"LGBM_BoosterUpdateOneIterCustom_R", (DL_FUNC) &LGBM_BoosterUpdateOneIterCustom_R, 5}, + {"LGBM_BoosterRollbackOneIter_R" , (DL_FUNC) &LGBM_BoosterRollbackOneIter_R , 2}, + {"LGBM_BoosterGetCurrentIteration_R", (DL_FUNC) &LGBM_BoosterGetCurrentIteration_R, 3}, + {"LGBM_BoosterGetUpperBoundValue_R" , (DL_FUNC) &LGBM_BoosterGetUpperBoundValue_R , 3}, + {"LGBM_BoosterGetLowerBoundValue_R" , (DL_FUNC) &LGBM_BoosterGetLowerBoundValue_R , 3}, + {"LGBM_BoosterGetEvalNames_R" , (DL_FUNC) &LGBM_BoosterGetEvalNames_R , 5}, + {"LGBM_BoosterGetEval_R" , (DL_FUNC) &LGBM_BoosterGetEval_R , 4}, + {"LGBM_BoosterGetNumPredict_R" , (DL_FUNC) &LGBM_BoosterGetNumPredict_R , 4}, + {"LGBM_BoosterGetPredict_R" , (DL_FUNC) &LGBM_BoosterGetPredict_R , 4}, + {"LGBM_BoosterPredictForFile_R" , (DL_FUNC) &LGBM_BoosterPredictForFile_R , 10}, + {"LGBM_BoosterCalcNumPredict_R" , (DL_FUNC) &LGBM_BoosterCalcNumPredict_R , 8}, + {"LGBM_BoosterPredictForCSC_R" , (DL_FUNC) &LGBM_BoosterPredictForCSC_R , 14}, + {"LGBM_BoosterPredictForMat_R" , (DL_FUNC) &LGBM_BoosterPredictForMat_R , 11}, + {"LGBM_BoosterSaveModel_R" , (DL_FUNC) &LGBM_BoosterSaveModel_R , 4}, + {"LGBM_BoosterSaveModelToString_R" , (DL_FUNC) &LGBM_BoosterSaveModelToString_R , 6}, + {"LGBM_BoosterDumpModel_R" , (DL_FUNC) &LGBM_BoosterDumpModel_R , 6}, {NULL, NULL, 0} }; From cd420517499ae33b1200929eac8201dbfa5e935d Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 22:29:24 -0500 Subject: [PATCH 17/28] Eliminated note about registering routines --- R-package/.Rbuildignore | 15 +- R-package/src/install.libs.R | 10 +- include/LightGBM/R_object_helper.h | 14 +- include/LightGBM/lightgbm_R.h | 460 +++++++++++++++-------------- src/lightgbm_R.cpp | 372 +++++++++++------------ 5 files changed, 446 insertions(+), 425 deletions(-) diff --git a/R-package/.Rbuildignore b/R-package/.Rbuildignore index f40fc91f7b71..51f94f068356 100644 --- a/R-package/.Rbuildignore +++ b/R-package/.Rbuildignore @@ -4,21 +4,24 @@ ^pkgdown$ # Objects created by compilation -\.o$ -\.so$ -\.dll$ -\.out$ -\.bin$ +^.*\.o +^.*\.so +^.*\.dll +^.*\.out +^.*\.bin # Code copied in at build time ^src/CMakeLists.txt$ ^Makefile$ +# ^src/build/Makefile$ +# ^src/build/CMakeFiles/.*$ +^src/build/.*$ # unnecessary files from submodules ^src/compute/.appveyor.yml$ ^src/compute/.coveralls.yml$ ^src/compute/.travis.yml$ -^src/compute/test/$ +^src/compute/test/.*$ ^src/compute/index.html$ ^src/compute/.git$ ^src/compute/.gitignore$ diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index f6d2335b2cd8..98a075d82e94 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -163,12 +163,20 @@ if (!use_precompile) { } } -# Check installation correctness +# Packages with install.libs.R need to copy some artifacts into the +# expected places in the package structure. +# see https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Package-subdirectories, +# especially the paragraph on install.libs.R dest <- file.path(R_PACKAGE_DIR, paste0("libs", R_ARCH), fsep = "/") dir.create(dest, recursive = TRUE, showWarnings = FALSE) if (file.exists(src)) { print(paste0("Found library file: ", src, " to move to ", dest)) file.copy(src, dest, overwrite = TRUE) + + symbols_file <- file.path(R_PACKAGE_SOURCE, "src", "symbols.rds") + if (file.exists(symbols_file)){ + file.copy(symbols_file, dest, overwrite = TRUE) + } } else { stop(paste0("Cannot find lib_lightgbm", SHLIB_EXT)) } diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index a3cf2f32ea77..20efc1ed1a58 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -15,6 +15,12 @@ #include +#ifdef LGB_R_BUILD + #define R_NO_REMAP + #define R_USE_C99_IN_CXX + #include +#endif + #define TYPE_BITS 5 // use .Internal(internalsID()) to uuid #define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327" @@ -145,7 +151,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(LGBM_SE x, void* ptr) { + inline void R_SET_PTR(SEXP x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int64_t)(NULL); } else { @@ -153,7 +159,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(LGBM_SE x) { + inline void* R_GET_PTR(SEXP x) { if (R_IS_NULL(x)) { return nullptr; } else { @@ -169,7 +175,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(LGBM_SE x, void* ptr) { + inline void R_SET_PTR(SEXP x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int32_t)(NULL); } else { @@ -177,7 +183,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(LGBM_SE x) { + inline void* R_GET_PTR(SEXP x) { if (R_IS_NULL(x)) { return nullptr; } else { diff --git a/include/LightGBM/lightgbm_R.h b/include/LightGBM/lightgbm_R.h index 076ea2946384..02c9490770c6 100644 --- a/include/LightGBM/lightgbm_R.h +++ b/include/LightGBM/lightgbm_R.h @@ -8,6 +8,10 @@ #include #include +#define R_NO_REMAP +#define R_USE_C99_IN_CXX +#include + /*! * \brief get string message of the last error * all functions in this file will return 0 on success @@ -15,10 +19,10 @@ * \return err_msg error information * \return error information */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE err_msg +LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( + SEXP buf_len, + SEXP actual_len, + SEXP err_msg ); // --- start Dataset interface @@ -31,12 +35,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( - LGBM_SE filename, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( + SEXP filename, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -52,17 +56,17 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE nindptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( + SEXP indptr, + SEXP indices, + SEXP data, + SEXP nindptr, + SEXP nelem, + SEXP num_row, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -75,14 +79,14 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( - LGBM_SE data, - LGBM_SE nrow, - LGBM_SE ncol, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( + SEXP data, + SEXP nrow, + SEXP ncol, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state ); /*! @@ -94,13 +98,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( - LGBM_SE handle, - LGBM_SE used_row_indices, - LGBM_SE len_used_row_indices, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( + SEXP handle, + SEXP used_row_indices, + SEXP len_used_row_indices, + SEXP parameters, + SEXP out, + SEXP call_state ); /*! @@ -109,10 +113,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( - LGBM_SE handle, - LGBM_SE feature_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( + SEXP handle, + SEXP feature_names, + SEXP call_state ); /*! @@ -121,12 +125,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( - LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE feature_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( + SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP feature_names, + SEXP call_state ); /*! @@ -135,10 +139,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( - LGBM_SE handle, - LGBM_SE filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( + SEXP handle, + SEXP filename, + SEXP call_state ); /*! @@ -146,9 +150,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( * \param handle an instance of dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( + SEXP handle, + SEXP call_state ); /*! @@ -161,12 +165,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( * \param num_element number of element in field_data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE num_element, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( + SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP num_element, + SEXP call_state ); /*! @@ -176,11 +180,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( * \param out size of info vector from dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( + SEXP handle, + SEXP field_name, + SEXP out, + SEXP call_state ); /*! @@ -190,11 +194,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( * \param field_data pointer to vector * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( - LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( + SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP call_state ); /*! @@ -203,10 +207,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( * \param new_params New dataset parameters * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( - LGBM_SE old_params, - LGBM_SE new_params, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( + SEXP old_params, + SEXP new_params, + SEXP call_state ); /*! @@ -215,10 +219,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( * \param out The address to hold number of data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -227,10 +231,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( * \param out The output of number of features * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( + SEXP handle, + SEXP out, + SEXP call_state ); // --- start Booster interfaces @@ -242,11 +246,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( - LGBM_SE train_data, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( + SEXP train_data, + SEXP parameters, + SEXP out, + SEXP call_state ); /*! @@ -254,9 +258,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( * \param handle handle to be freed * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( + SEXP handle, + SEXP call_state ); /*! @@ -265,10 +269,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( - LGBM_SE filename, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( + SEXP filename, + SEXP out, + SEXP call_state ); /*! @@ -277,10 +281,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( - LGBM_SE model_str, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( + SEXP model_str, + SEXP out, + SEXP call_state ); /*! @@ -289,10 +293,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( * \param other_handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( - LGBM_SE handle, - LGBM_SE other_handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( + SEXP handle, + SEXP other_handle, + SEXP call_state ); /*! @@ -301,10 +305,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( * \param valid_data validation data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( - LGBM_SE handle, - LGBM_SE valid_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( + SEXP handle, + SEXP valid_data, + SEXP call_state ); /*! @@ -313,10 +317,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( * \param train_data training data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( - LGBM_SE handle, - LGBM_SE train_data, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( + SEXP handle, + SEXP train_data, + SEXP call_state ); /*! @@ -325,10 +329,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( * \param parameters format: 'key1=value1 key2=value2' * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( - LGBM_SE handle, - LGBM_SE parameters, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( + SEXP handle, + SEXP parameters, + SEXP call_state ); /*! @@ -337,10 +341,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( * \param out number of classes * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -348,9 +352,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( + SEXP handle, + SEXP call_state ); /*! @@ -362,12 +366,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( * \param len length of grad/hess * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( - LGBM_SE handle, - LGBM_SE grad, - LGBM_SE hess, - LGBM_SE len, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( + SEXP handle, + SEXP grad, + SEXP hess, + SEXP len, + SEXP call_state ); /*! @@ -375,9 +379,9 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( - LGBM_SE handle, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( + SEXP handle, + SEXP call_state ); /*! @@ -385,10 +389,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( * \param out iteration of boosting rounds * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( - LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( + SEXP handle, + SEXP out, + SEXP call_state ); /*! @@ -397,10 +401,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( * \param[out] out_results Result pointing to max value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( - LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( + SEXP handle, + SEXP out_result, + SEXP call_state ); /*! @@ -409,10 +413,10 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( * \param[out] out_results Result pointing to min value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( - LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( + SEXP handle, + SEXP out_result, + SEXP call_state ); /*! @@ -420,12 +424,12 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( * \param eval_names eval names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( - LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE eval_names, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( + SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP eval_names, + SEXP call_state ); /*! @@ -435,11 +439,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( * \param out_result float array contains result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( + SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state ); /*! @@ -449,11 +453,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( * \param out size of predict * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( + SEXP handle, + SEXP data_idx, + SEXP out, + SEXP call_state ); /*! @@ -464,11 +468,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( * \param out_result, used to store predict result, should pre-allocate memory * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( - LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( + SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state ); /*! @@ -482,17 +486,17 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( * \return 0 when succeed, -1 when failure happens * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( - LGBM_SE handle, - LGBM_SE data_filename, - LGBM_SE data_has_header, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE result_filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( + SEXP handle, + SEXP data_filename, + SEXP data_has_header, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP result_filename, + SEXP call_state ); /*! @@ -505,15 +509,15 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( * \param out_len length of prediction * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( - LGBM_SE handle, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE out_len, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( + SEXP handle, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP out_len, + SEXP call_state ); /*! @@ -534,21 +538,21 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( - LGBM_SE handle, - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE nindptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( + SEXP handle, + SEXP indptr, + SEXP indices, + SEXP data, + SEXP nindptr, + SEXP nelem, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state ); /*! @@ -566,18 +570,18 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( - LGBM_SE handle, - LGBM_SE data, - LGBM_SE nrow, - LGBM_SE ncol, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( + SEXP handle, + SEXP data, + SEXP nrow, + SEXP ncol, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state ); /*! @@ -587,11 +591,11 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE filename, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( + SEXP handle, + SEXP num_iteration, + SEXP filename, + SEXP call_state ); /*! @@ -601,13 +605,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( * \param out_str string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( + SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state ); /*! @@ -617,13 +621,13 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( * \param out_str json format string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R( - LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state +LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R( + SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state ); #endif // LIGHTGBM_R_H_ diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index e06d32ccc210..98daaca45112 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -36,7 +36,7 @@ using LightGBM::Common::Join; using LightGBM::Common::Split; using LightGBM::Log; -LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actual_len, size_t str_len) { +SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_t str_len) { if (str_len > INT32_MAX) { Log::Fatal("Don't support large string in R-package"); } @@ -49,15 +49,15 @@ LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actua return dest; } -LGBM_SE LGBM_GetLastError_R(LGBM_SE buf_len, LGBM_SE actual_len, LGBM_SE err_msg) { +SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg) { return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1); } -LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); DatasetHandle handle = nullptr; CHECK_CALL(LGBM_DatasetCreateFromFile(R_CHAR_PTR(filename), R_CHAR_PTR(parameters), @@ -66,16 +66,16 @@ LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, R_API_END(); } -LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE num_indptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, + SEXP indices, + SEXP data, + SEXP num_indptr, + SEXP nelem, + SEXP num_row, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); const int* p_indptr = R_INT_PTR(indptr); const int* p_indices = R_INT_PTR(indices); @@ -92,13 +92,13 @@ LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, R_API_END(); } -LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, - LGBM_SE num_row, - LGBM_SE num_col, - LGBM_SE parameters, - LGBM_SE reference, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetCreateFromMat_R(SEXP data, + SEXP num_row, + SEXP num_col, + SEXP parameters, + SEXP reference, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int32_t nrow = static_cast(R_AS_INT(num_row)); int32_t ncol = static_cast(R_AS_INT(num_col)); @@ -110,12 +110,12 @@ LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, R_API_END(); } -LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, - LGBM_SE used_row_indices, - LGBM_SE len_used_row_indices, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetSubset_R(SEXP handle, + SEXP used_row_indices, + SEXP len_used_row_indices, + SEXP parameters, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int len = R_AS_INT(len_used_row_indices); std::vector idxvec(len); @@ -132,9 +132,9 @@ LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, - LGBM_SE feature_names, - LGBM_SE call_state) { +SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, + SEXP feature_names, + SEXP call_state) { R_API_BEGIN(); auto vec_names = Split(R_CHAR_PTR(feature_names), '\t'); std::vector vec_sptr; @@ -147,11 +147,11 @@ LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE feature_names, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP feature_names, + SEXP call_state) { R_API_BEGIN(); int len = 0; CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &len)); @@ -170,17 +170,17 @@ LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSaveBinary_R(LGBM_SE handle, - LGBM_SE filename, - LGBM_SE call_state) { +SEXP LGBM_DatasetSaveBinary_R(SEXP handle, + SEXP filename, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetSaveBinary(R_GET_PTR(handle), R_CHAR_PTR(filename))); R_API_END(); } -LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_DatasetFree_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_DatasetFree(R_GET_PTR(handle))); @@ -189,11 +189,11 @@ LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE num_element, - LGBM_SE call_state) { +SEXP LGBM_DatasetSetField_R(SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP num_element, + SEXP call_state) { R_API_BEGIN(); int len = static_cast(R_AS_INT(num_element)); const char* name = R_CHAR_PTR(field_name); @@ -217,10 +217,10 @@ LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE field_data, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetField_R(SEXP handle, + SEXP field_name, + SEXP field_data, + SEXP call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -251,10 +251,10 @@ LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, - LGBM_SE field_name, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, + SEXP field_name, + SEXP out, + SEXP call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -268,16 +268,16 @@ LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_DatasetUpdateParamChecking_R(LGBM_SE old_params, - LGBM_SE new_params, - LGBM_SE call_state) { +SEXP LGBM_DatasetUpdateParamChecking_R(SEXP old_params, + SEXP new_params, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetUpdateParamChecking(R_CHAR_PTR(old_params), R_CHAR_PTR(new_params))); R_API_END(); } -LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, + SEXP call_state) { int nrow; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumData(R_GET_PTR(handle), &nrow)); @@ -285,9 +285,9 @@ LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, R_API_END(); } -LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, + SEXP out, + SEXP call_state) { int nfeature; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &nfeature)); @@ -297,8 +297,8 @@ LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, // --- start Booster interfaces -LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterFree_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_BoosterFree(R_GET_PTR(handle))); @@ -307,10 +307,10 @@ LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, - LGBM_SE parameters, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterCreate_R(SEXP train_data, + SEXP parameters, + SEXP out, + SEXP call_state) { R_API_BEGIN(); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreate(R_GET_PTR(train_data), R_CHAR_PTR(parameters), &handle)); @@ -318,9 +318,9 @@ LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, R_API_END(); } -LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -329,9 +329,9 @@ LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, R_API_END(); } -LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -340,41 +340,41 @@ LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, R_API_END(); } -LGBM_SE LGBM_BoosterMerge_R(LGBM_SE handle, - LGBM_SE other_handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterMerge_R(SEXP handle, + SEXP other_handle, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterMerge(R_GET_PTR(handle), R_GET_PTR(other_handle))); R_API_END(); } -LGBM_SE LGBM_BoosterAddValidData_R(LGBM_SE handle, - LGBM_SE valid_data, - LGBM_SE call_state) { +SEXP LGBM_BoosterAddValidData_R(SEXP handle, + SEXP valid_data, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterAddValidData(R_GET_PTR(handle), R_GET_PTR(valid_data))); R_API_END(); } -LGBM_SE LGBM_BoosterResetTrainingData_R(LGBM_SE handle, - LGBM_SE train_data, - LGBM_SE call_state) { +SEXP LGBM_BoosterResetTrainingData_R(SEXP handle, + SEXP train_data, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetTrainingData(R_GET_PTR(handle), R_GET_PTR(train_data))); R_API_END(); } -LGBM_SE LGBM_BoosterResetParameter_R(LGBM_SE handle, - LGBM_SE parameters, - LGBM_SE call_state) { +SEXP LGBM_BoosterResetParameter_R(SEXP handle, + SEXP parameters, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetParameter(R_GET_PTR(handle), R_CHAR_PTR(parameters))); R_API_END(); } -LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, + SEXP out, + SEXP call_state) { int num_class; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetNumClasses(R_GET_PTR(handle), &num_class)); @@ -382,19 +382,19 @@ LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterUpdateOneIter_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterUpdateOneIter_R(SEXP handle, + SEXP call_state) { int is_finished = 0; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterUpdateOneIter(R_GET_PTR(handle), &is_finished)); R_API_END(); } -LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, - LGBM_SE grad, - LGBM_SE hess, - LGBM_SE len, - LGBM_SE call_state) { +SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, + SEXP grad, + SEXP hess, + SEXP len, + SEXP call_state) { int is_finished = 0; R_API_BEGIN(); int int_len = R_AS_INT(len); @@ -408,16 +408,16 @@ LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle, - LGBM_SE call_state) { +SEXP LGBM_BoosterRollbackOneIter_R(SEXP handle, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterRollbackOneIter(R_GET_PTR(handle))); R_API_END(); } -LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, + SEXP out, + SEXP call_state) { int out_iteration; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetCurrentIteration(R_GET_PTR(handle), &out_iteration)); @@ -425,29 +425,29 @@ LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetUpperBoundValue_R(LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetUpperBoundValue_R(SEXP handle, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetUpperBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -LGBM_SE LGBM_BoosterGetLowerBoundValue_R(LGBM_SE handle, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetLowerBoundValue_R(SEXP handle, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetLowerBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, - LGBM_SE buf_len, - LGBM_SE actual_len, - LGBM_SE eval_names, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, + SEXP buf_len, + SEXP actual_len, + SEXP eval_names, + SEXP call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -475,10 +475,10 @@ LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetEval_R(SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -489,10 +489,10 @@ LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, + SEXP data_idx, + SEXP out, + SEXP call_state) { R_API_BEGIN(); int64_t len; CHECK_CALL(LGBM_BoosterGetNumPredict(R_GET_PTR(handle), R_AS_INT(data_idx), &len)); @@ -500,10 +500,10 @@ LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, - LGBM_SE data_idx, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterGetPredict_R(SEXP handle, + SEXP data_idx, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); int64_t out_len; @@ -511,7 +511,7 @@ LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, R_API_END(); } -int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontrib) { +int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { int pred_type = C_API_PREDICT_NORMAL; if (R_AS_INT(is_rawscore)) { pred_type = C_API_PREDICT_RAW_SCORE; @@ -525,16 +525,16 @@ int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontr return pred_type; } -LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, - LGBM_SE data_filename, - LGBM_SE data_has_header, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE result_filename, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForFile_R(SEXP handle, + SEXP data_filename, + SEXP data_has_header, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP result_filename, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); CHECK_CALL(LGBM_BoosterPredictForFile(R_GET_PTR(handle), R_CHAR_PTR(data_filename), @@ -543,14 +543,14 @@ LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE out_len, - LGBM_SE call_state) { +SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP out_len, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); int64_t len = 0; @@ -560,20 +560,20 @@ LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, - LGBM_SE indptr, - LGBM_SE indices, - LGBM_SE data, - LGBM_SE num_indptr, - LGBM_SE nelem, - LGBM_SE num_row, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, + SEXP indptr, + SEXP indices, + SEXP data, + SEXP num_indptr, + SEXP nelem, + SEXP num_row, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -593,17 +593,17 @@ LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, - LGBM_SE data, - LGBM_SE num_row, - LGBM_SE num_col, - LGBM_SE is_rawscore, - LGBM_SE is_leafidx, - LGBM_SE is_predcontrib, - LGBM_SE num_iteration, - LGBM_SE parameter, - LGBM_SE out_result, - LGBM_SE call_state) { +SEXP LGBM_BoosterPredictForMat_R(SEXP handle, + SEXP data, + SEXP num_row, + SEXP num_col, + SEXP is_rawscore, + SEXP is_leafidx, + SEXP is_predcontrib, + SEXP num_iteration, + SEXP parameter, + SEXP out_result, + SEXP call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -620,21 +620,21 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterSaveModel_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE filename, - LGBM_SE call_state) { +SEXP LGBM_BoosterSaveModel_R(SEXP handle, + SEXP num_iteration, + SEXP filename, + SEXP call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_CHAR_PTR(filename))); R_API_END(); } -LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state) { +SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); @@ -643,12 +643,12 @@ LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, R_API_END(); } -LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, - LGBM_SE num_iteration, - LGBM_SE buffer_len, - LGBM_SE actual_len, - LGBM_SE out_str, - LGBM_SE call_state) { +SEXP LGBM_BoosterDumpModel_R(SEXP handle, + SEXP num_iteration, + SEXP buffer_len, + SEXP actual_len, + SEXP out_str, + SEXP call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); From b2ace3b580ad5b3ce05dbe7dca81c3ffa5d7e7c6 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 22:46:29 -0500 Subject: [PATCH 18/28] started cleaning up --- R-package/.Rbuildignore | 2 -- R-package/src/install.libs.R | 1 + src/lightgbm_R.cpp | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/R-package/.Rbuildignore b/R-package/.Rbuildignore index 51f94f068356..3a542101392a 100644 --- a/R-package/.Rbuildignore +++ b/R-package/.Rbuildignore @@ -13,8 +13,6 @@ # Code copied in at build time ^src/CMakeLists.txt$ ^Makefile$ -# ^src/build/Makefile$ -# ^src/build/CMakeFiles/.*$ ^src/build/.*$ # unnecessary files from submodules diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 98a075d82e94..592f9f3fd3ee 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -177,6 +177,7 @@ if (file.exists(src)) { if (file.exists(symbols_file)){ file.copy(symbols_file, dest, overwrite = TRUE) } + } else { stop(paste0("Cannot find lib_lightgbm", SHLIB_EXT)) } diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index 98daaca45112..c292a93dc3c9 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -16,6 +16,8 @@ #include #include +#include + #define COL_MAJOR (0) #define R_API_BEGIN() \ @@ -658,8 +660,6 @@ SEXP LGBM_BoosterDumpModel_R(SEXP handle, } // .Call() calls -#include - static const R_CallMethodDef CallEntries[] = { {"LGBM_GetLastError_R" , (DL_FUNC) &LGBM_GetLastError_R , 3}, {"LGBM_DatasetCreateFromFile_R" , (DL_FUNC) &LGBM_DatasetCreateFromFile_R , 5}, From 060ee940943abad954016309cde3218def3e7e04 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 23:15:48 -0500 Subject: [PATCH 19/28] reverted SEXP stuff --- include/LightGBM/R_object_helper.h | 8 +- include/LightGBM/lightgbm_R.h | 456 ++++++++++++++--------------- src/lightgbm_R.cpp | 372 +++++++++++------------ 3 files changed, 418 insertions(+), 418 deletions(-) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index 20efc1ed1a58..a5e9c5d61604 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -151,7 +151,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(SEXP x, void* ptr) { + inline void R_SET_PTR(LGBM_SE x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int64_t)(NULL); } else { @@ -159,7 +159,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(SEXP x) { + inline void* R_GET_PTR(LGBM_SE x) { if (R_IS_NULL(x)) { return nullptr; } else { @@ -175,7 +175,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; #define R_ADDR(x) (reinterpret_cast DATAPTR(x)) - inline void R_SET_PTR(SEXP x, void* ptr) { + inline void R_SET_PTR(LGBM_SE x, void* ptr) { if (ptr == nullptr) { R_ADDR(x)[0] = (int32_t)(NULL); } else { @@ -183,7 +183,7 @@ typedef union { VECTOR_SER s; double align; } SEXPREC_ALIGN; } } - inline void* R_GET_PTR(SEXP x) { + inline void* R_GET_PTR(LGBM_SE x) { if (R_IS_NULL(x)) { return nullptr; } else { diff --git a/include/LightGBM/lightgbm_R.h b/include/LightGBM/lightgbm_R.h index 02c9490770c6..2ac05384d87e 100644 --- a/include/LightGBM/lightgbm_R.h +++ b/include/LightGBM/lightgbm_R.h @@ -19,10 +19,10 @@ * \return err_msg error information * \return error information */ -LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( - SEXP buf_len, - SEXP actual_len, - SEXP err_msg +LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R( + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE err_msg ); // --- start Dataset interface @@ -35,12 +35,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( - SEXP filename, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R( + LGBM_SE filename, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -56,17 +56,17 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( - SEXP indptr, - SEXP indices, - SEXP data, - SEXP nindptr, - SEXP nelem, - SEXP num_row, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R( + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE nindptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -79,14 +79,14 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( - SEXP data, - SEXP nrow, - SEXP ncol, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R( + LGBM_SE data, + LGBM_SE nrow, + LGBM_SE ncol, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -98,13 +98,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R( * \param out created dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( - SEXP handle, - SEXP used_row_indices, - SEXP len_used_row_indices, - SEXP parameters, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R( + LGBM_SE handle, + LGBM_SE used_row_indices, + LGBM_SE len_used_row_indices, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -113,10 +113,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( - SEXP handle, - SEXP feature_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R( + LGBM_SE handle, + LGBM_SE feature_names, + LGBM_SE call_state ); /*! @@ -125,12 +125,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R( * \param feature_names feature names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( - SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP feature_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R( + LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE feature_names, + LGBM_SE call_state ); /*! @@ -139,10 +139,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( - SEXP handle, - SEXP filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R( + LGBM_SE handle, + LGBM_SE filename, + LGBM_SE call_state ); /*! @@ -150,9 +150,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R( * \param handle an instance of dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -165,12 +165,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R( * \param num_element number of element in field_data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( - SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP num_element, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE num_element, + LGBM_SE call_state ); /*! @@ -180,11 +180,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R( * \param out size of info vector from dataset * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( - SEXP handle, - SEXP field_name, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -194,11 +194,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R( * \param field_data pointer to vector * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( - SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R( + LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE call_state ); /*! @@ -207,10 +207,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R( * \param new_params New dataset parameters * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( - SEXP old_params, - SEXP new_params, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R( + LGBM_SE old_params, + LGBM_SE new_params, + LGBM_SE call_state ); /*! @@ -219,10 +219,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R( * \param out The address to hold number of data * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -231,10 +231,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R( * \param out The output of number of features * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); // --- start Booster interfaces @@ -246,11 +246,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( - SEXP train_data, - SEXP parameters, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R( + LGBM_SE train_data, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -258,9 +258,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R( * \param handle handle to be freed * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -269,10 +269,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( - SEXP filename, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R( + LGBM_SE filename, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -281,10 +281,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R( * \param out handle of created Booster * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( - SEXP model_str, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R( + LGBM_SE model_str, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -293,10 +293,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R( * \param other_handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( - SEXP handle, - SEXP other_handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R( + LGBM_SE handle, + LGBM_SE other_handle, + LGBM_SE call_state ); /*! @@ -305,10 +305,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R( * \param valid_data validation data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( - SEXP handle, - SEXP valid_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R( + LGBM_SE handle, + LGBM_SE valid_data, + LGBM_SE call_state ); /*! @@ -317,10 +317,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R( * \param train_data training data set * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( - SEXP handle, - SEXP train_data, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R( + LGBM_SE handle, + LGBM_SE train_data, + LGBM_SE call_state ); /*! @@ -329,10 +329,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R( * \param parameters format: 'key1=value1 key2=value2' * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( - SEXP handle, - SEXP parameters, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R( + LGBM_SE handle, + LGBM_SE parameters, + LGBM_SE call_state ); /*! @@ -341,10 +341,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R( * \param out number of classes * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -352,9 +352,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -366,12 +366,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R( * \param len length of grad/hess * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( - SEXP handle, - SEXP grad, - SEXP hess, - SEXP len, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R( + LGBM_SE handle, + LGBM_SE grad, + LGBM_SE hess, + LGBM_SE len, + LGBM_SE call_state ); /*! @@ -379,9 +379,9 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R( * \param handle handle * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( - SEXP handle, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R( + LGBM_SE handle, + LGBM_SE call_state ); /*! @@ -389,10 +389,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R( * \param out iteration of boosting rounds * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( - SEXP handle, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R( + LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -401,10 +401,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R( * \param[out] out_results Result pointing to max value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( - SEXP handle, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R( + LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -413,10 +413,10 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R( * \param[out] out_results Result pointing to min value * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( - SEXP handle, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R( + LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -424,12 +424,12 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R( * \param eval_names eval names * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( - SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP eval_names, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R( + LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE eval_names, + LGBM_SE call_state ); /*! @@ -439,11 +439,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R( * \param out_result float array contains result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( - SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -453,11 +453,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R( * \param out size of predict * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( - SEXP handle, - SEXP data_idx, - SEXP out, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out, + LGBM_SE call_state ); /*! @@ -468,11 +468,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R( * \param out_result, used to store predict result, should pre-allocate memory * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( - SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R( + LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -486,17 +486,17 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R( * \return 0 when succeed, -1 when failure happens * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( - SEXP handle, - SEXP data_filename, - SEXP data_has_header, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP result_filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R( + LGBM_SE handle, + LGBM_SE data_filename, + LGBM_SE data_has_header, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE result_filename, + LGBM_SE call_state ); /*! @@ -509,15 +509,15 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R( * \param out_len length of prediction * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( - SEXP handle, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP out_len, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R( + LGBM_SE handle, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE out_len, + LGBM_SE call_state ); /*! @@ -538,21 +538,21 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( - SEXP handle, - SEXP indptr, - SEXP indices, - SEXP data, - SEXP nindptr, - SEXP nelem, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R( + LGBM_SE handle, + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE nindptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -570,18 +570,18 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R( * \param out prediction result * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( - SEXP handle, - SEXP data, - SEXP nrow, - SEXP ncol, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R( + LGBM_SE handle, + LGBM_SE data, + LGBM_SE nrow, + LGBM_SE ncol, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state ); /*! @@ -591,11 +591,11 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R( * \param filename file name * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( - SEXP handle, - SEXP num_iteration, - SEXP filename, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE filename, + LGBM_SE call_state ); /*! @@ -605,13 +605,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R( * \param out_str string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( - SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state ); /*! @@ -621,13 +621,13 @@ LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R( * \param out_str json format string of model * \return 0 when succeed, -1 when failure happens */ -LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R( - SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state +LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R( + LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state ); #endif // LIGHTGBM_R_H_ diff --git a/src/lightgbm_R.cpp b/src/lightgbm_R.cpp index c292a93dc3c9..7d3a8dcafe80 100644 --- a/src/lightgbm_R.cpp +++ b/src/lightgbm_R.cpp @@ -38,7 +38,7 @@ using LightGBM::Common::Join; using LightGBM::Common::Split; using LightGBM::Log; -SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_t str_len) { +LGBM_SE EncodeChar(LGBM_SE dest, const char* src, LGBM_SE buf_len, LGBM_SE actual_len, size_t str_len) { if (str_len > INT32_MAX) { Log::Fatal("Don't support large string in R-package"); } @@ -51,15 +51,15 @@ SEXP EncodeChar(SEXP dest, const char* src, SEXP buf_len, SEXP actual_len, size_ return dest; } -SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg) { +LGBM_SE LGBM_GetLastError_R(LGBM_SE buf_len, LGBM_SE actual_len, LGBM_SE err_msg) { return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1); } -SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); DatasetHandle handle = nullptr; CHECK_CALL(LGBM_DatasetCreateFromFile(R_CHAR_PTR(filename), R_CHAR_PTR(parameters), @@ -68,16 +68,16 @@ SEXP LGBM_DatasetCreateFromFile_R(SEXP filename, R_API_END(); } -SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, - SEXP indices, - SEXP data, - SEXP num_indptr, - SEXP nelem, - SEXP num_row, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromCSC_R(LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE num_indptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); const int* p_indptr = R_INT_PTR(indptr); const int* p_indices = R_INT_PTR(indices); @@ -94,13 +94,13 @@ SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr, R_API_END(); } -SEXP LGBM_DatasetCreateFromMat_R(SEXP data, - SEXP num_row, - SEXP num_col, - SEXP parameters, - SEXP reference, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data, + LGBM_SE num_row, + LGBM_SE num_col, + LGBM_SE parameters, + LGBM_SE reference, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int32_t nrow = static_cast(R_AS_INT(num_row)); int32_t ncol = static_cast(R_AS_INT(num_col)); @@ -112,12 +112,12 @@ SEXP LGBM_DatasetCreateFromMat_R(SEXP data, R_API_END(); } -SEXP LGBM_DatasetGetSubset_R(SEXP handle, - SEXP used_row_indices, - SEXP len_used_row_indices, - SEXP parameters, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle, + LGBM_SE used_row_indices, + LGBM_SE len_used_row_indices, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int len = R_AS_INT(len_used_row_indices); std::vector idxvec(len); @@ -134,9 +134,9 @@ SEXP LGBM_DatasetGetSubset_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, - SEXP feature_names, - SEXP call_state) { +LGBM_SE LGBM_DatasetSetFeatureNames_R(LGBM_SE handle, + LGBM_SE feature_names, + LGBM_SE call_state) { R_API_BEGIN(); auto vec_names = Split(R_CHAR_PTR(feature_names), '\t'); std::vector vec_sptr; @@ -149,11 +149,11 @@ SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP feature_names, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE feature_names, + LGBM_SE call_state) { R_API_BEGIN(); int len = 0; CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &len)); @@ -172,17 +172,17 @@ SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSaveBinary_R(SEXP handle, - SEXP filename, - SEXP call_state) { +LGBM_SE LGBM_DatasetSaveBinary_R(LGBM_SE handle, + LGBM_SE filename, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetSaveBinary(R_GET_PTR(handle), R_CHAR_PTR(filename))); R_API_END(); } -SEXP LGBM_DatasetFree_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_DatasetFree_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_DatasetFree(R_GET_PTR(handle))); @@ -191,11 +191,11 @@ SEXP LGBM_DatasetFree_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetSetField_R(SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP num_element, - SEXP call_state) { +LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE num_element, + LGBM_SE call_state) { R_API_BEGIN(); int len = static_cast(R_AS_INT(num_element)); const char* name = R_CHAR_PTR(field_name); @@ -219,10 +219,10 @@ SEXP LGBM_DatasetSetField_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetField_R(SEXP handle, - SEXP field_name, - SEXP field_data, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE field_data, + LGBM_SE call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -253,10 +253,10 @@ SEXP LGBM_DatasetGetField_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, - SEXP field_name, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle, + LGBM_SE field_name, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); const char* name = R_CHAR_PTR(field_name); int out_len = 0; @@ -270,16 +270,16 @@ SEXP LGBM_DatasetGetFieldSize_R(SEXP handle, R_API_END(); } -SEXP LGBM_DatasetUpdateParamChecking_R(SEXP old_params, - SEXP new_params, - SEXP call_state) { +LGBM_SE LGBM_DatasetUpdateParamChecking_R(LGBM_SE old_params, + LGBM_SE new_params, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_DatasetUpdateParamChecking(R_CHAR_PTR(old_params), R_CHAR_PTR(new_params))); R_API_END(); } -SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetNumData_R(LGBM_SE handle, LGBM_SE out, + LGBM_SE call_state) { int nrow; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumData(R_GET_PTR(handle), &nrow)); @@ -287,9 +287,9 @@ SEXP LGBM_DatasetGetNumData_R(SEXP handle, SEXP out, R_API_END(); } -SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_DatasetGetNumFeature_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int nfeature; R_API_BEGIN(); CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &nfeature)); @@ -299,8 +299,8 @@ SEXP LGBM_DatasetGetNumFeature_R(SEXP handle, // --- start Booster interfaces -SEXP LGBM_BoosterFree_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterFree_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); if (R_GET_PTR(handle) != nullptr) { CHECK_CALL(LGBM_BoosterFree(R_GET_PTR(handle))); @@ -309,10 +309,10 @@ SEXP LGBM_BoosterFree_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterCreate_R(SEXP train_data, - SEXP parameters, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data, + LGBM_SE parameters, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); BoosterHandle handle = nullptr; CHECK_CALL(LGBM_BoosterCreate(R_GET_PTR(train_data), R_CHAR_PTR(parameters), &handle)); @@ -320,9 +320,9 @@ SEXP LGBM_BoosterCreate_R(SEXP train_data, R_API_END(); } -SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -331,9 +331,9 @@ SEXP LGBM_BoosterCreateFromModelfile_R(SEXP filename, R_API_END(); } -SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int out_num_iterations = 0; BoosterHandle handle = nullptr; @@ -342,41 +342,41 @@ SEXP LGBM_BoosterLoadModelFromString_R(SEXP model_str, R_API_END(); } -SEXP LGBM_BoosterMerge_R(SEXP handle, - SEXP other_handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterMerge_R(LGBM_SE handle, + LGBM_SE other_handle, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterMerge(R_GET_PTR(handle), R_GET_PTR(other_handle))); R_API_END(); } -SEXP LGBM_BoosterAddValidData_R(SEXP handle, - SEXP valid_data, - SEXP call_state) { +LGBM_SE LGBM_BoosterAddValidData_R(LGBM_SE handle, + LGBM_SE valid_data, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterAddValidData(R_GET_PTR(handle), R_GET_PTR(valid_data))); R_API_END(); } -SEXP LGBM_BoosterResetTrainingData_R(SEXP handle, - SEXP train_data, - SEXP call_state) { +LGBM_SE LGBM_BoosterResetTrainingData_R(LGBM_SE handle, + LGBM_SE train_data, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetTrainingData(R_GET_PTR(handle), R_GET_PTR(train_data))); R_API_END(); } -SEXP LGBM_BoosterResetParameter_R(SEXP handle, - SEXP parameters, - SEXP call_state) { +LGBM_SE LGBM_BoosterResetParameter_R(LGBM_SE handle, + LGBM_SE parameters, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterResetParameter(R_GET_PTR(handle), R_CHAR_PTR(parameters))); R_API_END(); } -SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetNumClasses_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int num_class; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetNumClasses(R_GET_PTR(handle), &num_class)); @@ -384,19 +384,19 @@ SEXP LGBM_BoosterGetNumClasses_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterUpdateOneIter_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterUpdateOneIter_R(LGBM_SE handle, + LGBM_SE call_state) { int is_finished = 0; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterUpdateOneIter(R_GET_PTR(handle), &is_finished)); R_API_END(); } -SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, - SEXP grad, - SEXP hess, - SEXP len, - SEXP call_state) { +LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(LGBM_SE handle, + LGBM_SE grad, + LGBM_SE hess, + LGBM_SE len, + LGBM_SE call_state) { int is_finished = 0; R_API_BEGIN(); int int_len = R_AS_INT(len); @@ -410,16 +410,16 @@ SEXP LGBM_BoosterUpdateOneIterCustom_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterRollbackOneIter_R(SEXP handle, - SEXP call_state) { +LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterRollbackOneIter(R_GET_PTR(handle))); R_API_END(); } -SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle, + LGBM_SE out, + LGBM_SE call_state) { int out_iteration; R_API_BEGIN(); CHECK_CALL(LGBM_BoosterGetCurrentIteration(R_GET_PTR(handle), &out_iteration)); @@ -427,29 +427,29 @@ SEXP LGBM_BoosterGetCurrentIteration_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetUpperBoundValue_R(SEXP handle, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetUpperBoundValue_R(LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetUpperBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -SEXP LGBM_BoosterGetLowerBoundValue_R(SEXP handle, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetLowerBoundValue_R(LGBM_SE handle, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); CHECK_CALL(LGBM_BoosterGetLowerBoundValue(R_GET_PTR(handle), ptr_ret)); R_API_END(); } -SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, - SEXP buf_len, - SEXP actual_len, - SEXP eval_names, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle, + LGBM_SE buf_len, + LGBM_SE actual_len, + LGBM_SE eval_names, + LGBM_SE call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -477,10 +477,10 @@ SEXP LGBM_BoosterGetEvalNames_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetEval_R(SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetEval_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int len; CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len)); @@ -491,10 +491,10 @@ SEXP LGBM_BoosterGetEval_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, - SEXP data_idx, - SEXP out, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetNumPredict_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out, + LGBM_SE call_state) { R_API_BEGIN(); int64_t len; CHECK_CALL(LGBM_BoosterGetNumPredict(R_GET_PTR(handle), R_AS_INT(data_idx), &len)); @@ -502,10 +502,10 @@ SEXP LGBM_BoosterGetNumPredict_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterGetPredict_R(SEXP handle, - SEXP data_idx, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterGetPredict_R(LGBM_SE handle, + LGBM_SE data_idx, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); double* ptr_ret = R_REAL_PTR(out_result); int64_t out_len; @@ -513,7 +513,7 @@ SEXP LGBM_BoosterGetPredict_R(SEXP handle, R_API_END(); } -int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { +int GetPredictType(LGBM_SE is_rawscore, LGBM_SE is_leafidx, LGBM_SE is_predcontrib) { int pred_type = C_API_PREDICT_NORMAL; if (R_AS_INT(is_rawscore)) { pred_type = C_API_PREDICT_RAW_SCORE; @@ -527,16 +527,16 @@ int GetPredictType(SEXP is_rawscore, SEXP is_leafidx, SEXP is_predcontrib) { return pred_type; } -SEXP LGBM_BoosterPredictForFile_R(SEXP handle, - SEXP data_filename, - SEXP data_has_header, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP result_filename, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForFile_R(LGBM_SE handle, + LGBM_SE data_filename, + LGBM_SE data_has_header, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE result_filename, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); CHECK_CALL(LGBM_BoosterPredictForFile(R_GET_PTR(handle), R_CHAR_PTR(data_filename), @@ -545,14 +545,14 @@ SEXP LGBM_BoosterPredictForFile_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP out_len, - SEXP call_state) { +LGBM_SE LGBM_BoosterCalcNumPredict_R(LGBM_SE handle, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE out_len, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); int64_t len = 0; @@ -562,20 +562,20 @@ SEXP LGBM_BoosterCalcNumPredict_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, - SEXP indptr, - SEXP indices, - SEXP data, - SEXP num_indptr, - SEXP nelem, - SEXP num_row, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle, + LGBM_SE indptr, + LGBM_SE indices, + LGBM_SE data, + LGBM_SE num_indptr, + LGBM_SE nelem, + LGBM_SE num_row, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -595,17 +595,17 @@ SEXP LGBM_BoosterPredictForCSC_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterPredictForMat_R(SEXP handle, - SEXP data, - SEXP num_row, - SEXP num_col, - SEXP is_rawscore, - SEXP is_leafidx, - SEXP is_predcontrib, - SEXP num_iteration, - SEXP parameter, - SEXP out_result, - SEXP call_state) { +LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle, + LGBM_SE data, + LGBM_SE num_row, + LGBM_SE num_col, + LGBM_SE is_rawscore, + LGBM_SE is_leafidx, + LGBM_SE is_predcontrib, + LGBM_SE num_iteration, + LGBM_SE parameter, + LGBM_SE out_result, + LGBM_SE call_state) { R_API_BEGIN(); int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib); @@ -622,21 +622,21 @@ SEXP LGBM_BoosterPredictForMat_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterSaveModel_R(SEXP handle, - SEXP num_iteration, - SEXP filename, - SEXP call_state) { +LGBM_SE LGBM_BoosterSaveModel_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE filename, + LGBM_SE call_state) { R_API_BEGIN(); CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_CHAR_PTR(filename))); R_API_END(); } -SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state) { +LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); @@ -645,12 +645,12 @@ SEXP LGBM_BoosterSaveModelToString_R(SEXP handle, R_API_END(); } -SEXP LGBM_BoosterDumpModel_R(SEXP handle, - SEXP num_iteration, - SEXP buffer_len, - SEXP actual_len, - SEXP out_str, - SEXP call_state) { +LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle, + LGBM_SE num_iteration, + LGBM_SE buffer_len, + LGBM_SE actual_len, + LGBM_SE out_str, + LGBM_SE call_state) { R_API_BEGIN(); int64_t out_len = 0; std::vector inner_char_buf(R_AS_INT(buffer_len)); From 76ec14bf7de2ec2ec83024451fc7e1c793427692 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 12 Mar 2020 23:26:16 -0500 Subject: [PATCH 20/28] more cleanup --- include/LightGBM/R_object_helper.h | 6 ------ include/LightGBM/lightgbm_R.h | 4 ---- 2 files changed, 10 deletions(-) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index a5e9c5d61604..a3cf2f32ea77 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -15,12 +15,6 @@ #include -#ifdef LGB_R_BUILD - #define R_NO_REMAP - #define R_USE_C99_IN_CXX - #include -#endif - #define TYPE_BITS 5 // use .Internal(internalsID()) to uuid #define R_INTERNALS_UUID "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327" diff --git a/include/LightGBM/lightgbm_R.h b/include/LightGBM/lightgbm_R.h index 2ac05384d87e..076ea2946384 100644 --- a/include/LightGBM/lightgbm_R.h +++ b/include/LightGBM/lightgbm_R.h @@ -8,10 +8,6 @@ #include #include -#define R_NO_REMAP -#define R_USE_C99_IN_CXX -#include - /*! * \brief get string message of the last error * all functions in this file will return 0 on success From 13db6bf653a7c8cb88b844e7a591426f1c5c3406 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 14 Mar 2020 01:46:50 -0500 Subject: [PATCH 21/28] fixed linting --- R-package/src/install.libs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 592f9f3fd3ee..6f10d12a1685 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -174,7 +174,7 @@ if (file.exists(src)) { file.copy(src, dest, overwrite = TRUE) symbols_file <- file.path(R_PACKAGE_SOURCE, "src", "symbols.rds") - if (file.exists(symbols_file)){ + if (file.exists(symbols_file)) { file.copy(symbols_file, dest, overwrite = TRUE) } From 3be19b428d8b3c6c9fa9451b11edf408c60ba773 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 23 Mar 2020 20:06:33 -0500 Subject: [PATCH 22/28] cleaned up whitespace --- CMakeLists.txt | 6 +++--- include/LightGBM/R_object_helper.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea296f97bad4..7f82722d09a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,9 +279,9 @@ if(USE_SWIG) COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) else() add_custom_command(TARGET _lightgbm_swig POST_BUILD - COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java - COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64 - COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) + COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java + COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64 + COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com) endif() endif(USE_SWIG) diff --git a/include/LightGBM/R_object_helper.h b/include/LightGBM/R_object_helper.h index a3cf2f32ea77..1464c0a7083f 100644 --- a/include/LightGBM/R_object_helper.h +++ b/include/LightGBM/R_object_helper.h @@ -59,7 +59,6 @@ }; typedef int xlen_t; - #endif // R_VER_ABOVE_35 struct lgbm_primsxp { From 346a497e44b4a9013b1f526399eae233bf593cc4 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 24 Mar 2020 23:08:44 -0500 Subject: [PATCH 23/28] Update CMakeLists.txt Co-Authored-By: Nikita Titov --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f82722d09a0..7782d636f85e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,12 +236,11 @@ file(GLOB SOURCES add_executable(lightgbm src/main.cpp ${SOURCES}) +add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES}) # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - add_library(_lightgbm SHARED src/c_api.cpp src/lightgbm_R.cpp ${SOURCES}) -else() - add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES}) + add_library(_lightgbm SHARED src/lightgbm_R.cpp) endif(BUILD_FOR_R) if(MSVC) From 80906c52d7dbd2d37ccd9a0198ae93b240b292df Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 25 Mar 2020 10:44:31 -0500 Subject: [PATCH 24/28] cleaned up handling of R package --- CMakeLists.txt | 6 ++++-- windows/LightGBM.vcxproj | 3 --- windows/LightGBM.vcxproj.filters | 9 --------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7782d636f85e..e208f3460c14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,14 +235,16 @@ file(GLOB SOURCES ) add_executable(lightgbm src/main.cpp ${SOURCES}) +set(SOURCES "${SOURCES} src/c_api.cpp") -add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES}) # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - add_library(_lightgbm SHARED src/lightgbm_R.cpp) + set(SOURCES "${SOURCES} lightgbm_R.cpp") endif(BUILD_FOR_R) +add_library(_lightgbm SHARED ${SOURCES}) + if(MSVC) set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm") endif(MSVC) diff --git a/windows/LightGBM.vcxproj b/windows/LightGBM.vcxproj index 6e15af50c5f6..0f814a341977 100644 --- a/windows/LightGBM.vcxproj +++ b/windows/LightGBM.vcxproj @@ -237,13 +237,11 @@ - - @@ -308,7 +306,6 @@ - diff --git a/windows/LightGBM.vcxproj.filters b/windows/LightGBM.vcxproj.filters index 11852bcb986d..f122c865afee 100644 --- a/windows/LightGBM.vcxproj.filters +++ b/windows/LightGBM.vcxproj.filters @@ -183,12 +183,6 @@ src\metric - - include\LightGBM - - - include\LightGBM - src\boosting @@ -296,9 +290,6 @@ src\boosting - - src - src\boosting From d88c3e351a8bda2b49ca94ded04b6007db6665a0 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 25 Mar 2020 10:45:55 -0500 Subject: [PATCH 25/28] fixed bad reference --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e208f3460c14..b5ae0435055b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,7 +240,7 @@ set(SOURCES "${SOURCES} src/c_api.cpp") # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - set(SOURCES "${SOURCES} lightgbm_R.cpp") + set(SOURCES "${SOURCES} src/lightgbm_R.cpp") endif(BUILD_FOR_R) add_library(_lightgbm SHARED ${SOURCES}) From 023890418573042cafafaf9b3304673802ba9d24 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 25 Mar 2020 13:01:08 -0500 Subject: [PATCH 26/28] fixed list of SOURCES --- .ci/test_r_package.sh | 2 +- CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/test_r_package.sh b/.ci/test_r_package.sh index 0e660ba8581b..30254f8ecf70 100755 --- a/.ci/test_r_package.sh +++ b/.ci/test_r_package.sh @@ -91,7 +91,7 @@ if grep -q -R "WARNING" "$LOG_FILE_NAME"; then exit -1 fi -ALLOWED_CHECK_NOTES=3 +ALLOWED_CHECK_NOTES=2 NUM_CHECK_NOTES=$( cat ${LOG_FILE_NAME} \ | grep -e '^Status: .* NOTE.*' \ diff --git a/CMakeLists.txt b/CMakeLists.txt index b5ae0435055b..1d1d8d585ae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,12 +235,12 @@ file(GLOB SOURCES ) add_executable(lightgbm src/main.cpp ${SOURCES}) -set(SOURCES "${SOURCES} src/c_api.cpp") +list(APPEND SOURCES "src/c_api.cpp") # Only build the R part of the library if building for # use with the R package if(BUILD_FOR_R) - set(SOURCES "${SOURCES} src/lightgbm_R.cpp") + list(APPEND SOURCES "src/lightgbm_R.cpp") endif(BUILD_FOR_R) add_library(_lightgbm SHARED ${SOURCES}) From c6894c64e90719617e95da5f2512e47693eb4ed6 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Fri, 27 Mar 2020 22:09:12 -0500 Subject: [PATCH 27/28] removed unnecessary linking --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d1d8d585ae4..e0734b0534ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,7 +316,6 @@ if(WIN32 AND (MINGW OR CYGWIN)) endif() if(BUILD_FOR_R) - TARGET_LINK_LIBRARIES(lightgbm ${LIBR_CORE_LIBRARY}) TARGET_LINK_LIBRARIES(_lightgbm ${LIBR_CORE_LIBRARY}) endif(BUILD_FOR_R) From 1666f67859d2b0635c0b1fd45a26493319d8fbce Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 1 Apr 2020 10:55:02 -0500 Subject: [PATCH 28/28] better use of source_dir and build_dir --- R-package/src/install.libs.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 6f10d12a1685..a79c93d846b7 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -43,7 +43,7 @@ if (!use_precompile) { # Prepare installation steps cmake_cmd <- "cmake " build_cmd <- "make _lightgbm" - lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/") + lib_folder <- file.path(source_dir, fsep = "/") if (use_gpu) { cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ") @@ -98,7 +98,7 @@ if (!use_precompile) { } else { cmake_cmd <- paste0(cmake_cmd, local_vs_def) build_cmd <- "cmake --build . --target _lightgbm --config Release" - lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") + lib_folder <- file.path(source_dir, "Release", fsep = "/") } } } @@ -110,9 +110,7 @@ if (!use_precompile) { # Makefile. We don't need it here anyway since targets are built serially, so trying # to remove it with this hack generated_makefile <- file.path( - R_PACKAGE_SOURCE - , "src" - , "build" + build_dir , "Makefile" ) if (file.exists(generated_makefile)) { @@ -173,7 +171,7 @@ if (file.exists(src)) { print(paste0("Found library file: ", src, " to move to ", dest)) file.copy(src, dest, overwrite = TRUE) - symbols_file <- file.path(R_PACKAGE_SOURCE, "src", "symbols.rds") + symbols_file <- file.path(source_dir, "symbols.rds") if (file.exists(symbols_file)) { file.copy(symbols_file, dest, overwrite = TRUE) }