checkin slice
This commit is contained in:
parent
776e4627de
commit
8c50cbb6dd
@ -1,6 +1,7 @@
|
|||||||
# Generated by roxygen2 (4.0.1): do not edit by hand
|
# Generated by roxygen2 (4.0.1): do not edit by hand
|
||||||
|
|
||||||
export(getinfo)
|
export(getinfo)
|
||||||
|
export(slice)
|
||||||
export(xgb.DMatrix)
|
export(xgb.DMatrix)
|
||||||
export(xgb.DMatrix.save)
|
export(xgb.DMatrix.save)
|
||||||
export(xgb.dump)
|
export(xgb.dump)
|
||||||
@ -9,3 +10,4 @@ export(xgb.save)
|
|||||||
export(xgb.train)
|
export(xgb.train)
|
||||||
export(xgboost)
|
export(xgboost)
|
||||||
exportMethods(predict)
|
exportMethods(predict)
|
||||||
|
|
||||||
|
|||||||
30
R-package/R/slice.xgb.DMatrix.R
Normal file
30
R-package/R/slice.xgb.DMatrix.R
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
setClass('xgb.DMatrix')
|
||||||
|
|
||||||
|
#' Get a new DMatrix containing the specified rows of
|
||||||
|
#' orginal xgb.DMatrix object
|
||||||
|
#'
|
||||||
|
#' Get a new DMatrix containing the specified rows of
|
||||||
|
#' orginal xgb.DMatrix object
|
||||||
|
#'
|
||||||
|
#' @param object Object of class "xgb.DMatrix"
|
||||||
|
#' @param idxset a integer vector of indices of rows needed
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' data(iris)
|
||||||
|
#' iris[,5] <- as.numeric(iris[,5])
|
||||||
|
#' dtrain <- xgb.DMatrix(as.matrix(iris[,1:4]), label=iris[,5])
|
||||||
|
#' dsub <- slice(dtrain, c(1,2,3))
|
||||||
|
#' @export
|
||||||
|
#'
|
||||||
|
slice <- function(object, ...){
|
||||||
|
UseMethod("slice")
|
||||||
|
}
|
||||||
|
|
||||||
|
setMethod("slice", signature = "xgb.DMatrix",
|
||||||
|
definition = function(object, idxset) {
|
||||||
|
if (class(object) != "xgb.DMatrix") {
|
||||||
|
stop("slice: first argument dtrain must be xgb.DMatrix")
|
||||||
|
}
|
||||||
|
ret <- .Call("XGDMatrixSliceDMatrix_R", object, idxset, PACKAGE = "xgboost")
|
||||||
|
return(structure(ret, class = "xgb.DMatrix"))
|
||||||
|
})
|
||||||
@ -91,6 +91,18 @@ extern "C" {
|
|||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
SEXP XGDMatrixSliceDMatrix_R(SEXP handle, SEXP idxset) {
|
||||||
|
int len = length(idxset);
|
||||||
|
std::vector<int> idxvec(len);
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
idxvec[i] = INTEGER(idxset)[i] - 1;
|
||||||
|
}
|
||||||
|
void *res = XGDMatrixSliceDMatrix(R_ExternalPtrAddr(handle), &idxvec[0], len);
|
||||||
|
SEXP ret = PROTECT(R_MakeExternalPtr(res, R_NilValue, R_NilValue));
|
||||||
|
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
||||||
|
UNPROTECT(1);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
void XGDMatrixSaveBinary_R(SEXP handle, SEXP fname, SEXP silent) {
|
void XGDMatrixSaveBinary_R(SEXP handle, SEXP fname, SEXP silent) {
|
||||||
XGDMatrixSaveBinary(R_ExternalPtrAddr(handle),
|
XGDMatrixSaveBinary(R_ExternalPtrAddr(handle),
|
||||||
CHAR(asChar(fname)), asInteger(silent));
|
CHAR(asChar(fname)), asInteger(silent));
|
||||||
|
|||||||
@ -36,6 +36,13 @@ extern "C" {
|
|||||||
SEXP XGDMatrixCreateFromCSC_R(SEXP indptr,
|
SEXP XGDMatrixCreateFromCSC_R(SEXP indptr,
|
||||||
SEXP indices,
|
SEXP indices,
|
||||||
SEXP data);
|
SEXP data);
|
||||||
|
/*!
|
||||||
|
* \brief create a new dmatrix from sliced content of existing matrix
|
||||||
|
* \param handle instance of data matrix to be sliced
|
||||||
|
* \param idxset index set
|
||||||
|
* \return a sliced new matrix
|
||||||
|
*/
|
||||||
|
SEXP XGDMatrixSliceDMatrix_R(SEXP handle, SEXP idxset);
|
||||||
/*!
|
/*!
|
||||||
* \brief load a data matrix into binary file
|
* \brief load a data matrix into binary file
|
||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user