32 #ifndef VSMC_CORE_PARTICLE_HPP 33 #define VSMC_CORE_PARTICLE_HPP 56 using rng_type =
typename rng_set_type::rng_type;
57 using resample_type = std::function<void(std::size_t, std::size_t,
93 value_ = other.value_;
94 weight_ = other.weight_;
97 rng_set_ = other.rng_set_;
98 resample_rng_ = other.resample_rng_;
107 if (
this != &other) {
109 value_ = std::move(other.value_);
110 weight_ = std::move(other.weight_);
113 rng_set_ = other.rng_set_;
114 resample_rng_ = other.resample_rng_;
157 std::size_t N =
static_cast<std::size_t
>(weight_.resample_size());
158 bool resampled = weight_.ess() < threshold * N;
160 const double *
const rwptr = weight_.resample_data();
161 if (rwptr !=
nullptr) {
167 #else // VSMC_USE_TBB 170 #endif // VSMC_USE_TBB 172 op(N, N, resample_rng_, rwptr, rep.data());
174 value_.copy(N, idx.data());
176 value_.copy(N, static_cast<const size_type *>(
nullptr));
191 ::tbb::combinable<Vector<size_type>> rep_;
192 ::tbb::combinable<Vector<size_type>> idx_;
198 #endif // VSMC_CORE_PARTICLE_HPP
static SeedGenerator< ID, ResultType > & instance()
Particle class representing the whole particle set.
typename rng_set_type::rng_type rng_type
typename RNGSetTypeTrait< T >::type RNGSetType
Particle< T > clone(bool new_rng) const
Clone the particle system except the RNG engines.
value_type & value()
Read and write access to the value collection object.
typename std::conditional< std::is_scalar< T >::value, std::vector< T, AlignedAllocator< T >>, std::vector< T >>::type Vector
AlignedVector for scalar type and std::vector for others.
weight_type & weight()
Read and write access to the weight collection object.
typename ResampleRNGTypeTrait< T >::type ResampleRNGType
const weight_type & weight() const
Read only access to the weight collection object.
const value_type & value() const
Read only access to the value collection object.
Particle< T > & clone(const Particle< T > &other, bool retain_rng)
Clone another particle system except the RNG engines.
bool resample(const resample_type &op, double threshold)
Performing resampling if ESS/N < threshold.
Particle< T > & clone(Particle< T > &&other, bool retain_rng)
std::function< void(std::size_t, std::size_t, resample_rng_type &, const double *, size_type *)> resample_type
resample_rng_type & resample_rng()
Get the (sequential) RNG used stream for resampling.
rng_type & rng(size_type id)
Get an (parallel) RNG stream for a given particle.
void resample_trans_rep_index(std::size_t M, std::size_t N, const IntType1 *replication, IntType2 *src_idx)
Transform replication numbers into parent indices.
rng_set_type & rng_set()
Read and write access to the RNG collection object.
typename SizeTypeTrait< T >::type SizeType
typename WeightTypeTrait< T >::type WeightType
size_type size() const
Number of particles.
const rng_set_type & rng_set() const
Read only access to the RNG collection object.