Unverified Commit 26cde5f5 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] remove pre-allocated call_state in C++ calls (#4244)

parent b27dcfa4
......@@ -16,11 +16,9 @@ Booster <- R6::R6Class(
if (!lgb.is.null.handle(x = private$handle)) {
# Freeing up handle
call_state <- 0L
.Call(
LGBM_BoosterFree_R
, private$handle
, call_state
)
private$handle <- NULL
......@@ -54,13 +52,11 @@ Booster <- R6::R6Class(
params <- modifyList(params, train_set$get_params())
params_str <- lgb.params2str(params = params)
# Store booster handle
call_state <- 0L
.Call(
LGBM_BoosterCreate_R
, train_set_handle
, params_str
, handle
, call_state
)
# Create private booster information
......@@ -73,12 +69,10 @@ Booster <- R6::R6Class(
if (!is.null(private$init_predictor)) {
# Merge booster
call_state <- 0L
.Call(
LGBM_BoosterMerge_R
, handle
, private$init_predictor$.__enclos_env__$private$handle
, call_state
)
}
......@@ -94,12 +88,10 @@ Booster <- R6::R6Class(
}
# Create booster from model
call_state <- 0L
.Call(
LGBM_BoosterCreateFromModelfile_R
, lgb.c_str(x = modelfile)
, handle
, call_state
)
} else if (!is.null(model_str)) {
......@@ -110,12 +102,10 @@ Booster <- R6::R6Class(
}
# Create booster from model
call_state <- 0L
.Call(
LGBM_BoosterLoadModelFromString_R
, lgb.c_str(x = model_str)
, handle
, call_state
)
} else {
......@@ -141,12 +131,10 @@ Booster <- R6::R6Class(
class(handle) <- "lgb.Booster.handle"
private$handle <- handle
private$num_class <- 1L
call_state <- 0L
.Call(
LGBM_BoosterGetNumClasses_R
, private$handle
, private$num_class
, call_state
)
}
......@@ -188,12 +176,10 @@ Booster <- R6::R6Class(
}
# Add validation data to booster
call_state <- 0L
.Call(
LGBM_BoosterAddValidData_R
, private$handle
, data$.__enclos_env__$private$get_handle()
, call_state
)
# Store private information
......@@ -216,12 +202,10 @@ Booster <- R6::R6Class(
params <- modifyList(params, list(...))
params_str <- lgb.params2str(params = params)
call_state <- 0L
.Call(
LGBM_BoosterResetParameter_R
, private$handle
, params_str
, call_state
)
self$params <- params
......@@ -252,12 +236,10 @@ Booster <- R6::R6Class(
}
# Reset training data on booster
call_state <- 0L
.Call(
LGBM_BoosterResetTrainingData_R
, private$handle
, train_set$.__enclos_env__$private$get_handle()
, call_state
)
# Store private train set
......@@ -272,11 +254,9 @@ Booster <- R6::R6Class(
stop("lgb.Booster.update: cannot update due to null objective function")
}
# Boost iteration from known objective
call_state <- 0L
.Call(
LGBM_BoosterUpdateOneIter_R
, private$handle
, call_state
)
} else {
......@@ -299,14 +279,12 @@ Booster <- R6::R6Class(
}
# Return custom boosting gradient/hessian
call_state <- 0L
.Call(
LGBM_BoosterUpdateOneIterCustom_R
, private$handle
, gpair$grad
, gpair$hess
, length(gpair$grad)
, call_state
)
}
......@@ -324,11 +302,9 @@ Booster <- R6::R6Class(
rollback_one_iter = function() {
# Return one iteration behind
call_state <- 0L
.Call(
LGBM_BoosterRollbackOneIter_R
, private$handle
, call_state
)
# Loop through each iteration
......@@ -344,12 +320,10 @@ Booster <- R6::R6Class(
current_iter = function() {
cur_iter <- 0L
call_state <- 0L
.Call(
LGBM_BoosterGetCurrentIteration_R
, private$handle
, cur_iter
, call_state
)
return(cur_iter)
......@@ -359,12 +333,10 @@ Booster <- R6::R6Class(
upper_bound = function() {
upper_bound <- 0.0
call_state <- 0L
.Call(
LGBM_BoosterGetUpperBoundValue_R
, private$handle
, upper_bound
, call_state
)
return(upper_bound)
......@@ -374,12 +346,10 @@ Booster <- R6::R6Class(
lower_bound = function() {
lower_bound <- 0.0
call_state <- 0L
.Call(
LGBM_BoosterGetLowerBoundValue_R
, private$handle
, lower_bound
, call_state
)
return(lower_bound)
......@@ -477,14 +447,12 @@ Booster <- R6::R6Class(
}
# Save booster model
call_state <- 0L
.Call(
LGBM_BoosterSaveModel_R
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
, lgb.c_str(x = filename)
, call_state
)
return(invisible(self))
......@@ -504,7 +472,6 @@ Booster <- R6::R6Class(
buf <- raw(buf_len)
# Call buffer
call_state <- 0L
.Call(
LGBM_BoosterSaveModelToString_R
, private$handle
......@@ -513,14 +480,12 @@ Booster <- R6::R6Class(
, buf_len
, act_len
, buf
, call_state
)
# Check for buffer content
if (act_len > buf_len) {
buf_len <- act_len
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_BoosterSaveModelToString_R
, private$handle
......@@ -529,7 +494,6 @@ Booster <- R6::R6Class(
, buf_len
, act_len
, buf
, call_state
)
}
......@@ -550,7 +514,6 @@ Booster <- R6::R6Class(
buf_len <- as.integer(1024L * 1024L)
act_len <- 0L
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_BoosterDumpModel_R
, private$handle
......@@ -559,13 +522,11 @@ Booster <- R6::R6Class(
, buf_len
, act_len
, buf
, call_state
)
if (act_len > buf_len) {
buf_len <- act_len
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_BoosterDumpModel_R
, private$handle
......@@ -574,7 +535,6 @@ Booster <- R6::R6Class(
, buf_len
, act_len
, buf
, call_state
)
}
......@@ -674,14 +634,12 @@ Booster <- R6::R6Class(
if (is.null(private$predict_buffer[[data_name]])) {
# Store predictions
call_state <- 0L
npred <- 0L
.Call(
LGBM_BoosterGetNumPredict_R
, private$handle
, as.integer(idx - 1L)
, npred
, call_state
)
private$predict_buffer[[data_name]] <- numeric(npred)
......@@ -691,13 +649,11 @@ Booster <- R6::R6Class(
if (!private$is_predicted_cur_iter[[idx]]) {
# Use buffer
call_state <- 0L
.Call(
LGBM_BoosterGetPredict_R
, private$handle
, as.integer(idx - 1L)
, private$predict_buffer[[data_name]]
, call_state
)
private$is_predicted_cur_iter[[idx]] <- TRUE
}
......@@ -715,26 +671,22 @@ Booster <- R6::R6Class(
buf_len <- as.integer(1024L * 1024L)
act_len <- 0L
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_BoosterGetEvalNames_R
, private$handle
, buf_len
, act_len
, buf
, call_state
)
if (act_len > buf_len) {
buf_len <- act_len
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_BoosterGetEvalNames_R
, private$handle
, buf_len
, act_len
, buf
, call_state
)
}
names <- lgb.encode.char(arr = buf, len = act_len)
......@@ -778,13 +730,11 @@ Booster <- R6::R6Class(
# Create evaluation values
tmp_vals <- numeric(length(private$eval_names))
call_state <- 0L
.Call(
LGBM_BoosterGetEval_R
, private$handle
, as.integer(data_idx - 1L)
, tmp_vals
, call_state
)
# Loop through all evaluation names
......
......@@ -13,11 +13,9 @@ Dataset <- R6::R6Class(
if (!lgb.is.null.handle(x = private$handle)) {
# Freeing up handle
call_state <- 0L
.Call(
LGBM_DatasetFree_R
, private$handle
, call_state
)
private$handle <- NULL
......@@ -202,20 +200,17 @@ Dataset <- R6::R6Class(
# Are we using a data file?
if (is.character(private$raw_data)) {
call_state <- 0L
.Call(
LGBM_DatasetCreateFromFile_R
, lgb.c_str(x = private$raw_data)
, params_str
, ref_handle
, handle
, call_state
)
} else if (is.matrix(private$raw_data)) {
# Are we using a matrix?
call_state <- 0L
.Call(
LGBM_DatasetCreateFromMat_R
, private$raw_data
......@@ -224,7 +219,6 @@ Dataset <- R6::R6Class(
, params_str
, ref_handle
, handle
, call_state
)
} else if (methods::is(private$raw_data, "dgCMatrix")) {
......@@ -232,7 +226,6 @@ Dataset <- R6::R6Class(
stop("Cannot support large CSC matrix")
}
# Are we using a dgCMatrix (sparsed matrix column compressed)
call_state <- 0L
.Call(
LGBM_DatasetCreateFromCSC_R
, private$raw_data@p
......@@ -244,7 +237,6 @@ Dataset <- R6::R6Class(
, params_str
, ref_handle
, handle
, call_state
)
} else {
......@@ -265,7 +257,6 @@ Dataset <- R6::R6Class(
}
# Construct subset
call_state <- 0L
.Call(
LGBM_DatasetGetSubset_R
, ref_handle
......@@ -273,7 +264,6 @@ Dataset <- R6::R6Class(
, length(private$used_indices)
, params_str
, handle
, call_state
)
}
......@@ -342,19 +332,15 @@ Dataset <- R6::R6Class(
num_col <- 0L
# Get numeric data and numeric features
call_state <- 0L
.Call(
LGBM_DatasetGetNumData_R
, private$handle
, num_row
, call_state
)
call_state <- 0L
.Call(
LGBM_DatasetGetNumFeature_R
, private$handle
, num_col
, call_state
)
return(
c(num_row, num_col)
......@@ -388,26 +374,22 @@ Dataset <- R6::R6Class(
buf_len <- as.integer(1024L * 1024L)
act_len <- 0L
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_DatasetGetFeatureNames_R
, private$handle
, buf_len
, act_len
, buf
, call_state
)
if (act_len > buf_len) {
buf_len <- act_len
buf <- raw(buf_len)
call_state <- 0L
.Call(
LGBM_DatasetGetFeatureNames_R
, private$handle
, buf_len
, act_len
, buf
, call_state
)
}
cnames <- lgb.encode.char(arr = buf, len = act_len)
......@@ -451,12 +433,10 @@ Dataset <- R6::R6Class(
# Merge names with tab separation
merged_name <- paste0(as.list(private$colnames), collapse = "\t")
call_state <- 0L
.Call(
LGBM_DatasetSetFeatureNames_R
, private$handle
, lgb.c_str(x = merged_name)
, call_state
)
}
......@@ -485,13 +465,11 @@ Dataset <- R6::R6Class(
# Get field size of info
info_len <- 0L
call_state <- 0L
.Call(
LGBM_DatasetGetFieldSize_R
, private$handle
, lgb.c_str(x = name)
, info_len
, call_state
)
# Check if info is not empty
......@@ -505,13 +483,11 @@ Dataset <- R6::R6Class(
numeric(info_len) # Numeric
}
call_state <- 0L
.Call(
LGBM_DatasetGetField_R
, private$handle
, lgb.c_str(x = name)
, ret
, call_state
)
private$info[[name]] <- ret
......@@ -548,14 +524,12 @@ Dataset <- R6::R6Class(
if (length(info) > 0L) {
call_state <- 0L
.Call(
LGBM_DatasetSetField_R
, private$handle
, lgb.c_str(x = name)
, info
, length(info)
, call_state
)
private$version <- private$version + 1L
......@@ -600,12 +574,10 @@ Dataset <- R6::R6Class(
private$params <- modifyList(private$params, params)
} else {
tryCatch({
call_state <- 0L
.Call(
LGBM_DatasetUpdateParamChecking_R
, lgb.params2str(params = private$params)
, lgb.params2str(params = params)
, call_state
)
}, error = function(e) {
# If updating failed but raw data is not available, raise an error because
......@@ -703,12 +675,10 @@ Dataset <- R6::R6Class(
# Store binary data
self$construct()
call_state <- 0L
.Call(
LGBM_DatasetSaveBinary_R
, private$handle
, lgb.c_str(x = fname)
, call_state
)
return(invisible(self))
}
......
......@@ -14,11 +14,9 @@ Predictor <- R6::R6Class(
if (private$need_free_handle && !lgb.is.null.handle(x = private$handle)) {
# Freeing up handle
call_state <- 0L
.Call(
LGBM_BoosterFree_R
, private$handle
, call_state
)
private$handle <- NULL
......@@ -39,12 +37,10 @@ Predictor <- R6::R6Class(
if (is.character(modelfile)) {
# Create handle on it
call_state <- 0L
.Call(
LGBM_BoosterCreateFromModelfile_R
, lgb.c_str(x = modelfile)
, handle
, call_state
)
private$need_free_handle <- TRUE
......@@ -72,12 +68,10 @@ Predictor <- R6::R6Class(
current_iter = function() {
cur_iter <- 0L
call_state <- 0L
.Call(
LGBM_BoosterGetCurrentIteration_R
, private$handle
, cur_iter
, call_state
)
return(cur_iter)
......@@ -112,7 +106,6 @@ Predictor <- R6::R6Class(
on.exit(unlink(tmp_filename), add = TRUE)
# Predict from temporary file
call_state <- 0L
.Call(
LGBM_BoosterPredictForFile_R
, private$handle
......@@ -125,7 +118,6 @@ Predictor <- R6::R6Class(
, as.integer(num_iteration)
, private$params
, lgb.c_str(x = tmp_filename)
, call_state
)
# Get predictions from file
......@@ -141,7 +133,6 @@ Predictor <- R6::R6Class(
npred <- 0L
# Check number of predictions to do
call_state <- 0L
.Call(
LGBM_BoosterCalcNumPredict_R
, private$handle
......@@ -152,7 +143,6 @@ Predictor <- R6::R6Class(
, as.integer(start_iteration)
, as.integer(num_iteration)
, npred
, call_state
)
# Pre-allocate empty vector
......@@ -165,7 +155,6 @@ Predictor <- R6::R6Class(
if (storage.mode(data) != "double") {
storage.mode(data) <- "double"
}
call_state <- 0L
.Call(
LGBM_BoosterPredictForMat_R
, private$handle
......@@ -179,7 +168,6 @@ Predictor <- R6::R6Class(
, as.integer(num_iteration)
, private$params
, preds
, call_state
)
} else if (methods::is(data, "dgCMatrix")) {
......@@ -187,7 +175,6 @@ Predictor <- R6::R6Class(
stop("Cannot support large CSC matrix")
}
# Check if data is a dgCMatrix (sparse matrix, column compressed format)
call_state <- 0L
.Call(
LGBM_BoosterPredictForCSC_R
, private$handle
......@@ -204,7 +191,6 @@ Predictor <- R6::R6Class(
, as.integer(num_iteration)
, private$params
, preds
, call_state
)
} else {
......
This diff is collapsed.
......@@ -31,12 +31,11 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R(
LGBM_SE filename,
LGBM_SE parameters,
LGBM_SE reference,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -52,7 +51,7 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R(
LGBM_SE indptr,
LGBM_SE indices,
LGBM_SE data,
......@@ -61,8 +60,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R(
LGBM_SE num_row,
LGBM_SE parameters,
LGBM_SE reference,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -75,14 +73,13 @@ 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(
LIGHTGBM_C_EXPORT SEXP 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
LGBM_SE out
);
/*!
......@@ -94,13 +91,12 @@ 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(
LIGHTGBM_C_EXPORT SEXP 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
LGBM_SE out
);
/*!
......@@ -109,10 +105,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R(
LGBM_SE handle,
LGBM_SE feature_names,
LGBM_SE call_state
LGBM_SE feature_names
);
/*!
......@@ -121,12 +116,11 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R(
LGBM_SE handle,
LGBM_SE buf_len,
LGBM_SE actual_len,
LGBM_SE feature_names,
LGBM_SE call_state
LGBM_SE feature_names
);
/*!
......@@ -135,10 +129,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R(
LGBM_SE handle,
LGBM_SE filename,
LGBM_SE call_state
LGBM_SE filename
);
/*!
......@@ -146,9 +139,8 @@ 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(
LGBM_SE handle
);
/*!
......@@ -161,12 +153,11 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R(
LGBM_SE handle,
LGBM_SE field_name,
LGBM_SE field_data,
LGBM_SE num_element,
LGBM_SE call_state
LGBM_SE num_element
);
/*!
......@@ -176,11 +167,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R(
LGBM_SE handle,
LGBM_SE field_name,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -190,11 +180,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R(
LGBM_SE handle,
LGBM_SE field_name,
LGBM_SE field_data,
LGBM_SE call_state
LGBM_SE field_data
);
/*!
......@@ -203,10 +192,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R(
LGBM_SE old_params,
LGBM_SE new_params,
LGBM_SE call_state
LGBM_SE new_params
);
/*!
......@@ -215,10 +203,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R(
LGBM_SE handle,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -227,10 +214,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R(
LGBM_SE handle,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
// --- start Booster interfaces
......@@ -242,11 +228,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R(
LGBM_SE train_data,
LGBM_SE parameters,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -254,9 +239,8 @@ 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(
LGBM_SE handle
);
/*!
......@@ -265,10 +249,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R(
LGBM_SE filename,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -277,10 +260,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R(
LGBM_SE model_str,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -289,10 +271,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R(
LGBM_SE handle,
LGBM_SE other_handle,
LGBM_SE call_state
LGBM_SE other_handle
);
/*!
......@@ -301,10 +282,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R(
LGBM_SE handle,
LGBM_SE valid_data,
LGBM_SE call_state
LGBM_SE valid_data
);
/*!
......@@ -313,10 +293,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R(
LGBM_SE handle,
LGBM_SE train_data,
LGBM_SE call_state
LGBM_SE train_data
);
/*!
......@@ -325,10 +304,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R(
LGBM_SE handle,
LGBM_SE parameters,
LGBM_SE call_state
LGBM_SE parameters
);
/*!
......@@ -337,10 +315,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R(
LGBM_SE handle,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -348,9 +325,8 @@ 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(
LGBM_SE handle
);
/*!
......@@ -362,12 +338,11 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R(
LGBM_SE handle,
LGBM_SE grad,
LGBM_SE hess,
LGBM_SE len,
LGBM_SE call_state
LGBM_SE len
);
/*!
......@@ -375,9 +350,8 @@ 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(
LGBM_SE handle
);
/*!
......@@ -385,10 +359,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R(
LGBM_SE handle,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -397,10 +370,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R(
LGBM_SE handle,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -409,10 +381,9 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R(
LGBM_SE handle,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -420,12 +391,11 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R(
LGBM_SE handle,
LGBM_SE buf_len,
LGBM_SE actual_len,
LGBM_SE eval_names,
LGBM_SE call_state
LGBM_SE eval_names
);
/*!
......@@ -435,11 +405,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R(
LGBM_SE handle,
LGBM_SE data_idx,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -449,11 +418,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R(
LGBM_SE handle,
LGBM_SE data_idx,
LGBM_SE out,
LGBM_SE call_state
LGBM_SE out
);
/*!
......@@ -464,11 +432,10 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R(
LGBM_SE handle,
LGBM_SE data_idx,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -482,7 +449,7 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R(
LGBM_SE handle,
LGBM_SE data_filename,
LGBM_SE data_has_header,
......@@ -492,8 +459,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R(
LGBM_SE start_iteration,
LGBM_SE num_iteration,
LGBM_SE parameter,
LGBM_SE result_filename,
LGBM_SE call_state
LGBM_SE result_filename
);
/*!
......@@ -506,7 +472,7 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R(
LGBM_SE handle,
LGBM_SE num_row,
LGBM_SE is_rawscore,
......@@ -514,8 +480,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R(
LGBM_SE is_predcontrib,
LGBM_SE start_iteration,
LGBM_SE num_iteration,
LGBM_SE out_len,
LGBM_SE call_state
LGBM_SE out_len
);
/*!
......@@ -536,7 +501,7 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R(
LGBM_SE handle,
LGBM_SE indptr,
LGBM_SE indices,
......@@ -550,8 +515,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R(
LGBM_SE start_iteration,
LGBM_SE num_iteration,
LGBM_SE parameter,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -569,7 +533,7 @@ 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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R(
LGBM_SE handle,
LGBM_SE data,
LGBM_SE nrow,
......@@ -580,8 +544,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R(
LGBM_SE start_iteration,
LGBM_SE num_iteration,
LGBM_SE parameter,
LGBM_SE out_result,
LGBM_SE call_state
LGBM_SE out_result
);
/*!
......@@ -591,12 +554,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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE filename,
LGBM_SE call_state
LGBM_SE filename
);
/*!
......@@ -606,14 +568,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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
LGBM_SE call_state
LGBM_SE out_str
);
/*!
......@@ -623,14 +584,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(
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
LGBM_SE call_state
LGBM_SE out_str
);
#endif // LIGHTGBM_R_H_
......@@ -75,7 +75,6 @@ test_that("lgb.Dataset: Dataset should be able to construct from matrix and retu
rawData <- matrix(runif(1000L), ncol = 10L)
handle <- lgb.null.handle()
ref_handle <- NULL
call_state <- 0L
.Call(
LGBM_DatasetCreateFromMat_R
, rawData
......@@ -84,11 +83,9 @@ test_that("lgb.Dataset: Dataset should be able to construct from matrix and retu
, lightgbm:::lgb.params2str(params = list())
, ref_handle
, handle
, call_state
)
expect_false(is.na(handle))
call_state <- 0L
.Call(LGBM_DatasetFree_R, handle, call_state)
.Call(LGBM_DatasetFree_R, handle)
handle <- NULL
})
......
......@@ -391,6 +391,11 @@ c_api_contents <- gsub(
, replacement = ""
, x = c_api_contents
)
c_api_contents <- gsub(
pattern = "LIGHTGBM_C_EXPORT SEXP "
, replacement = ""
, x = c_api_contents
)
c_api_symbols <- gsub(
pattern = "\\("
, replacement = ""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment