Use matrix for gradient. (#9508)
- Use the `linalg::Matrix` for storing gradients. - New API for the custom objective. - Custom objective for multi-class/multi-target is now required to return the correct shape. - Custom objective for Python can accept arrays with any strides. (row-major, column-major)
This commit is contained in:
@@ -154,7 +154,14 @@ xgb.iter.update <- function(booster_handle, dtrain, iter, obj) {
|
||||
pred <- predict(booster_handle, dtrain, outputmargin = TRUE, training = TRUE,
|
||||
ntreelimit = 0)
|
||||
gpair <- obj(pred, dtrain)
|
||||
.Call(XGBoosterBoostOneIter_R, booster_handle, dtrain, gpair$grad, gpair$hess)
|
||||
n_samples <- dim(dtrain)[1]
|
||||
# We still require row-major in R as I'm not quite sure sure how to get the stride of
|
||||
# the matrix in C.
|
||||
gpair$grad <- matrix(gpair$grad, nrow = n_samples, byrow = TRUE)
|
||||
gpair$hess <- matrix(gpair$hess, nrow = n_samples, byrow = TRUE)
|
||||
.Call(
|
||||
XGBoosterBoostOneIter_R, booster_handle, dtrain, iter, gpair$grad, gpair$hess
|
||||
)
|
||||
}
|
||||
return(TRUE)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user