10 #ifndef MULTI_ARRAY_REF_OPENFPM_HPP_
11 #define MULTI_ARRAY_REF_OPENFPM_HPP_
13 #include "util/cuda_util.hpp"
14 #include "boost/multi_array/collection_concept.hpp"
15 #include "boost/multi_array/concept_checks.hpp"
16 #include "boost/multi_array/algorithm.hpp"
17 #include <boost/mpl/placeholders.hpp>
18 #include <boost/mpl/accumulate.hpp>
19 #include <boost/mpl/multiplies.hpp>
20 #include <boost/concept_check.hpp>
21 #include "array_openfpm.hpp"
23 #include "multi_array_ref_base_openfpm.hpp"
24 #include "multi_array_ref_subarray_openfpm.hpp"
25 #include "storage_order.hpp"
26 #include "multi_array_iterator_openfpm.hpp"
27 #include "util/common.hpp"
33 template <
typename T, std::
size_t NumDims,
typename vector,
typename TPtr,
typename StorageOrder>
38 typedef typename boost::mpl::accumulate<
vector,
39 typename boost::mpl::int_<1>,
40 typename boost::mpl::multiplies<typename boost::mpl::_2,typename boost::mpl::_1> >::type size_ct;
45 typedef typename super_type::const_reference const_reference;
49 typedef size_t size_type;
51 typedef typename super_type::index index;
54 template <
typename ExtentType>
58 init_multi_array_ref(extents);
62 template <
class InputIterator>
63 void assign(InputIterator begin, InputIterator end)
65 boost::function_requires<boost::InputIteratorConcept<InputIterator> >();
67 InputIterator in_iter = begin;
69 std::size_t copy_count=0;
70 while (in_iter != end && copy_count < num_elements_)
72 *out_iter++ = *in_iter++;
77 size_type num_dimensions()
const {
return NumDims; }
79 size_type size()
const {
return extent_sz; }
82 size_type max_size()
const {
return num_elements(); }
84 bool empty()
const {
return size() == 0; }
86 inline __device__ __host__
const index* strides()
const {
return stride_list_.data();}
87 inline __device__ __host__
const element* origin()
const {
return base_; }
88 inline __device__ __host__
const element* data()
const {
return base_; }
90 size_type num_elements()
const {
return num_elements_; }
105 void set_base_ptr(TPtr new_base) { base_ = new_base; }
110 size_type num_elements_;
118 void init_multi_array_ref(
const index sz)
123 this->
template compute_strides<StorageOrder>(stride_list_,extent_sz);
125 num_elements_ = sz * size_ct::value;
130 template <
typename T,
int NumDims,
typename vector,
typename StorageOrder>
136 typedef typename super_type::reference reference;
139 typedef typename super_type::const_reference const_reference;
142 typedef typename super_type::element element;
143 typedef typename super_type::size_type size_type;
145 typedef typename super_type::index index;
155 template <
class ExtentType>
162 template <
typename ConstMultiArray>
165 boost::function_requires<
166 boost::multi_array_concepts::
167 ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
170 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
171 BOOST_ASSERT(std::equal(other.shape(),other.shape()+this->num_dimensions(),
174 std::copy(other.begin(),other.end(),this->begin());
178 multi_array_ref_openfpm & operator=(
const multi_array_ref_openfpm & other)
184 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
187 std::copy(other.begin(),other.end(),this->begin());
192 multi_array_ref_openfpm & bind_ref(
const multi_array_ref_openfpm & other)
194 if (&other !=
this) {
196 this->base_ = other.base_;
197 this->extent_sz = other.extent_sz;
198 this->stride_list_ = other.stride_list_;
199 this->num_elements_ = other.num_elements_;
209 void set_pointer(
void * base)
211 this->base_ =
static_cast<T *
>(base);
229 __device__ __host__
const void *
get_pointer()
const
234 multi_array_ref_openfpm & operator=(multi_array_ref_openfpm && other)
241 void swap(multi_array_ref_openfpm & other)
243 T* base_tmp = this->base_;
244 this->base_ = other.base_;
245 other.base_ = base_tmp;
247 size_type extent_tmp = this->extent_sz;
248 this->extent_sz = other.extent_sz;
249 other.extent_sz = extent_tmp;
251 index_list stride_list_tmp = this->stride_list_;
252 this->stride_list_ = other.stride_list_;
253 other.stride_list_ = stride_list_tmp;
255 size_type num_elements_tmp = this->num_elements_;
256 this->num_elements_ = other.num_elements_;
257 other.num_elements_ = num_elements_tmp;
260 __device__ __host__ element* origin() {
return super_type::base_; }
262 __device__ __host__
const element* origin()
const {
return super_type::origin(); }
264 __device__ __host__ reference operator[](index idx)
266 return super_type::access(boost::type<reference>(),
275 {
return iterator(0,origin(),this->size(),this->strides());}
278 {
return iterator(this->size(),origin(),this->size(),this->strides());}
280 __inline__ __device__ __host__ const_reference operator[](index idx)
const
282 return super_type::access(boost::type<const_reference>(),
288 const_iterator begin()
const
289 {
return super_type::begin();}
291 const_iterator end()
const
292 {
return super_type::end();}
295 template<
typename T,
typename Sfinae =
void>
int yes_is_multi_array
indicate that this class is a multi dimensional array
Implementation of 1-D std::vector like structure.
convert a type into constant type