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