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

Method Shuffle

catboost/libs/data/objects_grouping.cpp:191–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189
190
191TObjectsGroupingSubset NCB::Shuffle(
192 TObjectsGroupingPtr objectsGrouping,
193 ui32 permuteBlockSize,
194 TRestorableFastRng64* rand
195) {
196 const ui32 objectCount = objectsGrouping->GetObjectCount();
197
198 TIndexedSubset<ui32> indices;
199 indices.yresize(objectCount);
200
201 if (objectsGrouping->IsTrivial()) {
202 if (permuteBlockSize == 1) {
203 CreateShuffledIndices(objectCount, rand, &indices);
204 } else {
205 const ui32 blocksCount = (objectCount + permuteBlockSize - 1) / permuteBlockSize;
206 TVector<ui32> blockedPermute;
207 CreateShuffledIndices(blocksCount, rand, &blockedPermute);
208
209 ui32 currentIdx = 0;
210 for (ui32 i = 0; i < blocksCount; ++i) {
211 const ui32 blockStartIdx = blockedPermute[i] * permuteBlockSize;
212 const ui32 blockEndIndx = Min(blockStartIdx + permuteBlockSize, objectCount);
213 for (ui32 j = blockStartIdx; j < blockEndIndx; ++j) {
214 indices[currentIdx + j - blockStartIdx] = j;
215 }
216 currentIdx += blockEndIndx - blockStartIdx;
217 }
218 }
219 return TObjectsGroupingSubset(
220 objectsGrouping,
221 TArraySubsetIndexing<ui32>(std::move(indices)),
222 EObjectsOrder::RandomShuffled
223 );
224 } else {
225 CB_ENSURE_INTERNAL(permuteBlockSize == 1, "permuteBlockSize must be 1 if groups are present");
226
227 TIndexedSubset<ui32> groupPermute;
228 CreateShuffledIndices(objectsGrouping->GetGroupCount(), rand, &groupPermute);
229
230 const TConstArrayRef<TGroupBounds> srcGroupsBounds = objectsGrouping->GetNonTrivialGroups();
231
232 TVector<TGroupBounds> dstGroupBounds;
233 dstGroupBounds.yresize(objectsGrouping->GetGroupCount());
234
235 ui32 idxInResult = 0;
236 for (ui32 queryIdx = 0; queryIdx < (ui32)groupPermute.size(); queryIdx++) {
237 TGroupBounds srcGroupBounds = srcGroupsBounds[groupPermute[queryIdx]];
238 ui32 initialStart = srcGroupBounds.Begin;
239 ui32 resultStart = idxInResult;
240 ui32 size = srcGroupBounds.GetSize();
241 dstGroupBounds[queryIdx] = TGroupBounds(idxInResult, idxInResult + size);
242 for (ui32 doc = 0; doc < size; doc++) {
243 indices[resultStart + doc] = initialStart + doc;
244 }
245 Shuffle(indices.begin() + resultStart, indices.begin() + resultStart + size, *rand);
246 idxInResult += size;
247 }
248

Callers

nothing calls this directly

Calls 13

CreateShuffledIndicesFunction · 0.85
yresizeMethod · 0.80
GetGroupCountMethod · 0.80
GetNonTrivialGroupsMethod · 0.80
MinFunction · 0.50
moveFunction · 0.50
ShuffleFunction · 0.50
GetObjectCountMethod · 0.45
IsTrivialMethod · 0.45
sizeMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected