14 #ifndef OHMMS_PETE_ARRAY_H 15 #define OHMMS_PETE_ARRAY_H 21 #include <type_traits> 24 template<
class T,
unsigned D,
typename ALLOC = std::allocator<T>>
42 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
49 template<
typename... Args>
55 inline unsigned dim()
const {
return D; }
56 inline const std::array<size_t, D>&
shape()
const {
return Length; }
64 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
67 for (
int i = 0; i <
dims.size(); i++)
73 template<
typename... Args>
76 static_assert(
sizeof...(Args) == D,
"resize arguments must match dimensionality of Array");
77 resize({
static_cast<std::size_t
>(std::forward<Args>(sizes))...});
89 template<
typename Allocator = ALLOC,
typename = qmcplusplus::IsDualSpace<Allocator>>
94 template<
typename Allocator = ALLOC,
typename = qmcplusplus::IsDualSpace<Allocator>>
103 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
108 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
113 template<
typename SIZET = size_t,
114 typename = std::is_integral<SIZET>,
115 typename Allocator = ALLOC,
121 template<
typename SIZET = size_t,
122 typename = std::is_integral<SIZET>,
123 typename Allocator = ALLOC,
130 template<
typename... Args>
133 static_assert(
sizeof...(Args) == D,
"data arguments must match dimensionality of Array");
134 return data_at({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
136 template<
typename... Args>
139 static_assert(
sizeof...(Args) == D,
"data arguments must match dimensionality of Array");
140 return data_at({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
145 static_assert(
sizeof...(Args) == D,
"device_data arguments must match dimensionality of Array");
146 return device_data_at({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
151 static_assert(
sizeof...(Args) == D,
"device_data arguments must match dimensionality of Array");
152 return device_data_at({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
180 template<
typename TT,
typename ALLOC2>
190 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
195 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
200 template<
typename... Args>
203 static_assert(
sizeof...(Args) == D,
"operator() arguments must match dimensionality of Array");
204 return operator()({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
206 template<
typename... Args>
209 static_assert(
sizeof...(Args) == D,
"operator() arguments must match dimensionality of Array");
210 return operator()({
static_cast<std::size_t
>(std::forward<Args>(indices))...});
217 for (
int i = 0; i <
X.
size(); ++i)
223 template<
typename Allocator = ALLOC,
typename = qmcplusplus::IsDualSpace<Allocator>>
228 template<
typename Allocator = ALLOC,
typename = qmcplusplus::IsDualSpace<Allocator>>
240 size_t total =
dims[0];
241 for (
int i = 1; i <
dims.size(); i++)
246 template<
typename SIZET =
size_t,
typename = std::is_
integral<SIZET>>
249 SIZET offset = indices[0];
250 for (
int i = 1; i < indices.size(); i++)
251 offset = offset *
Length[i] + indices[i];
256 template<
class T,
unsigned D,
class Alloc>
260 "operator== requires host accessible Vector.");
263 for (
int i = 0; i < rhs.
size(); i++)
264 if (lhs(i) != rhs(i))
272 template<
class T,
unsigned D,
class Alloc>
276 "operator== requires host accessible Vector.");
277 return !(lhs == rhs);
279 #endif //OHMMS_PETE_ARRAY_H const Type_t * data_at(const std::array< SIZET, D > &indices) const
void resize(size_type n, Type_t val=Type_t())
Resize the container.
std::array< size_t, D > Length
const Type_t * device_data_at(Args... indices) const
Type_t * device_data_at(Args... indices)
Container_t::const_iterator end() const
Type_t & operator()(Args... indices)
This_t & operator=(const Array< TT, D, ALLOC2 > &rhs)
Type_t * data_at(const std::array< SIZET, D > &indices)
pointer device_data()
Return the device_ptr matching X if this is a vector attached or owning dual space memory...
void updateFrom(size_type size=0, std::ptrdiff_t offset=0)
bool operator!=(const Array< T, D, Alloc > &lhs, const Array< T, D, Alloc > &rhs)
void resize(const std::array< SIZET, D > &dims)
Resize the container.
const Type_t * last_address() const
bool operator==(const Array< T, D, Alloc > &lhs, const Array< T, D, Alloc > &rhs)
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
This_t & operator=(const Array &rhs)
const Type_t * device_data_at(const std::array< SIZET, D > &indices) const
size_t full_size(const std::array< size_t, D > &dims) const
compute the full size of dims
size_type size() const
return the current size
const Type_t & operator()(const std::array< SIZET, D > &indices) const
Type_t * device_data_at(const std::array< SIZET, D > &indices)
Type_t & operator()(const std::array< SIZET, D > &indices)
void resize(Args... sizes)
Provides specialized resize(size_1, ... , size_D) functions for the array D.
template class analogous to std::allocator_traits.
void updateFrom(size_t size=0, std::ptrdiff_t offset=0)
SIZET compute_offset(const std::array< SIZET, D > &indices) const
Array(Args... sizes)
Provides specialized constructors with signature (size_1, ... , size_D) for array dimension D...
const Type_t & operator()(Args... indices) const
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
const Type_t * data_at(Args... indices) const
void updateTo(size_t size=0, std::ptrdiff_t offset=0)
const Type_t * device_data() const
Type_t * data_at(Args... indices)
Container_t::iterator begin()
std::enable_if_t< qmc_allocator_traits< Allocator >::is_dual_space > IsDualSpace
const Type_t * data() const
Array(const std::array< SIZET, D > &dims)
void updateTo(size_type size=0, std::ptrdiff_t offset=0)
const Type_t * first_address() const
A D-dimensional Array class based on PETE.
const std::array< size_t, D > & shape() const
Container_t::const_iterator begin() const
This_t & operator=(const T &rhs)
Container_t::iterator end()