8#ifndef MULTI_ARRAY_VIEW_OPENFPM_HPP_
9#define MULTI_ARRAY_VIEW_OPENFPM_HPP_
12#include "boost/utility/enable_if.hpp"
13#include "boost/multi_array/index_gen.hpp"
22template <
typename T, std::
size_t NumDims,
typename vector>
27 typedef typename super_type::value_type value_type;
28 typedef typename super_type::const_reference const_reference;
30 typedef typename super_type::const_reverse_iterator const_reverse_iterator;
31 typedef typename super_type::element element;
32 typedef typename super_type::size_type size_type;
33 typedef typename super_type::difference_type difference_type;
34 typedef typename super_type::index index;
35 typedef typename super_type::extent_range extent_range;
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;
43 template <std::
size_t NDims>
48 template <std::
size_t NDims>
53 template <
typename OPtr>
56 base_(other.base_), origin_offset_(other.origin_offset_),
57 num_elements_(other.num_elements_),
58 stride_list_(other.stride_list_), index_base_list_(other.index_base_list_)
62 template <
class BaseList>
67 boost::disable_if<typename boost::is_integral<BaseList>::type,
void >::type
69 reindex(
const BaseList& values)
71 boost::function_requires<
72 boost::CollectionConcept<BaseList> >();
73 boost::detail::multi_array::
74 copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
76 this->calculate_indexing_offset(stride_list_,index_base_list_);
79 void reindex(index value)
81 index_base_list_.assign(value);
83 this->calculate_indexing_offset(stride_list_,index_base_list_);
86 size_type num_dimensions()
const {
return NumDims; }
88 size_type size()
const {
return extent; }
89 size_type max_size()
const {
return num_elements(); }
90 bool empty()
const {
return size() == 0; }
92 __device__ __host__
const index* strides()
const {
93 return stride_list_.data();
96 __device__ __host__
const T* origin()
const {
return base_+origin_offset_; }
98 size_type num_elements()
const {
return num_elements_; }
100 __device__ __host__
const index* index_bases()
const {
101 return index_base_list_.data();
104 template <
typename IndexList>
105 const element& operator()(IndexList indices)
const
107 boost::function_requires<boost::CollectionConcept<IndexList> >();
108 return super_type::access_element(boost::type<const element&>(),
109 indices,origin(),strides(),index_bases());
113 __device__ __host__ const_reference operator[](index idx)
const {
114 return super_type::access(boost::type<const_reference>(),
115 idx,origin(),strides(),
121 __device__ __host__
typename const_array_view_openfpm<NDims>::type
122 operator[](
const boost::detail::multi_array::index_gen<NumDims,NDims>& indices)
const
124 typedef typename const_array_view_openfpm<NDims>::type return_type;
126 super_type::generate_array_view(boost::type<return_type>(),
133 const_iterator begin()
const {
134 return const_iterator(*index_bases(),origin(),strides(),index_bases());
137 const_reverse_iterator rend()
const {
138 return const_reverse_iterator(begin());
141 template <
typename OPtr>
142 bool operator!=(
const const_multi_array_view_openfpm<T,NumDims,OPtr>& rhs)
const
144 return !(*
this == rhs);
147 template <
typename OPtr>
149 const_multi_array_view_openfpm<T,NumDims,OPtr>& rhs)
154 template <
typename OPtr>
155 bool operator<=(
const
156 const_multi_array_view_openfpm<T,NumDims,OPtr>& rhs)
158 return !(*
this > rhs);
161 template <
typename OPtr>
162 bool operator>=(
const
163 const_multi_array_view_openfpm<T,NumDims,OPtr>& rhs)
165 return !(*
this < rhs);
169#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
171 template <
typename,std::
size_t,
typename>
friend class multi_array_impl_base_openfpm;
172 template <
typename,std::
size_t,
typename>
friend class const_multi_array_view_openfpm;
179 template <
typename ExtentType,
typename Index>
180 explicit const_multi_array_view_openfpm(TPtr base,
181 const ExtentType extent,
182 const boost::array<Index,NumDims>& strides):
183 base_(base), origin_offset_(0) ,extent(extent)
186 index_base_list_.assign(0);
189 boost::detail::multi_array::
190 copy_n(strides.begin(),NumDims,stride_list_.begin());
193 num_elements_ = extent * size_ct::type::value;
196 typedef boost::array<index,NumDims> index_list;
199 index origin_offset_;
200 size_type num_elements_;
202 index_list stride_list_;
203 index_list index_base_list_;
207 const_multi_array_view_openfpm& operator=(
const const_multi_array_view_openfpm& other);
211template <
typename T, std::
size_t NumDims>
217 typedef typename super_type::value_type value_type;
218 typedef typename super_type::reference reference;
220 typedef typename super_type::reverse_iterator reverse_iterator;
221 typedef typename super_type::const_reference const_reference;
223 typedef typename super_type::const_reverse_iterator const_reverse_iterator;
224 typedef typename super_type::element element;
225 typedef typename super_type::size_type size_type;
226 typedef typename super_type::difference_type difference_type;
227 typedef typename super_type::index index;
228 typedef typename super_type::extent_range extent_range;
231 template <std::
size_t NDims>
237 template <std::
size_t NDims>
243 template <
typename ConstMultiArray>
245 boost::function_requires<
246 boost::multi_array_concepts::
247 ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
250 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
251 BOOST_ASSERT(std::equal(other.shape(),other.shape()+this->num_dimensions(),
254 std::copy(other.begin(),other.end(),begin());
260 if (&other !=
this) {
262 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
263 BOOST_ASSERT(std::equal(other.shape(),
264 other.shape()+this->num_dimensions(),
267 std::copy(other.begin(),other.end(),begin());
272 element* origin() {
return this->base_+this->origin_offset_; }
274 template <
class IndexList>
275 element& operator()(
const IndexList& indices) {
276 boost::function_requires<
277 boost::CollectionConcept<IndexList> >();
278 return super_type::access_element(boost::type<element&>(),
280 this->shape(),this->strides(),
281 this->index_bases());
285 reference operator[](index idx) {
286 return super_type::access(boost::type<reference>(),
288 this->shape(),this->strides(),
289 this->index_bases());
310 return iterator(*this->index_bases(),origin(),
311 this->shape(),this->strides(),
312 this->index_bases());
316 return iterator(*this->index_bases()+(index)*this->shape(),origin(),
317 this->shape(),this->strides(),
318 this->index_bases());
321 reverse_iterator rbegin() {
322 return reverse_iterator(end());
325 reverse_iterator rend() {
326 return reverse_iterator(begin());
332 const element* origin()
const {
return super_type::origin(); }
334 template <
class IndexList>
335 const element& operator()(
const IndexList& indices)
const {
336 boost::function_requires<
337 boost::CollectionConcept<IndexList> >();
338 return super_type::operator()(indices);
341 const_reference operator[](index idx)
const {
342 return super_type::operator[](idx);
354 const_iterator begin()
const {
355 return super_type::begin();
358 const_iterator end()
const {
359 return super_type::end();
362 const_reverse_iterator rbegin()
const {
363 return super_type::rbegin();
366 const_reverse_iterator rend()
const {
367 return super_type::rend();
370#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
372 template <
typename,std::
size_t>
friend class multi_array_impl_base;
379 template <
typename ExtentList,
typename Index>
380 explicit multi_array_view_openfpm(T* base,
381 const ExtentList& extents,
383 super_type(base,extents,strides) { }
393template <
typename Array,
int N>
395 typedef typename Array::element element;
400template <
typename Array,
int N>
402 typedef typename Array::element element;
This class is a trick to indicate the compiler a specific specialization pattern.
Implementation of 1-D std::vector like structure.
convert a type into constant type