| 157 | |
| 158 | |
| 159 | static ui64 EstimateMemUsageForFloatFeature( |
| 160 | const TFloatValuesHolder& srcFeature, |
| 161 | const TQuantizedFeaturesInfo& quantizedFeaturesInfo, |
| 162 | const TQuantizationOptions& options, |
| 163 | bool doQuantization, // if false - only calc borders |
| 164 | bool storeFeaturesDataAsExternalValuesHolder |
| 165 | ) { |
| 166 | ui64 result = 0; |
| 167 | |
| 168 | size_t borderCount; |
| 169 | |
| 170 | ui32 nonDefaultObjectCount = GetNonDefaultValuesCount(srcFeature); |
| 171 | |
| 172 | const TFloatFeatureIdx floatFeatureIdx |
| 173 | = quantizedFeaturesInfo.GetPerTypeFeatureIdx<EFeatureType::Float>(srcFeature); |
| 174 | |
| 175 | if (!quantizedFeaturesInfo.HasBorders(floatFeatureIdx)) { |
| 176 | // sampleSize is computed using defaultBinarizationSettings for now |
| 177 | const auto& defaultBinarizationSettings |
| 178 | = quantizedFeaturesInfo.GetFloatFeatureBinarization(Max<ui32>()); |
| 179 | |
| 180 | const ui32 sampleSize = GetSampleSizeForBorderSelectionType( |
| 181 | srcFeature.GetSize(), |
| 182 | defaultBinarizationSettings.BorderSelectionType, |
| 183 | options.MaxSubsetSizeForBuildBordersAlgorithms |
| 184 | ); |
| 185 | |
| 186 | ui32 nonDefaultSampleSize; |
| 187 | TMaybe<TDefaultValue<float>> defaultValue; |
| 188 | |
| 189 | if (/* const auto* denseData = */ dynamic_cast<const TFloatArrayValuesHolder*>(&srcFeature)) { |
| 190 | nonDefaultSampleSize = sampleSize; |
| 191 | } else if (const auto* sparseData = dynamic_cast<const TFloatSparseValuesHolder*>(&srcFeature)) { |
| 192 | const auto& sparseArray = sparseData->GetData(); |
| 193 | |
| 194 | // random shuffle with select default and non-default values in this proportion |
| 195 | nonDefaultSampleSize |
| 196 | = (sampleSize * sparseArray.GetNonDefaultSize()) / sparseArray.GetSize(); |
| 197 | const ui64 defaultSize = sparseArray.GetSize() - sparseArray.GetNonDefaultSize(); |
| 198 | if (defaultSize) { |
| 199 | defaultValue.ConstructInPlace( |
| 200 | sparseArray.GetDefaultValue(), |
| 201 | Max((sampleSize * defaultSize) / sparseArray.GetSize(), ui64(1)) |
| 202 | ); |
| 203 | } |
| 204 | } else { |
| 205 | CB_ENSURE_INTERNAL(false, "EstimateMemUsageForFloatFeature: Unsupported column type"); |
| 206 | } |
| 207 | |
| 208 | result += sizeof(float) * nonDefaultSampleSize; // for copying to srcFeatureValuesForBuildBorders |
| 209 | |
| 210 | const auto& floatFeatureBinarizationSettings |
| 211 | = quantizedFeaturesInfo.GetFloatFeatureBinarization(srcFeature.GetId()); |
| 212 | |
| 213 | borderCount = floatFeatureBinarizationSettings.BorderCount.Get(); |
| 214 | |
| 215 | result += NSplitSelection::CalcMemoryForFindBestSplit( |
| 216 | SafeIntegerCast<int>(borderCount), |
no test coverage detected