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