Restoring the correct behavior of UniqueSampler
parent
b61636e2f7
commit
cb80f27ee8
|
@ -107,7 +107,7 @@ static vector<size_t> UniqueSampler(const vector<double> &weight,
|
|||
const size_t m = weight.size();
|
||||
if (n > m) throw std::invalid_argument("UniqueSampler: invalid input size");
|
||||
|
||||
vector<size_t> samples;
|
||||
vector<size_t> results;
|
||||
|
||||
size_t count = 0;
|
||||
vector<bool> touched(m, false);
|
||||
|
@ -127,16 +127,15 @@ static vector<size_t> UniqueSampler(const vector<double> &weight,
|
|||
|
||||
/* sampling and cache results */
|
||||
vector<size_t> samples = iidSampler(localWeights, n - count);
|
||||
const auto samplesSize = samples.size();
|
||||
for (size_t index = 0; index < samplesSize; index++) {
|
||||
for (const size_t &index : samples) {
|
||||
if (touched[index] == false) {
|
||||
touched[index] = true;
|
||||
samples.push_back(index);
|
||||
results.push_back(index);
|
||||
if (++count >= n) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return samples;
|
||||
return results;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue