32 #ifndef VSMC_CORE_STATE_MATRIX_HPP
33 #define VSMC_CORE_STATE_MATRIX_HPP
40 #define VSMC_STATIC_ASSERT_CORE_STATE_MATRIX_DYNAMIC_DIM_RESIZE(Dim) \
41 VSMC_STATIC_ASSERT((Dim == Dynamic), \
42 USE_METHOD_resize_dim_WITH_A_FIXED_SIZE_StateMatrix_OBJECT)
44 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_COPY_SIZE_MISMATCH \
45 VSMC_RUNTIME_ASSERT((N == static_cast<size_type>(this->size())), \
46 ("**StateMatrix::copy** SIZE MISMATCH"))
48 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_DIM_SIZE(dim) \
49 VSMC_RUNTIME_ASSERT((dim >= 1), \
50 ("**StateMatrix** DIMENSION IS LESS THAN 1"))
52 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_UNPACK_SIZE(psize, dim) \
53 VSMC_RUNTIME_ASSERT((psize >= dim), \
54 ("**StateMatrix::state_unpack** INPUT PACK SIZE TOO SMALL"))
60 template <MatrixOrder Order, std::
size_t Dim,
typename T>
79 state_type &
state (std::size_t pos)
const
82 template <std::
size_t Pos>
84 {
return this->
state(Pos);}
86 template <std::
size_t Pos>
88 {
return this->
state(Pos);}
100 const state_type &
state (std::size_t pos)
const
103 template <std::
size_t Pos>
105 {
return this->
state(Pos);}
107 template <std::
size_t Pos>
109 {
return this->
state(Pos);}
118 data_.resize(size_ * dim);
121 size_type
size ()
const {
return size_;}
129 const state_type &
operator() (std::size_t i, std::size_t pos)
const
137 const T *
data ()
const {
return &data_[0];}
139 template <
typename OutputIter>
144 for (size_type i = 0; i != size_; ++i, ++first)
145 *first = sptr->state(i, pos);
148 template <std::
size_t Pos,
typename OutputIter>
152 template <std::
size_t Pos,
typename OutputIter>
156 template <
typename OutputIterIter>
159 for (std::size_t d = 0; d != this->
dim(); ++d, ++first)
163 template <MatrixOrder ROrder,
typename OutputIter>
166 if (ROrder == Order) {
167 std::copy(data_.begin(), data_.end(), first);
172 for (size_type i = 0; i != size_; ++i) {
173 for (std::size_t d = 0; d != this->
dim(); ++d) {
174 *first = sptr->state(i, d);
179 for (std::size_t d = 0; d != this->
dim(); ++d) {
180 for (size_type i = 0; i != size_; ++i) {
181 *first = sptr->state(i, d);
189 template <
typename CharT,
typename Traits>
190 std::basic_ostream<CharT, Traits> &
print (
191 std::basic_ostream<CharT, Traits> &os,
char sepchar =
'\t')
const
193 if (this->
dim() == 0 || size_ == 0 || !os.good())
198 for (size_type i = 0; i != size_; ++i) {
199 for (std::size_t d = 0; d != this->
dim() - 1; ++d)
200 os << sptr->state(i, d) << sepchar;
201 os << sptr->state(i, this->
dim() - 1) <<
'\n';
213 return create_pack_dispatch(
221 std::vector<T, AlignedAllocator<T> >,
222 std::vector<T> >
::type data_;
227 {
return std::vector<T>(this->
dim());}
230 {
return Array<T, Dim>();}
233 template <
typename CharT,
typename Traits,
236 std::basic_ostream<CharT, Traits> &os,
238 {
return smatrix.
print(os);}
242 template <std::
size_t Dim,
typename T>
253 T &
state (size_type
id, std::size_t pos)
254 {
return this->data()[
id * this->dim() + pos];}
256 const T &
state (size_type
id, std::size_t pos)
const
257 {
return this->data()[
id * this->dim() + pos];}
259 template <std::
size_t Pos>
261 {
return state(
id, Pos);}
263 template <std::
size_t Pos>
265 {
return state(
id, Pos);}
267 template <std::
size_t Pos>
269 {
return state(
id, Pos);}
271 template <std::
size_t Pos>
273 {
return state(
id, Pos);}
276 {
return this->data() +
id * this->dim();}
279 {
return this->data() +
id * this->dim();}
281 template <
typename IntType>
282 void copy (size_type N,
const IntType *copy_from)
286 for (size_type to = 0; to != N; ++to)
287 copy_particle(copy_from[to], to);
295 std::copy(row_data(from), row_data(from + 1), row_data(to));
300 state_pack_type pack(this->create_pack());
301 std::copy(row_data(
id), row_data(
id + 1), &pack[0]);
309 pack.
size(), this->dim());
311 const T *ptr = &pack[0];
312 std::copy(ptr, ptr + this->dim(), row_data(
id));
315 #if VSMC_HAS_CXX11_RVALUE_REFERENCES && VSMC_HAS_CXX11LIB_ALGORITHM
316 void state_unpack (size_type
id, state_pack_type &&pack)
319 pack.size(), this->dim());
321 const T *ptr = &pack[0];
322 std::move(ptr, ptr + this->dim(), row_data(
id));
329 template <std::
size_t Dim,
typename T>
340 T &
state (size_type
id, std::size_t pos)
341 {
return this->data()[pos * this->size() + id];}
343 const T &
state (size_type
id, std::size_t pos)
const
344 {
return this->data()[pos * this->size() + id];}
346 template <std::
size_t Pos>
348 {
return state(
id, Pos);}
350 template <std::
size_t Pos>
352 {
return state(
id, Pos);}
354 template <std::
size_t Pos>
356 {
return state(
id, Pos);}
358 template <std::
size_t Pos>
360 {
return state(
id, Pos);}
363 {
return this->data() + pos * this->size();}
366 {
return this->data() + pos * this->size();}
368 template <
typename IntType>
369 void copy (size_type N,
const IntType *copy_from)
373 for (size_type to = 0; to != N; ++to)
374 copy_particle(copy_from[to], to);
382 for (std::size_t d = 0; d != this->dim(); ++d)
383 state(to, d) = state(from, d);
388 state_pack_type pack(this->create_pack());
389 for (std::size_t d = 0; d != this->dim(); ++d)
390 pack[d] = state(
id, d);
398 pack.
size(), this->dim());
400 for (std::size_t d = 0; d != this->dim(); ++d)
401 state(
id, d) = pack[d];
404 #if VSMC_HAS_CXX11_RVALUE_REFERENCES
408 pack.size(), this->dim());
410 for (std::size_t d = 0; d != this->dim(); ++d)
418 #endif // VSMC_CORE_STATE_MATRIX_HPP
const Particle< S > * particle_ptr() const
T & state(size_type id, std::size_t pos)
Particle class representing the whole particle set.
StateMatrixBase(size_type N)
Particle< S > * mutable_particle_ptr() const
state_matrix_base_type::state_pack_type state_pack_type
void state_unpack(size_type id, const state_pack_type &pack)
state_type & state(std::size_t pos) const
T * col_data(std::size_t pos)
state_type & state() const
const T & state(size_type id, std::size_t pos) const
const T & state(size_type id, std::size_t pos) const
StateMatrixBase< RowMajor, Dim, T > state_matrix_base_type
state_pack_type create_pack() const
value_type & value()
Read and write access to the value collection object.
const T & state(size_type id) const
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_UNPACK_SIZE(psize, dim)
T * row_data(size_type id)
void copy_particle(size_type from, size_type to)
std::basic_ostream< CharT, Traits > & print(std::basic_ostream< CharT, Traits > &os, char sepchar= '\t') const
state_matrix_base_type::size_type size_type
StateMatrixBase< ColMajor, Dim, T > state_matrix_base_type
static constexpr std::size_t dim()
integral_constant< bool, false > false_type
Function template argument used for position.
state_pack_type state_pack(size_type id) const
void read_state(OutputIter first) const
Data are stored column by column in memory.
const state_type & state() const
state_type & operator()(std::size_t i, std::size_t pos)
void resize_dim(std::size_t dim)
Used to specify a dimension template parameter is dynamic.
void state_unpack(size_type id, state_pack_type &&pack)
state_pack_type state_pack(size_type id) const
Dimension trait for StateMatrix and StateCL (fixed dimension)
state_matrix_base_type::size_type size_type
const state_type & state(Position< Pos >) const
cxx11::conditional< Dim==Dynamic, std::vector< T >, Array< T, Dim > >::type state_pack_type
Data are stored row by row in memory.
remove_reference< T >::type && move(T &&t) noexcept
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Sampler< T > &sampler)
A const variant to SingleParticle.
state_type & state(Position< Pos >) const
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_COPY_SIZE_MISMATCH
const_single_particle_type(typename Particle< S >::size_type id, const Particle< S > *particle_ptr)
const T & state(size_type id, Position< Pos >) const
const T * row_data(size_type id) const
A thin wrapper over a complete Particle.
T & state(size_type id, Position< Pos >)
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_DIM_SIZE(dim)
void read_state(std::size_t pos, OutputIter first) const
void copy_particle(size_type from, size_type to)
T & state(size_type id, Position< Pos >)
void copy(size_type N, const IntType *copy_from)
void read_state_matrix(OutputIterIter first) const
const T & state(size_type id, Position< Pos >) const
single_particle_type(typename Particle< S >::size_type id, Particle< S > *particle_ptr)
const Particle< S > * particle_ptr() const
const T * col_data(std::size_t pos) const
T & state(size_type id, std::size_t pos)
void copy(size_type N, const IntType *copy_from)
void read_state(Position< Pos >, OutputIter first) const
void read_state_matrix(OutputIter first) const
state_matrix_base_type::state_pack_type state_pack_type
const T & state(size_type id) const
void state_unpack(size_type id, const state_pack_type &pack)
#define VSMC_STATIC_ASSERT_CORE_STATE_MATRIX_DYNAMIC_DIM_RESIZE(Dim)
static constexpr size_type size()
const state_type & state(std::size_t pos) const