| 874 | class TDst, |
| 875 | class TSrc> |
| 876 | static void MakeQuantizedColumnWithDefaultBin( |
| 877 | const TSrc& srcFeature, |
| 878 | TValueQuantizer<TSrc> valueQuantizer, |
| 879 | ESparseArrayIndexingType sparseArrayIndexingType, |
| 880 | |
| 881 | // pass as parameter to enable type deduction |
| 882 | THolder<TDst>* dstFeature |
| 883 | ) { |
| 884 | using TDenseSrcData = TPolymorphicArrayValuesHolder<TSrc>; |
| 885 | using TSparseSrcData = TSparsePolymorphicArrayValuesHolder<TSrc>; |
| 886 | |
| 887 | Y_ASSERT(valueQuantizer.GetDstBitsPerKey() == sizeof(TStoredDstValue) * CHAR_BIT); |
| 888 | |
| 889 | ui32 defaultQuantizedBin = *valueQuantizer.GetDefaultBin(); |
| 890 | |
| 891 | TSparseArrayIndexingBuilderPtr<ui32> indexingBuilder |
| 892 | = CreateSparseArrayIndexingBuilder<ui32>(sparseArrayIndexingType); |
| 893 | |
| 894 | constexpr size_t ALLOC_BLOCK = 8192; |
| 895 | |
| 896 | TVector<ui64> quantizedDataStorage; |
| 897 | |
| 898 | ui32 nonDefaultValuesCount = 0; |
| 899 | |
| 900 | auto onSrcNonDefaultValueCallback = [&, valueQuantizer, defaultQuantizedBin] (ui32 idx, typename TSrc::TValueType value) { |
| 901 | auto quantizedBin = valueQuantizer.Quantize(value); |
| 902 | if (quantizedBin != defaultQuantizedBin) { |
| 903 | indexingBuilder->AddOrdered(idx); |
| 904 | |
| 905 | if (nonDefaultValuesCount % (ALLOC_BLOCK * sizeof(ui64) / sizeof(TStoredDstValue)) == 0) { |
| 906 | quantizedDataStorage.yresize(nonDefaultValuesCount + ALLOC_BLOCK); |
| 907 | } |
| 908 | ((TStoredDstValue*)quantizedDataStorage.data())[nonDefaultValuesCount] = quantizedBin; |
| 909 | ++nonDefaultValuesCount; |
| 910 | } |
| 911 | }; |
| 912 | |
| 913 | if (const auto* denseSrcFeature = dynamic_cast<const TDenseSrcData*>(&srcFeature)){ |
| 914 | denseSrcFeature->GetData()->ForEach(onSrcNonDefaultValueCallback); |
| 915 | } else if (const auto* sparseSrcFeature = dynamic_cast<const TSparseSrcData*>(&srcFeature)) { |
| 916 | const auto& sparseArray = sparseSrcFeature->GetData(); |
| 917 | sparseArray.ForEachNonDefault(onSrcNonDefaultValueCallback); |
| 918 | } else { |
| 919 | CB_ENSURE_INTERNAL(false, "MakeQuantizedColumnWithDefaultBin: unsupported src feature type"); |
| 920 | } |
| 921 | |
| 922 | *dstFeature = MakeHolder<TSparseCompressedValuesHolderImpl<TDst>>( |
| 923 | srcFeature.GetId(), |
| 924 | TSparseCompressedArray<typename TDst::TValueType, ui32>( |
| 925 | indexingBuilder->Build(srcFeature.GetSize()), |
| 926 | TCompressedArray( |
| 927 | nonDefaultValuesCount, |
| 928 | valueQuantizer.GetDstBitsPerKey(), |
| 929 | std::move(quantizedDataStorage) |
| 930 | ), |
| 931 | std::move(defaultQuantizedBin) |
| 932 | ) |
| 933 | ); |
nothing calls this directly
no test coverage detected