8 #ifndef MULTI_ARRAY_REF_OPENFPM_BASE_HPP_
9 #define MULTI_ARRAY_REF_OPENFPM_BASE_HPP_
12 #include <boost/mpl/size_t.hpp>
13 #include "boost/iterator/reverse_iterator.hpp"
14 #include "storage_order.hpp"
15 #include <boost/mpl/at.hpp>
16 #include <boost/mpl/size.hpp>
17 #include <boost/mpl/pop_front.hpp>
18 #include <boost/mpl/for_each.hpp>
19 #include <boost/mpl/range_c.hpp>
20 #include <boost/type.hpp>
32 template <typename T, int NumDims, typename vector, typename StorageOrder=typename ofp_storage_order<NumDims>::value>
33 class multi_array_ref_openfpm;
36 namespace multi_array_types
38 typedef openfpm::detail::multi_array::size_type size_type;
39 typedef std::ptrdiff_t difference_type;
40 typedef openfpm::detail::multi_array::index index;
47 template <
typename T, std::
size_t NumDims,
typename vector>
48 class sub_array_openfpm;
50 template <
typename T, std::
size_t NumDims,
typename vector,
typename TPtr = const T*>
51 class const_sub_array_openfpm;
53 template <
typename T,
typename TPtr,
typename NumDims,
typename vector,
typename Reference,
54 typename IteratorCategory>
55 class array_iterator_openfpm;
57 template <
typename T, std::
size_t NumDims,
typename TPtr = const T*>
58 class const_multi_array_view_openfpm;
60 template <
typename T, std::
size_t NumDims>
61 class multi_array_view_openfpm;
71 typedef multi_array_types::size_type size_type;
72 typedef multi_array_types::difference_type difference_type;
73 typedef multi_array_types::index index;
81 template<
typename T, std::
size_t NumDims,
typename vector>
86 typedef typename super_type::index index;
99 template <
typename Reference,
typename TPtr>
100 __device__ __host__
inline Reference access(boost::type<Reference>,
102 const index* strides,
105 TPtr newbase = base + idx * strides[0];
106 return Reference(newbase,strides+1);
113 template <
class T>
inline __device__ __host__
void ignore_unused_variable_warning_ofp(T
const&) {}
120 template<
typename T,
typename vector>
125 typedef typename super_type::index index;
130 typedef T value_type;
131 typedef T& reference;
132 typedef T
const& const_reference;
137 template <
typename Reference,
typename TPtr>
138 inline __device__ __host__ Reference access(boost::type<Reference>,index idx,
139 const index* strides,
142 return *(base + idx * strides[0]);
146 template <
typename Reference,
typename TPtr>
147 inline __device__ __host__ Reference access(boost::type<Reference>,index idx,TPtr base,
const index* strides)
const
149 BOOST_ASSERT(size_type(idx < boost::mpl::at<
vector,boost::mpl::int_<0>>::type::value));
150 return *(base + idx * strides[0]);
162 template <
typename T, std::
size_t NumDims,
typename vector>
168 template <
typename T,
typename vector>
174 template <
typename T,
typename NumDims,
typename vector>
177 BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims::value);
180 boost::mpl::eval_if_c<(dimensionality == 1),
187 template <
class T,
class NumDims,
typename vector>
199 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
200 struct mutable_iterator_tag
201 : boost::random_access_traversal_tag, std::input_iterator_tag
203 operator std::output_iterator_tag()
const {
204 return std::output_iterator_tag();
213 template <
typename T, std::
size_t NumDims,
typename vector>
219 typedef typename types::index index;
220 typedef typename types::size_type size_type;
221 typedef typename types::element element;
222 typedef typename types::value_type value_type;
223 typedef typename types::reference reference;
224 typedef typename types::const_reference const_reference;
226 template <std::
size_t NDims>
232 template <std::
size_t NDims>
238 template <std::
size_t NDims>
244 template <std::
size_t NDims>
251 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
257 boost::random_access_traversal_tag>
iterator;
262 typedef ::boost::reverse_iterator<iterator> reverse_iterator;
263 typedef ::boost::reverse_iterator<const_iterator> const_reverse_iterator;
265 BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims);
272 template <
typename StorageOrder,
typename Str
ide_list,
typename Extent_type>
273 void compute_strides(Stride_list& stride_list, Extent_type& extent)
278 boost::mpl::for_each<boost::mpl::range_c<int,0,NumDims>>([&](
auto i) {
279 constexpr
int ordering = boost::mpl::at<StorageOrder,boost::mpl::int_<i> >::type::value;
280 constexpr
int extent_i = boost::mpl::int_<boost::mpl::at<vector,boost::mpl::int_<ordering>>::type::value>::value;
284 stride_list[ordering] = stride;
294 template <
typename Reference,
typename IndexList,
typename TPtr>
295 Reference access_element(boost::type<Reference>,
296 const IndexList& indices,
298 const size_type* extents,
299 const index* strides,
300 const index* index_bases)
const
302 boost::function_requires<
303 boost::CollectionConcept<IndexList> >();
304 ignore_unused_variable_warning(index_bases);
305 ignore_unused_variable_warning(extents);
307 for (size_type i = 0; i != NumDims; ++i)
309 BOOST_ASSERT(indices[i] - index_bases[i] >= 0);
310 BOOST_ASSERT(size_type(indices[i] - index_bases[i]) < extents[i]);
316 typename IndexList::const_iterator i = indices.begin();
320 offset += (*i) * strides[n];
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