8#ifndef MULTI_ARRAY_REF_SUBARRAY_OPENFPM_HPP_
9#define MULTI_ARRAY_REF_SUBARRAY_OPENFPM_HPP_
11#include "multi_array_view_openfpm.hpp"
12#include "multi_array_ref_base_openfpm.hpp"
18template<
typename vmpl>
21 typedef typename boost::mpl::at<vmpl,boost::mpl::int_<0>>::type type;
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::value_type value_type;
46 typedef typename super_type::const_reference const_reference;
48 typedef typename super_type::const_reverse_iterator const_reverse_iterator;
49 typedef typename super_type::element element;
50 typedef typename super_type::size_type size_type;
51 typedef typename super_type::difference_type difference_type;
52 typedef typename super_type::index index;
55 template <std::
size_t NDims>
60 template <std::
size_t NDims>
67 template <
typename Ovector>
69 :base_(rhs.base_), strides_(rhs.strides_)
74 inline __device__ __host__ const_reference operator[](index idx)
const
76 return super_type::access(boost::type<const_reference>(),idx,strides(),base_);
79 template <
typename IndexList>
80 const element& operator()(
const IndexList& indices)
const
82 boost::function_requires<boost::CollectionConcept<IndexList> >();
83 return super_type::access_element(boost::type<const element&>(),
84 indices,origin(),strides());
89 __device__ __host__
typename const_array_view<NDims>::type
90 operator[](
const boost::detail::multi_array::index_gen<NumDims,NDims>& indices)
const
92 typedef typename const_array_view<NDims>::type return_type;
93 return super_type::generate_array_view(boost::type<return_type>(),
98 template <
typename OPtr>
99 bool operator!=(
const const_sub_array_openfpm<T,NumDims,OPtr>& rhs)
const {
100 return !(*
this == rhs);
103 template <
typename OPtr>
104 bool operator>(
const const_sub_array_openfpm<T,NumDims,OPtr>& rhs)
const {
108 template <
typename OPtr>
109 bool operator<=(
const const_sub_array_openfpm<T,NumDims,OPtr>& rhs)
const {
110 return !(*
this > rhs);
113 template <
typename OPtr>
114 bool operator>=(
const const_sub_array_openfpm<T,NumDims,OPtr>& rhs)
const {
115 return !(*
this < rhs);
118 TPtr origin()
const {
return base_; }
119 inline __host__ __device__ size_type size()
const {
return boost::mpl::at<vector,boost::mpl::int_<0>>::type::value; }
120 size_type max_size()
const {
return num_elements(); }
121 bool empty()
const {
return size() == 0; }
122 inline __device__ __host__ size_type num_dimensions()
const {
return NumDims; }
123 inline __host__ __device__
const index* strides()
const {
return strides_; }
125 size_type num_elements()
const
127 return size_ct::type::value;
130 __device__ __host__ const_sub_array_openfpm (TPtr base,
const index* strides)
131 :base_(base), strides_(strides)
134#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
136 template <
typename,std::
size_t,
typename>
friend class value_accessor_n_openfpm;
137 template <
typename,std::
size_t,
typename,
typename>
friend class const_sub_array_openfpm;
144 const index* strides_;
147 const_sub_array_openfpm& operator=(
const const_sub_array_openfpm&);
155template <
typename T, std::
size_t NumDims,
typename vector>
160 typedef typename super_type::element element;
161 typedef typename super_type::reference reference;
162 typedef typename super_type::index index;
163 typedef typename super_type::size_type size_type;
165 typedef typename super_type::reverse_iterator reverse_iterator;
166 typedef typename super_type::const_reference const_reference;
168 typedef typename super_type::const_reverse_iterator const_reverse_iterator;
169 typedef int yes_is_multi_array;
172 template <std::
size_t NDims>
177 template <std::
size_t NDims>
183 template <
typename ConstMultiArray>
184 __device__ __host__
inline sub_array_openfpm& operator=(
const ConstMultiArray& other)
189 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
195 for (
int i = 0 ; i < (int)other.size() ; i++)
196 {this->operator[](i) = other[i];}
200 __device__ __host__ sub_array_openfpm& operator=(
const sub_array_openfpm& other)
204 BOOST_ASSERT(other.num_dimensions() == this->num_dimensions());
212 for (
int i = 0 ; i < (int)other.size() ; i++)
213 {this->operator[](i) = other[i];}
217 __device__ __host__ T* origin_mutable()
const {
return const_cast<T*
>(this->base_); }
218 __device__ __host__ T* origin() {
return this->base_; }
219 __device__ __host__
const T* origin()
const {
return this->base_; }
221 __device__ __host__ reference operator[](index idx) {
222 return super_type::access(boost::type<reference>(),
228 __device__ __host__ iterator begin()
230 return iterator(*this->index_bases(),origin(),
231 this->shape(),this->strides(),this->index_bases());
234 __device__ __host__ iterator end()
236 return iterator(*this->index_bases()+(index)*this->shape(),origin(),
237 this->shape(),this->strides(),this->index_bases());
241 reverse_iterator rbegin() {
242 reverse_iterator ri(end());
246 reverse_iterator rend() {
247 reverse_iterator ri(begin());
255 template <
class IndexList>
256 const element& operator()(
const IndexList& indices)
const {
257 boost::function_requires<
258 boost::CollectionConcept<IndexList> >();
259 return super_type::operator()(indices);
262 const_reference __device__ __host__ operator[](index idx)
const {
263 return super_type::operator[](idx);
266 const_iterator begin()
const {
267 return super_type::begin();
270 const_iterator end()
const {
271 return super_type::end();
274 const_reverse_iterator rbegin()
const {
275 return super_type::rbegin();
278 const_reverse_iterator rend()
const {
279 return super_type::rend();
282#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
284 template <
typename,std::
size_t,
typename>
friend class value_accessor_n_openfpm;
288 inline __device__ __host__ sub_array_openfpm (T* base,
289 const index* strides)
290 :super_type(base,strides)
300template <
typename Array,
int N,
typename vector>
302 typedef typename Array::element element;
307template <
typename Array,
int N,
typename vector>
309 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
return the dimension of the sub_array