32 #ifndef VSMC_CORE_STATE_MATRIX_HPP 33 #define VSMC_CORE_STATE_MATRIX_HPP 38 #define VSMC_STATIC_ASSERT_CORE_STATE_MATRIX_DYNAMIC_DIM_RESIZE(Dim) \ 39 VSMC_STATIC_ASSERT((Dim == Dynamic), \ 40 "**StateMatrix::resize_dim** USED WITH A FIXED DIMENSION OBJECT") 42 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_COPY_SIZE_MISMATCH \ 43 VSMC_RUNTIME_ASSERT((N == static_cast<size_type>(this->size())), \ 44 "**StateMatrix::copy** SIZE MISMATCH") 46 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_DIM_SIZE(dim) \ 47 VSMC_RUNTIME_ASSERT((dim >= 1), "**StateMatrix** DIMENSION IS LESS THAN " \ 50 #define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_UNPACK_SIZE(psize, dim) \ 51 VSMC_RUNTIME_ASSERT((psize >= dim), \ 52 "**StateMatrix::state_unpack** INPUT PACK SIZE TOO SMALL") 60 template <std::
size_t Dim>
64 static constexpr std::size_t
dim() {
return Dim; }
76 std::size_t
dim()
const {
return dim_; }
91 template <MatrixOrder Order, std::
size_t Dim,
typename T>
109 std::size_t
dim()
const {
return this->particle().value().dim(); }
113 return this->particle().value().state(this->
id(), pos);
123 data_.resize(size_ * dim);
136 data_.swap(other.data_);
139 template <
typename OutputIter>
144 for (
size_type i = 0; i != size_; ++i, ++first)
145 *first = sptr->state(i, pos);
148 template <
typename OutputIterIter>
151 for (std::size_t d = 0; d != this->
dim(); ++d, ++first)
152 read_state(d, *first);
155 template <MatrixOrder ROrder,
typename OutputIter>
158 if (ROrder == Order) {
159 std::copy(data_.begin(), data_.end(), first);
165 for (std::size_t d = 0; d != this->
dim(); ++d)
166 *first++ = sptr->state(i, d);
168 for (std::size_t d = 0; d != this->
dim(); ++d)
170 *first++ = sptr->state(i, d);
175 template <
typename CharT,
typename Traits>
176 std::basic_ostream<CharT, Traits> &
print(
177 std::basic_ostream<CharT, Traits> &os,
char sepchar =
'\t')
const 179 if (this->
dim() == 0 || size_ == 0 || !os.good())
185 for (std::size_t d = 0; d != this->
dim() - 1; ++d)
186 os << sptr->state(i, d) << sepchar;
187 os << sptr->state(i, this->
dim() - 1) <<
'\n';
201 template <
typename CharT,
typename Traits,
MatrixOrder Order, std::size_t Dim,
204 std::basic_ostream<CharT, Traits> &os,
207 return smatrix.
print(os);
212 template <std::
size_t Dim,
typename T>
225 return this->data()[
id * this->
dim() + pos];
230 return this->data()[
id * this->
dim() + pos];
233 using state_matrix_base_type::data;
241 return this->data() +
id * this->
dim();
246 return this->data() +
id * this->
dim();
249 template <
typename IntType>
255 copy_particle(src_idx[dst], dst);
263 copy_particle_dispatch(src, dst, std::integral_constant <
bool,
264 Dim ==
Dynamic || 8 < Dim > ());
270 std::copy(row_data(
id), row_data(
id) + this->
dim(), pack.data());
278 pack.size(), this->
dim());
287 pack.size(), this->
dim());
290 std::move(ptr, ptr + this->
dim(), row_data(
id));
296 std::copy(row_data(src), row_data(src) + this->
dim(), row_data(dst));
301 copy_particle_pos<0>(row_data(src), row_data(dst),
302 std::integral_constant<bool, 0 < Dim>());
305 template <std::
size_t D>
310 template <std::
size_t D>
311 void copy_particle_pos(
315 copy_particle_pos<D + 1>(
316 src, dst, std::integral_constant<bool, D + 1 < Dim>());
322 template <std::
size_t Dim,
typename T>
335 return this->data()[pos * this->size() + id];
340 return this->data()[pos * this->size() + id];
343 using state_matrix_base_type::data;
351 return this->data() + pos * this->size();
356 return this->data() + pos * this->size();
359 template <
typename IntType>
364 for (std::size_t d = 0; d != this->
dim(); ++d)
366 state(dst, d) = state(static_cast<size_type>(src_idx[dst]), d);
374 copy_particle_dispatch(src, dst, std::integral_constant <
bool,
375 Dim ==
Dynamic || 8 < Dim > ());
381 for (std::size_t d = 0; d != this->
dim(); ++d)
382 pack[d] = state(
id, d);
390 pack.size(), this->
dim());
392 for (std::size_t d = 0; d != this->
dim(); ++d)
393 state(
id, d) = pack[d];
399 pack.size(), this->
dim());
401 for (std::size_t d = 0; d != this->
dim(); ++d)
402 state(
id, d) = std::move(pack[d]);
408 for (std::size_t d = 0; d != this->
dim(); ++d)
409 state(dst, d) = state(src, d);
414 copy_particle_pos<0>(this->data() + src, this->data() + dst,
415 std::integral_constant<bool, 0 < Dim>());
418 template <std::
size_t D>
423 template <std::
size_t D>
424 void copy_particle_pos(
427 dst[D * this->size()] = src[D * this->size()];
428 copy_particle_pos<D + 1>(
429 src, dst, std::integral_constant<bool, D + 1 < Dim>());
435 #endif // VSMC_CORE_STATE_MATRIX_HPP
T & state(size_type id, std::size_t pos)
Particle class representing the whole particle set.
StateMatrixBase(size_type N)
state_type * row_data(size_type id)
typename state_matrix_base_type::state_pack_type state_pack_type
Base type of StateMatrix.
state_type * data(size_type id)
void state_unpack(size_type id, const state_pack_type &pack)
const state_type * data() const
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_DIM_SIZE(dim)
const T & state(size_type id, std::size_t pos) const
const T & state(size_type id, std::size_t pos) const
state_type * data(size_type pos)
const state_type * col_data(std::size_t pos) const
Used to specify a dimension template parameter is dynamic.
state_type & state(std::size_t pos) const
typename state_matrix_base_type::size_type size_type
const state_type * row_data(size_type id) const
void copy_particle(size_type src, size_type dst)
std::basic_ostream< CharT, Traits > & print(std::basic_ostream< CharT, Traits > &os, char sepchar= '\t') const
void state_unpack(size_type id, state_pack_type &&pack)
void copy(size_type N, const IntType *src_idx)
void copy(size_type N, const IntType *src_idx)
void copy_particle(size_type src, size_type dst)
void copy(std::size_t n, const T *x, std::size_t incx, T *y, std::size_t incy)
Copies vector to another vector.
typename state_matrix_base_type::state_pack_type state_pack_type
state_pack_type state_pack(size_type id) const
Data are stored column by column in memory.
typename state_matrix_base_type::state_type state_type
#define VSMC_STATIC_ASSERT_CORE_STATE_MATRIX_DYNAMIC_DIM_RESIZE(Dim)
void resize_dim(std::size_t dim)
static constexpr std::size_t dim()
void state_unpack(size_type id, state_pack_type &&pack)
state_pack_type state_pack(size_type id) const
Data are stored row by row in memory.
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Sampler< T > &sampler)
void swap(const MKLBase< MKLPtr, Derived > &ptr1, const MKLBase< MKLPtr, Derived > &ptr2)
Swap two MKLBase objects.
void resize_dim(std::size_t dim)
single_particle_type(typename Particle< S >::size_type id, Particle< S > *pptr)
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_COPY_SIZE_MISMATCH
const state_type * data(size_type pos) const
void swap(StateMatrixDim< Dim > &)
A thin wrapper over a complete Particle.
void read_state(std::size_t pos, OutputIter first) const
state_type * col_data(std::size_t pos)
typename state_matrix_base_type::state_type state_type
void swap(StateMatrixBase< Order, Dim, T > &other)
void read_state_matrix(OutputIterIter first) const
const state_type * data(size_type id) const
#define VSMC_RUNTIME_ASSERT_CORE_STATE_MATRIX_UNPACK_SIZE(psize, dim)
T & state(size_type id, std::size_t pos)
void swap(StateMatrixDim< Dynamic > &other)
void read_state_matrix(OutputIter first) const
void state_unpack(size_type id, const state_pack_type &pack)
typename state_matrix_base_type::size_type size_type