30 #include <cugar/basic/types.h> 31 #include <cugar/basic/iterator.h> 62 typedef typename std::iterator_traits<T>::value_type value_type;
63 typedef typename std::iterator_traits<T>::reference reference;
64 typedef typename to_const<reference>::type const_reference;
65 typedef typename std::iterator_traits<T>::pointer pointer;
66 typedef typename std::iterator_traits<T>::difference_type difference_type;
68 typedef typename std::iterator_traits<T>::iterator_category iterator_category;
72 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
77 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
82 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
83 const_reference
operator*()
const {
return *m_vec; }
87 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
92 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
93 const_reference
operator[](
const uint32 i)
const {
return m_vec[i*m_stride]; }
97 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
98 reference
operator[](
const uint32 i) {
return m_vec[i*m_stride]; }
102 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
110 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
113 return (m_vec - it.m_vec) / m_stride;
118 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
131 template <
typename T>
132 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
140 template <
typename T>
141 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
144 return (it1.m_vec == it2.m_vec) && (it1.m_stride == it2.m_stride);
148 template <
typename T>
149 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
152 return (it1.m_vec != it2.m_vec) || (it1.m_stride != it2.m_stride);
156 template <
typename T>
157 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
158 bool operator<(const strided_iterator<T> it1,
const strided_iterator<T> it2) {
return (it1.m_vec < it2.m_vec); }
161 template <
typename T>
162 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
163 bool operator<=(const strided_iterator<T> it1,
const strided_iterator<T> it2) {
return (it1.m_vec <= it2.m_vec); }
166 template <
typename T>
167 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
171 template <
typename T>
172 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
175 enum block_strided_layout
177 ROW_MAJOR_LAYOUT = 0u,
178 COLUMN_MAJOR_LAYOUT = 1u
192 template <u
int32 BLOCKSIZE,
typename T, block_str
ided_layout LAYOUT = ROW_MAJOR_LAYOUT>
195 typedef typename std::iterator_traits<T>::value_type value_type;
196 typedef typename std::iterator_traits<T>::reference reference;
197 typedef typename to_const<reference>::type const_reference;
198 typedef typename std::iterator_traits<T>::pointer pointer;
199 typedef typename std::iterator_traits<T>::difference_type difference_type;
201 typedef typename std::iterator_traits<T>::iterator_category iterator_category;
205 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
210 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
211 block_strided_iterator(T vec,
const uint32 stride,
const uint32 offset = 0) : m_vec( vec ), m_offset(offset), m_stride( stride ) {}
215 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
216 const_reference
operator*()
const {
return m_vec[m_offset]; }
220 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
223 if (LAYOUT == ROW_MAJOR_LAYOUT)
224 return m_vec[((i+m_offset) / BLOCKSIZE)*m_stride + ((i+m_offset) % BLOCKSIZE)];
226 return m_vec[((i+m_offset) % BLOCKSIZE)*m_stride + ((i+m_offset) / BLOCKSIZE)];
231 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
234 if (LAYOUT == ROW_MAJOR_LAYOUT)
235 return m_vec[((i+m_offset) / BLOCKSIZE)*m_stride + ((i+m_offset) % BLOCKSIZE)];
237 return m_vec[((i+m_offset) % BLOCKSIZE)*m_stride + ((i+m_offset) / BLOCKSIZE)];
242 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
250 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
253 return (m_vec + m_offset) - (it.m_vec + it.m_offset);
258 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
272 template <u
int32 BLOCKSIZE,
typename T, block_str
ided_layout LAYOUT>
273 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
276 return (it1.m_vec == it2.m_vec) && (it1.m_offset == it2.m_offset) && (it1.m_stride == it2.m_stride);
280 template <u
int32 BLOCKSIZE,
typename T, block_str
ided_layout LAYOUT>
281 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
284 return (it1.m_vec != it2.m_vec) || (it1.m_offset != it2.m_offset) || (it1.m_stride != it2.m_stride);
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE block_strided_iterator()
Definition: strided_iterator.h:206
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE strided_iterator()
Definition: strided_iterator.h:73
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator*() const
Definition: strided_iterator.h:83
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE difference_type operator-(const block_strided_iterator< BLOCKSIZE, T > it) const
Definition: strided_iterator.h:251
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator*() const
Definition: strided_iterator.h:216
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator[](const uint32 i) const
Definition: strided_iterator.h:221
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE strided_iterator(T vec, const uint32 stride)
Definition: strided_iterator.h:78
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference operator*()
Definition: strided_iterator.h:88
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE strided_iterator< T > operator+(const uint32 i) const
Definition: strided_iterator.h:103
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE block_strided_iterator< BLOCKSIZE, T > & operator++()
Definition: strided_iterator.h:259
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE const_reference operator[](const uint32 i) const
Definition: strided_iterator.h:93
Definition: strided_iterator.h:60
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE strided_iterator< T > & operator++()
Definition: strided_iterator.h:119
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE block_strided_iterator< BLOCKSIZE, T > operator+(const uint32 i) const
Definition: strided_iterator.h:243
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE block_strided_iterator(T vec, const uint32 stride, const uint32 offset=0)
Definition: strided_iterator.h:211
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference operator[](const uint32 i)
Definition: strided_iterator.h:232
Definition: strided_iterator.h:193
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference operator[](const uint32 i)
Definition: strided_iterator.h:98
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE difference_type operator-(const strided_iterator< T > it) const
Definition: strided_iterator.h:111
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE strided_iterator< T > make_strided_iterator(T it, const uint32 stride)
Definition: strided_iterator.h:133