| 7 | template <class TDataSet, |
| 8 | class TCtrSplitBuilder> |
| 9 | class TSplitHelper: public IBinarySplitProvider { |
| 10 | public: |
| 11 | TSplitHelper(TScopedCacheHolder& scopedCache, |
| 12 | TCtrSplitBuilder& builder, |
| 13 | const TBinarizedFeaturesManager& featuresManager, |
| 14 | const TDataSet& dataSet) |
| 15 | : ScopedCache(scopedCache) |
| 16 | , CtrSplitBuilder(builder) |
| 17 | , FeaturesManager(featuresManager) |
| 18 | , DataSet(dataSet) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | const TMirrorBuffer<ui64>& GetCompressedBits(const TBinarySplit& split) const final { |
| 23 | const ui32 featureId = split.FeatureId; |
| 24 | if (DataSet.HasFeatures() && DataSet.GetFeatures().HasFeature(featureId)) { |
| 25 | return GetCompressedBitsFromGpuFeatures(DataSet.GetFeatures(), split, nullptr); |
| 26 | } else if (DataSet.HasPermutationDependentFeatures() && DataSet.GetPermutationFeatures().HasFeature(featureId)) { |
| 27 | return GetCompressedBitsFromGpuFeatures(DataSet.GetPermutationFeatures(), |
| 28 | split, |
| 29 | &DataSet.GetInverseIndices()); |
| 30 | } else if (FeaturesManager.IsTreeCtr(split.FeatureId)) { |
| 31 | return CtrSplitBuilder.ComputeAndCacheCtrSplit(DataSet, |
| 32 | split); |
| 33 | } else { |
| 34 | ythrow TCatBoostException() << "Error: unknown feature"; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void Split(const TBinarySplit& split, |
| 39 | TMirrorBuffer<ui32>& bins, |
| 40 | ui32 depth) final { |
| 41 | const auto& compressedBits = GetCompressedBits(split); |
| 42 | UpdateBinFromCompressedBits(compressedBits, |
| 43 | bins, |
| 44 | depth); |
| 45 | } |
| 46 | |
| 47 | void SplitByExternalComputedFeature(const TBinarySplit& split, |
| 48 | const TSingleBuffer<const ui64>& compressedBits, |
| 49 | TMirrorBuffer<ui32>& dst, |
| 50 | ui32 depth) override { |
| 51 | CB_ENSURE(FeaturesManager.IsTreeCtr(split.FeatureId), "Feature id should be combinations ctr"); |
| 52 | |
| 53 | const auto& ctr = FeaturesManager.GetCtr(split.FeatureId); |
| 54 | |
| 55 | const ui32 docCount = DataSet.GetSamplesMapping().GetObjectsSlice().Size(); |
| 56 | const ui32 compressedSize = CompressedSize<ui64>(docCount, 2); |
| 57 | auto broadcastFunction = [&]() -> TMirrorBuffer<ui64> { |
| 58 | TMirrorBuffer<ui64> broadcastedBits = TMirrorBuffer<ui64>::Create(NCudaLib::TMirrorMapping(compressedSize)); |
| 59 | Reshard(compressedBits, broadcastedBits); |
| 60 | return broadcastedBits; |
| 61 | }; |
| 62 | |
| 63 | const auto& mirrorCompressedBits = [&]() -> const TMirrorBuffer<ui64>& { |
| 64 | if (FeaturesManager.IsPermutationDependent(ctr)) { |
| 65 | return ScopedCache.Cache(DataSet.GetPermutationDependentScope(), |
| 66 | split, |
nothing calls this directly
no test coverage detected