File indexing completed on 2026-04-09 07:49:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #pragma once
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #include <thrust/iterator/counting_iterator.h>
0053 #include <thrust/iterator/transform_iterator.h>
0054 #include <thrust/iterator/permutation_iterator.h>
0055 #include <thrust/functional.h>
0056 #include <thrust/device_vector.h>
0057
0058 template <typename Iterator>
0059 class strided_range
0060 {
0061 public:
0062
0063 typedef typename thrust::iterator_difference<Iterator>::type difference_type;
0064
0065 struct stride_functor
0066 {
0067 difference_type stride;
0068
0069 stride_functor(difference_type stride)
0070 : stride(stride) {}
0071
0072 __host__ __device__
0073 difference_type operator()(const difference_type& i) const
0074 {
0075 return stride * i;
0076 }
0077 };
0078
0079 typedef typename thrust::counting_iterator<difference_type> CountingIterator;
0080 typedef typename thrust::transform_iterator<stride_functor, CountingIterator> TransformIterator;
0081 typedef typename thrust::permutation_iterator<Iterator,TransformIterator> PermutationIterator;
0082
0083
0084 typedef PermutationIterator iterator;
0085
0086
0087 strided_range(Iterator first, Iterator last, difference_type stride)
0088 :
0089 first(first),
0090 last(last),
0091 stride(stride)
0092 {
0093 }
0094
0095 iterator begin(void) const
0096 {
0097 return PermutationIterator(first, TransformIterator(CountingIterator(0), stride_functor(stride)));
0098 }
0099
0100 iterator end(void) const
0101 {
0102 return begin() + ((last - first) + (stride - 1)) / stride;
0103 }
0104
0105 protected:
0106 Iterator first;
0107 Iterator last;
0108 difference_type stride;
0109 };
0110
0111
0112
0113