| 158 | } |
| 159 | |
| 160 | TDataProviderPtr NCB::DataProviderSamplerReorderBySampleIds( |
| 161 | const TDataProviderSampleParams& params, |
| 162 | TDataProviderPtr dataProvider, |
| 163 | TConstArrayRef<TString> sampleIds |
| 164 | ) { |
| 165 | const ui32 objectCount = dataProvider->GetObjectCount(); |
| 166 | |
| 167 | CB_ENSURE_INTERNAL( |
| 168 | sampleIds.size() == (size_t)objectCount, |
| 169 | "sampled dataset must have the sample number of objects as sampleIds array" |
| 170 | ); |
| 171 | |
| 172 | // resort dataset according to original sampleIds |
| 173 | THashMap<TString, TVector<ui32>> sampleIdToIdx; |
| 174 | |
| 175 | for (ui32 i : xrange(objectCount)) { |
| 176 | sampleIdToIdx[sampleIds[i]].push_back(i); |
| 177 | } |
| 178 | |
| 179 | TConstArrayRef<TString> datasetSampleIds = dataProvider->ObjectsData->GetSampleIds().GetRef(); |
| 180 | |
| 181 | TVector<ui32> finalOrder(sampleIds.size()); |
| 182 | |
| 183 | for (ui32 i : xrange(objectCount)) { |
| 184 | auto dstIt = sampleIdToIdx.find(datasetSampleIds[i]); |
| 185 | CB_ENSURE_INTERNAL(dstIt != sampleIdToIdx.end(), "dataset sampleId not found in sampleIds"); |
| 186 | auto& mappedIndices = dstIt->second; |
| 187 | CB_ENSURE_INTERNAL(!mappedIndices.empty(), "empty list of mapped indices"); |
| 188 | finalOrder[mappedIndices.back()] = i; |
| 189 | mappedIndices.pop_back(); |
| 190 | } |
| 191 | |
| 192 | if (params.OnlyFeaturesData) { |
| 193 | DegroupDataset(dataProvider.Get()); |
| 194 | } |
| 195 | |
| 196 | return dataProvider->GetSubset( |
| 197 | GetGroupingSubsetFromObjectsSubset( |
| 198 | dataProvider->ObjectsGrouping, |
| 199 | finalOrder, |
| 200 | EObjectsOrder::RandomShuffled |
| 201 | ), |
| 202 | params.CpuUsedRamLimit, |
| 203 | params.LocalExecutor |
| 204 | ); |
| 205 | } |
nothing calls this directly
no test coverage detected