MCPcopy Create free account
hub / github.com/dmlc/xgboost / XGDMatrixCreateFromCallbackGeneric_R

Function XGDMatrixCreateFromCallbackGeneric_R

R-package/src/xgboost_R.cc:761–823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

759}
760
761SEXP XGDMatrixCreateFromCallbackGeneric_R(
762 SEXP f_next, SEXP f_reset, SEXP calling_env, SEXP proxy_dmat,
763 SEXP n_threads, SEXP missing, SEXP max_bin, SEXP ref_dmat,
764 SEXP cache_prefix, bool as_quantile_dmatrix) {
765 SEXP continuation_token = Rf_protect(R_MakeUnwindCont());
766 SEXP out = Rf_protect(R_MakeExternalPtr(nullptr, R_NilValue, R_NilValue));
767 R_API_BEGIN();
768 DMatrixHandle out_dmat;
769
770 int res_code;
771 try {
772 _RDataIterator data_iterator(f_next, f_reset, calling_env, continuation_token);
773
774 std::string str_cache_prefix;
775 xgboost::Json jconfig{xgboost::Object{}};
776 jconfig["missing"] = Rf_asReal(missing);
777 if (!Rf_isNull(n_threads)) {
778 jconfig["nthread"] = Rf_asInteger(n_threads);
779 }
780 if (as_quantile_dmatrix) {
781 if (!Rf_isNull(max_bin)) {
782 jconfig["max_bin"] = Rf_asInteger(max_bin);
783 }
784 } else {
785 str_cache_prefix = std::string(CHAR(Rf_asChar(cache_prefix)));
786 jconfig["cache_prefix"] = str_cache_prefix;
787 }
788 std::string json_str = xgboost::Json::Dump(jconfig);
789
790 DMatrixHandle ref_dmat_handle = nullptr;
791 if (as_quantile_dmatrix && !Rf_isNull(ref_dmat)) {
792 ref_dmat_handle = R_ExternalPtrAddr(ref_dmat);
793 }
794
795 if (as_quantile_dmatrix) {
796 res_code = XGQuantileDMatrixCreateFromCallback(
797 &data_iterator,
798 R_ExternalPtrAddr(proxy_dmat),
799 ref_dmat_handle,
800 _reset_RDataIterator,
801 _next_RDataIterator,
802 json_str.c_str(),
803 &out_dmat);
804 } else {
805 res_code = XGDMatrixCreateFromCallback(
806 &data_iterator,
807 R_ExternalPtrAddr(proxy_dmat),
808 _reset_RDataIterator,
809 _next_RDataIterator,
810 json_str.c_str(),
811 &out_dmat);
812 }
813 } catch (ErrorWithUnwind &e) {
814 R_ContinueUnwind(continuation_token);
815 }
816 CHECK_CALL(res_code);
817
818 R_SetExternalPtrAddr(out, out_dmat);

Calls 3

c_strMethod · 0.80

Tested by

no test coverage detected