Skip to content

Commit

Permalink
[R] Fix a crash that occurs with noLD R (#6378)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Nov 12, 2020
1 parent 12d27f4 commit c564518
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R-package/R/callbacks.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,15 @@ cb.early.stop <- function(stopping_rounds, maximize = FALSE,
finalizer <- function(env) {
if (!is.null(env$bst)) {
attr_best_score <- as.numeric(xgb.attr(env$bst$handle, 'best_score'))
if (best_score != attr_best_score)
stop("Inconsistent 'best_score' values between the closure state: ", best_score,
" and the xgb.attr: ", attr_best_score)
if (best_score != attr_best_score) {
# If the difference is too big, throw an error
if (abs(best_score - attr_best_score) >= 1e-14) {
stop("Inconsistent 'best_score' values between the closure state: ", best_score,
" and the xgb.attr: ", attr_best_score)
}
# If the difference is due to floating-point truncation, update best_score
best_score <- attr_best_score
}
env$bst$best_iteration <- best_iteration
env$bst$best_ntreelimit <- best_ntreelimit
env$bst$best_score <- best_score
Expand Down

0 comments on commit c564518

Please sign in to comment.