32 #ifndef VSMC_CORE_PARTICLE_HPP 33 #define VSMC_CORE_PARTICLE_HPP 55 using rng_type =
typename rng_set_type::rng_type;
93 value_ = other.value_;
94 weight_ = other.weight_;
97 rng_set_ = other.rng_set_;
107 if (
this != &other) {
109 value_ = std::move(other.value_);
110 weight_ = std::move(other.weight_);
113 rng_set_ = other.rng_set_;
172 std::size_t N =
static_cast<std::size_t
>(weight_.resample_size());
173 bool resampled = weight_.ess() < threshold * N;
175 const double *
const rwptr = weight_.resample_data();
176 if (rwptr !=
nullptr) {
182 #else // VSMC_USE_TBB 185 #endif // VSMC_USE_TBB 187 op(N, N, rng_, rwptr, rep.data());
189 value_.copy(N, idx.data());
191 value_.copy(N, static_cast<const size_type *>(
nullptr));
206 ::tbb::combinable<Vector<size_type>> rep_;
207 ::tbb::combinable<Vector<size_type>> idx_;
213 #endif // VSMC_CORE_PARTICLE_HPP
static SeedGenerator< ID, ResultType > & instance()
Particle class representing the whole particle set.
sp_type sp(size_type id)
Get a SingleParticle<T> object.
typename rng_set_type::rng_type rng_type
typename std::conditional< std::is_scalar< T >::value, AlignedVector< T >, std::vector< T >>::type Vector
AlignedVector for scalar type and std::vector for others.
typename RNGSetTypeTrait< T >::type RNGSetType
const rng_type & rng(size_type id) const
Get an (parallel) RNG stream for a given particle.
sp_type end()
Get a SingleParticle<T> object for the first particle.
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.
const rng_type & rng() const
Get the (sequential) RNG used stream for resampling.
weight_type & weight()
Read and write access to the weight collection object.
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.
void resample_trans_rep_index(std::size_t M, std::size_t N, const IntType1 *replication, IntType2 *index)
Transform replication numbers into parent indices.
std::function< void(std::size_t, std::size_t, rng_type &, const double *, size_type *)> resample_type
Particle< T > & clone(Particle< T > &&other, bool retain_rng)
rng_type & rng(size_type id)
Get an (parallel) RNG stream for a given particle.
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.
sp_type begin()
Get a SingleParticle<T> object for the first particle.
A thin wrapper over a complete Particle.
rng_type & rng()
Get the (sequential) RNG used stream for resampling.
const rng_set_type & rng_set() const
Read only access to the RNG collection object.