32 #ifndef VSMC_RESAMPLE_COMMON_HPP
33 #define VSMC_RESAMPLE_COMMON_HPP
46 #ifndef VSMC_RESAMPLE_RNG_TYPE
47 #define VSMC_RESAMPLE_RNG_TYPE ::vsmc::Threefry4x64
60 template <
typename IntType>
62 const double *weight,
const double *u01, IntType *replication,
69 *replication =
static_cast<IntType
>(N);
79 std::partial_sum(weight, weight + M, accw_.begin());
83 std::copy(u01, u01 + N, u01_.begin());
85 std::sort(u01_.begin(), u01_.end());
89 std::size_t offset = 0;
90 for (std::size_t i = 0; i != M; ++i) {
91 while (offset != N && u01_[offset] <= accw_[i]) {
100 std::vector<double, AlignedAllocator<double> > accw_;
101 std::vector<double, AlignedAllocator<double> > u01_;
123 template <ResampleScheme Scheme>
136 template <
typename IntType1,
typename IntType2>
138 const IntType1 *, IntType2 *)
const {}
147 template <
typename IntType1,
typename IntType2>
149 const IntType1 *replication, IntType2 *copy_from)
const
154 for (std::size_t to = 0; to != N; ++to) {
155 if (replication[to] != 0) {
156 copy_from[to] =
static_cast<IntType2
>(to);
159 if (replication[from] < time + 2) {
164 while (replication[from] < 2);
166 copy_from[to] = from;
172 for (std::size_t from = 0; from != M; ++from)
173 for (IntType1 i = 0; i != replication[from]; ++i)
174 copy_from[to++] = static_cast<IntType2>(from);
183 template <
typename WeightSetType>
185 {weight_set.set_equal_weight();}
209 #endif // VSMC_RESAMPLE_COMMON_HPP
Resampling type of the built-in schemes.
Transform replication numbers to parent particle locations.
Transform replication numbers to parent particle locations.
void operator()(std::size_t M, std::size_t N, const IntType1 *replication, IntType2 *copy_from) const
ResampleScheme
Resampling schemes.
void * memset(void *dst, int ch, std::size_t n)
SIMD optimized memset with non-temporal store for large buffers.
#define VSMC_DEFINE_TYPE_DISPATCH_TRAIT(Outer, Inner, Default)
#define VSMC_RESAMPLE_RNG_TYPE
Default RNG type for resampling.
Resample< cxx11::integral_constant< ResampleScheme, Scheme > > type
void operator()(WeightSetType &weight_set) const
Resample forward decleration.
Systematic resampling on residuals.
Stratified resampling on residuals.
void operator()(std::size_t M, std::size_t N, const double *weight, const double *u01, IntType *replication, bool usorted=false)
void operator()(std::size_t, std::size_t, const IntType1 *, IntType2 *) const