зеркало из https://github.com/microsoft/LightGBM.git
[R-package] Convert LGBM_GetLastError_R to use R built-in types (#4242)
* [R-package] move some functions over to SEXP objects * clarify comment * remove paste0() * fix registration table * fix cmake builds
This commit is contained in:
Родитель
1a367c65d1
Коммит
66ee29192a
|
@ -25,38 +25,15 @@ lgb.encode.char <- function(arr, len) {
|
|||
return(rawToChar(arr[seq_len(len)]))
|
||||
}
|
||||
|
||||
# [description] Raise an error. Before raising that error, check for any error message
|
||||
# stored in a buffer on the C++ side.
|
||||
# [description] Get the most recent error stored on the C++ side and raise it
|
||||
# as an R error.
|
||||
lgb.last_error <- function() {
|
||||
# Perform text error buffering
|
||||
buf_len <- 200L
|
||||
act_len <- 0L
|
||||
err_msg <- raw(buf_len)
|
||||
err_msg <- .Call(
|
||||
LGBM_GetLastError_R
|
||||
, buf_len
|
||||
, act_len
|
||||
, err_msg
|
||||
)
|
||||
|
||||
# Check error buffer
|
||||
if (act_len > buf_len) {
|
||||
buf_len <- act_len
|
||||
err_msg <- raw(buf_len)
|
||||
err_msg <- .Call(
|
||||
LGBM_GetLastError_R
|
||||
, buf_len
|
||||
, act_len
|
||||
, err_msg
|
||||
)
|
||||
}
|
||||
|
||||
stop("api error: ", lgb.encode.char(arr = err_msg, len = act_len))
|
||||
|
||||
stop("api error: ", err_msg)
|
||||
return(invisible(NULL))
|
||||
|
||||
}
|
||||
|
||||
lgb.params2str <- function(params, ...) {
|
||||
|
||||
# Check for a list as input
|
||||
|
|
|
@ -56,8 +56,12 @@ 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) {
|
||||
return EncodeChar(err_msg, LGBM_GetLastError(), buf_len, actual_len, std::strlen(LGBM_GetLastError()) + 1);
|
||||
SEXP LGBM_GetLastError_R() {
|
||||
SEXP out;
|
||||
out = PROTECT(Rf_allocVector(STRSXP, 1));
|
||||
SET_STRING_ELT(out, 0, Rf_mkChar(LGBM_GetLastError()));
|
||||
UNPROTECT(1);
|
||||
return out;
|
||||
}
|
||||
|
||||
SEXP LGBM_DatasetCreateFromFile_R(LGBM_SE filename,
|
||||
|
@ -640,7 +644,7 @@ SEXP LGBM_BoosterDumpModel_R(LGBM_SE handle,
|
|||
|
||||
// .Call() calls
|
||||
static const R_CallMethodDef CallEntries[] = {
|
||||
{"LGBM_GetLastError_R" , (DL_FUNC) &LGBM_GetLastError_R , 3},
|
||||
{"LGBM_GetLastError_R" , (DL_FUNC) &LGBM_GetLastError_R , 0},
|
||||
{"LGBM_DatasetCreateFromFile_R" , (DL_FUNC) &LGBM_DatasetCreateFromFile_R , 4},
|
||||
{"LGBM_DatasetCreateFromCSC_R" , (DL_FUNC) &LGBM_DatasetCreateFromCSC_R , 9},
|
||||
{"LGBM_DatasetCreateFromMat_R" , (DL_FUNC) &LGBM_DatasetCreateFromMat_R , 6},
|
||||
|
|
|
@ -15,11 +15,7 @@
|
|||
* \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();
|
||||
|
||||
// --- start Dataset interface
|
||||
|
||||
|
|
|
@ -397,7 +397,7 @@ c_api_contents <- gsub(
|
|||
, x = c_api_contents
|
||||
)
|
||||
c_api_symbols <- gsub(
|
||||
pattern = "\\("
|
||||
pattern = "\\(.*"
|
||||
, replacement = ""
|
||||
, x = c_api_contents
|
||||
)
|
||||
|
|
Загрузка…
Ссылка в новой задаче