MCPcopy Create free account
hub / github.com/catboost/catboost / CatBoostPoolSlice_R

Function CatBoostPoolSlice_R

catboost/R-package/src/catboostr.cpp:495–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495EXPORT_FUNCTION CatBoostPoolSlice_R(SEXP poolParam, SEXP sizeParam, SEXP offsetParam) {
496 SEXP result = NULL;
497 size_t size, offset;
498 R_API_BEGIN();
499 size = static_cast<size_t>(asInteger(sizeParam));
500 offset = static_cast<size_t>(asInteger(offsetParam));
501 TPoolHandle pool = static_cast<TPoolHandle>(R_ExternalPtrAddr(poolParam));
502 const TRawObjectsDataProvider* rawObjectsData
503 = dynamic_cast<const TRawObjectsDataProvider*>(pool->ObjectsData.Get());
504 CB_ENSURE(rawObjectsData, "Cannot Slice quantized features data");
505
506 const auto& featuresLayout = *(rawObjectsData->GetFeaturesLayout());
507
508 CB_ENSURE(
509 featuresLayout.GetExternalFeatureCount() == featuresLayout.GetFloatFeatureCount(),
510 "Dataset slicing error: non-numeric features present, slicing datasets with categorical, text or embedding features is not supported"
511 );
512
513 result = PROTECT(allocVector(VECSXP, size));
514 ui32 featureCount = pool->MetaInfo.GetFeatureCount();
515 auto target = pool->RawTargetData.GetTarget();
516 const auto& weights = pool->RawTargetData.GetWeights();
517
518
519 const size_t sliceEnd = std::min((size_t)pool->GetObjectCount(), offset + size);
520
521 TRangesSubset<ui32>::TBlocks subsetBlocks = { TSubsetBlock<ui32>(TIndexRange<ui32>(offset, sliceEnd), 0) };
522
523 TObjectsGroupingSubset objectsGroupingSubset = GetGroupingSubsetFromObjectsSubset(
524 rawObjectsData->GetObjectsGrouping(),
525 TArraySubsetIndexing<ui32>(TRangesSubset<ui32>(subsetBlocks[0].GetSize(), std::move(subsetBlocks))),
526 EObjectsOrder::Ordered
527 );
528
529 TObjectsDataProviderPtr sliceObjectsData = rawObjectsData->GetSubset(
530 objectsGroupingSubset,
531 GetMonopolisticFreeCpuRam(),
532 &NPar::LocalExecutor()
533 );
534
535 const TRawObjectsDataProvider& sliceRawObjectsData
536 = dynamic_cast<const TRawObjectsDataProvider&>(*sliceObjectsData);
537
538 TVector<double*> rows;
539 const auto targetCount = pool->MetaInfo.TargetCount;
540
541 for (size_t i = offset; i < sliceEnd; ++i) {
542 ui32 featureCount = pool->MetaInfo.GetFeatureCount();
543 SEXP row = PROTECT(allocVector(REALSXP, featureCount + targetCount + 1));
544 REAL(row)[targetCount] = weights[i];
545 rows.push_back(REAL(row));
546 SET_VECTOR_ELT(result, i - offset, row);
547 }
548
549 for (auto targetIdx : xrange(targetCount)) {
550 if (const ITypedSequencePtr<float>* typedSequence
551 = std::get_if<ITypedSequencePtr<float>>(&((*target)[targetIdx])))
552 {

Callers

nothing calls this directly

Calls 15

xrangeFunction · 0.85
minFunction · 0.50
moveFunction · 0.50
GetMethod · 0.45
GetFeaturesLayoutMethod · 0.45
GetFloatFeatureCountMethod · 0.45
GetFeatureCountMethod · 0.45
GetTargetMethod · 0.45
GetWeightsMethod · 0.45

Tested by

no test coverage detected