MCPcopy Create free account
hub / github.com/davisking/dlib / shuffle_samples_and_labels

Function shuffle_samples_and_labels

examples/slm_basic_train_ex.cpp:72–91  ·  view source on GitHub ↗

Function to shuffle samples and labels in sync

Source from the content-addressed store, hash-verified

70
71// Function to shuffle samples and labels in sync
72void shuffle_samples_and_labels(std::vector<matrix<int, 0, 1>>& samples, std::vector<unsigned long>& labels) {
73 std::vector<size_t> indices(samples.size());
74 std::iota(indices.begin(), indices.end(), 0); // Fill with 0, 1, 2, ..., N-1
75 std::shuffle(indices.begin(), indices.end(), std::default_random_engine{});
76
77 // Create temporary vectors to hold shuffled data
78 std::vector<matrix<int, 0, 1>> shuffled_samples(samples.size());
79 std::vector<unsigned long> shuffled_labels(labels.size());
80
81 // Apply the shuffle
82 for (size_t i = 0; i < indices.size(); ++i)
83 {
84 shuffled_samples[i] = samples[indices[i]];
85 shuffled_labels[i] = labels[indices[i]];
86 }
87
88 // Replace the original data with shuffled data
89 samples = std::move(shuffled_samples);
90 labels = std::move(shuffled_labels);
91}
92
93// ----------------------------------------------------------------------------------------
94

Callers 1

mainFunction · 0.85

Calls 4

moveFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected