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"
33template <
typename T, std::
size_t NumDims,
typename vector,
typename TPtr>
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;
55 template <
typename ExtentType>
57 :base_(base),storage_(so)
59 init_multi_array_ref(extents);
63 template <
class InputIterator>
64 void assign(InputIterator begin, InputIterator end)
66 boost::function_requires<boost::InputIteratorConcept<InputIterator> >();
68 InputIterator in_iter = begin;
70 std::size_t copy_count=0;
71 while (in_iter != end && copy_count < num_elements_)
73 *out_iter++ = *in_iter++;
78 size_type num_dimensions()
const {
return NumDims; }
80 size_type size()
const {
return extent_sz; }
83 size_type max_size()
const {
return num_elements(); }
85 bool empty()
const {
return size() == 0; }
87 inline __device__ __host__
const index* strides()
const {
return stride_list_.data();}
88 inline __device__ __host__
const element* origin()
const {
return base_; }
89 inline __device__ __host__
const element* data()
const {
return base_; }
91 size_type num_elements()
const {
return num_elements_; }
106 void set_base_ptr(TPtr new_base) { base_ = new_base; }
112 size_type num_elements_;
120 void init_multi_array_ref(
const index sz)
125 this->compute_strides(stride_list_,extent_sz,storage_);
127 num_elements_ = sz * size_ct::value;
132template <
typename T,
int NumDims,
typename vector>
138 typedef typename super_type::reference reference;
141 typedef typename super_type::const_reference const_reference;
144 typedef typename super_type::element element;
145 typedef typename super_type::size_type size_type;
147 typedef typename super_type::index index;
158 template <
class ExtentType>
165 template <
typename ConstMultiArray>
168 boost::function_requires<
169 boost::multi_array_concepts::
170 ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
173 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
174 BOOST_ASSERT(std::equal(other.shape(),other.shape()+this->num_dimensions(),
177 std::copy(other.begin(),other.end(),this->begin());
181 multi_array_ref_openfpm & operator=(
const multi_array_ref_openfpm & other)
187 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
190 std::copy(other.begin(),other.end(),this->begin());
195 multi_array_ref_openfpm & bind_ref(
const multi_array_ref_openfpm & other)
197 if (&other !=
this) {
199 this->base_ = other.base_;
200 this->storage_ = other.storage_;
201 this->extent_sz = other.extent_sz;
202 this->stride_list_ = other.stride_list_;
203 this->num_elements_ = other.num_elements_;
213 void set_pointer(
void * base)
215 this->base_ =
static_cast<T *
>(base);
233 __device__ __host__
const void *
get_pointer()
const
238 multi_array_ref_openfpm & operator=(multi_array_ref_openfpm && other)
245 void swap(multi_array_ref_openfpm & other)
247 T* base_tmp = this->base_;
248 this->base_ = other.base_;
249 other.base_ = base_tmp;
251 storage_order_type storage_tmp = this->storage_;
252 this->storage_ = other.storage_;
253 other.storage_ = storage_tmp;
255 size_type extent_tmp = this->extent_sz;
256 this->extent_sz = other.extent_sz;
257 other.extent_sz = extent_tmp;
259 index_list stride_list_tmp = this->stride_list_;
260 this->stride_list_ = other.stride_list_;
261 other.stride_list_ = stride_list_tmp;
263 size_type num_elements_tmp = this->num_elements_;
264 this->num_elements_ = other.num_elements_;
265 other.num_elements_ = num_elements_tmp;
268 __device__ __host__ element* origin() {
return super_type::base_; }
270 __device__ __host__
const element* origin()
const {
return super_type::origin(); }
272 __device__ __host__ reference operator[](index idx)
274 return super_type::access(boost::type<reference>(),
283 {
return iterator(0,origin(),this->size(),this->strides());}
286 {
return iterator(this->size(),origin(),this->size(),this->strides());}
288 __inline__ __device__ __host__ const_reference operator[](index idx)
const
290 return super_type::access(boost::type<const_reference>(),
296 const_iterator begin()
const
297 {
return super_type::begin();}
299 const_iterator end()
const
300 {
return super_type::end();}
303template<
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