~ubuntu-branches/ubuntu/utopic/libthrust/utopic

« back to all changes in this revision

Viewing changes to scatter.h

  • Committer: Package Import Robot
  • Author(s): Andreas Beckmann
  • Date: 2013-07-10 12:57:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130710125733-my19jic71sqsabaj
Tags: 1.7.0-1
* New upstream release.  (Closes: #715362)
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#pragma once
23
23
 
24
24
#include <thrust/detail/config.h>
 
25
#include <thrust/detail/execution_policy.h>
25
26
 
26
27
namespace thrust
27
28
{
28
29
 
 
30
 
29
31
/*! \addtogroup scattering
30
32
 *  \ingroup copying
31
33
 *  \{
32
34
 */
33
35
 
34
 
/*! \p scatter copies elements from a source range into an output array
35
 
 *  according to a map. For each iterator \c i in the range [\p first, \p last),
36
 
 *  the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>. The 
37
 
 *  output iterator must permit random access. If the same index 
38
 
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>,
39
 
 *  the result is undefined.
40
 
 *
41
 
 *  \param first Beginning of the sequence of values to scatter.
42
 
 *  \param last End of the sequence of values to scatter.
43
 
 *  \param map  Beginning of the sequence of output indices.
44
 
 *  \param output Destination of the source elements.
45
 
 *
46
 
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
47
 
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
48
 
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
36
 
 
37
/*! \p scatter copies elements from a source range into an output array
 
38
 *  according to a map. For each iterator \c i in the range [\p first, \p last),
 
39
 *  the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>. The 
 
40
 *  output iterator must permit random access. If the same index 
 
41
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>,
 
42
 *  the result is undefined.
 
43
 *
 
44
 *  The algorithm's execution is parallelized as determined by \p exec.
 
45
 *
 
46
 *  \param exec The execution policy to use for parallelization.
 
47
 *  \param first Beginning of the sequence of values to scatter.
 
48
 *  \param last End of the sequence of values to scatter.
 
49
 *  \param map  Beginning of the sequence of output indices.
 
50
 *  \param result Destination of the source elements.
 
51
 *
 
52
 *  \tparam DerivedPolicy The name of the derived execution policy.
 
53
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
 
54
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
 
55
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
56
 *
 
57
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
58
 *
 
59
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
60
 *
 
61
 *  \pre The expression `result[*i]` shall be valid for all iterators in the range `[map,map + (last - first))`.
 
62
 *
 
63
 *  The following code snippet demonstrates how to use \p scatter to
 
64
 *  reorder a range using the \p thrust::device execution policy for parallelization:
 
65
 *
 
66
 *  \code
 
67
 *  #include <thrust/scatter.h>
 
68
 *  #include <thrust/device_vector.h>
 
69
 *  #include <thrust/execution_policy.h>
 
70
 *  ...
 
71
 *  // mark even indices with a 1; odd indices with a 0
 
72
 *  int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
 
73
 *  thrust::device_vector<int> d_values(values, values + 10);
 
74
 *
 
75
 *  // scatter all even indices into the first half of the
 
76
 *  // range, and odd indices vice versa
 
77
 *  int map[10]   = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9};
 
78
 *  thrust::device_vector<int> d_map(map, map + 10);
 
79
 *
 
80
 *  thrust::device_vector<int> d_output(10);
 
81
 *  thrust::scatter(thrust::device,
 
82
 *                  d_values.begin(), d_values.end(),
 
83
 *                  d_map.begin(), d_output.begin());
 
84
 *  // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
 
85
 *  \endcode
 
86
 *
 
87
 *  \note \p scatter is the inverse of thrust::gather.
 
88
 */
 
89
template<typename DerivedPolicy,
 
90
         typename InputIterator1,
 
91
         typename InputIterator2,
 
92
         typename RandomAccessIterator>
 
93
  void scatter(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
 
94
               InputIterator1 first,
 
95
               InputIterator1 last,
 
96
               InputIterator2 map,
 
97
               RandomAccessIterator result);
 
98
 
 
99
 
 
100
/*! \p scatter copies elements from a source range into an output array
 
101
 *  according to a map. For each iterator \c i in the range [\p first, \p last),
 
102
 *  the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>. The 
 
103
 *  output iterator must permit random access. If the same index 
 
104
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>,
 
105
 *  the result is undefined.
 
106
 *
 
107
 *  \param first Beginning of the sequence of values to scatter.
 
108
 *  \param last End of the sequence of values to scatter.
 
109
 *  \param map  Beginning of the sequence of output indices.
 
110
 *  \param result Destination of the source elements.
 
111
 *
 
112
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
 
113
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
 
114
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
115
 *
 
116
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
117
 *
 
118
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
119
 *
 
120
 *  \pre The expression `result[*i]` shall be valid for all iterators in the range `[map,map + (last - first))`.
49
121
 *
50
122
 *  The following code snippet demonstrates how to use \p scatter to
51
123
 *  reorder a range.
77
149
  void scatter(InputIterator1 first,
78
150
               InputIterator1 last,
79
151
               InputIterator2 map,
80
 
               RandomAccessIterator output);
81
 
 
82
 
 
83
 
/*! \p scatter_if conditionally copies elements from a source range into an 
84
 
 *  output array according to a map. For each iterator \c i in the 
85
 
 *  range <tt>[first, last)</tt> such that <tt>*(stencil + (i - first))</tt> is
86
 
 *  true, the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>.
87
 
 *  The output iterator must permit random access. If the same index 
88
 
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>
89
 
 *  the result is undefined.
90
 
 *
91
 
 *  \param first Beginning of the sequence of values to scatter.
92
 
 *  \param last End of the sequence of values to scatter.
93
 
 *  \param map Beginning of the sequence of output indices.
94
 
 *  \param stencil Beginning of the sequence of predicate values.
95
 
 *  \param output Beginning of the destination range.
96
 
 *
97
 
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
98
 
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
99
 
 *  \tparam InputIterator3 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator3's \c value_type must be convertible to \c bool.
100
 
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
152
               RandomAccessIterator result);
 
153
 
 
154
 
 
155
/*! \p scatter_if conditionally copies elements from a source range into an 
 
156
 *  output array according to a map. For each iterator \c i in the 
 
157
 *  range <tt>[first, last)</tt> such that <tt>*(stencil + (i - first))</tt> is
 
158
 *  true, the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>.
 
159
 *  The output iterator must permit random access. If the same index 
 
160
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>
 
161
 *  the result is undefined.
 
162
 *
 
163
 *  The algorithm's execution is parallelized as determined by \p exec.
 
164
 *
 
165
 *  \param exec The execution policy to use for parallelization.
 
166
 *  \param first Beginning of the sequence of values to scatter.
 
167
 *  \param last End of the sequence of values to scatter.
 
168
 *  \param map Beginning of the sequence of output indices.
 
169
 *  \param stencil Beginning of the sequence of predicate values.
 
170
 *  \param output Beginning of the destination range.
 
171
 *
 
172
 *  \tparam DerivedPolicy The name of the derived execution policy.
 
173
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
 
174
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
 
175
 *  \tparam InputIterator3 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator3's \c value_type must be convertible to \c bool.
 
176
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
177
 *
 
178
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
179
 *
 
180
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
181
 *
 
182
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
183
 *
 
184
 *  \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `*(stencil + i) != false`.
 
185
 *
 
186
 *  \code
 
187
 *  #include <thrust/scatter.h>
 
188
 *  #include <thrust/execution_policy.h>
 
189
 *  ...
 
190
 *  int V[8] = {10, 20, 30, 40, 50, 60, 70, 80};
 
191
 *  int M[8] = {0, 5, 1, 6, 2, 7, 3, 4};
 
192
 *  int S[8] = {1, 0, 1, 0, 1, 0, 1, 0};
 
193
 *  int D[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 
194
 * 
 
195
 *  thrust::scatter_if(thrust::host, V, V + 8, M, S, D);
 
196
 * 
 
197
 *  // D contains [10, 30, 50, 70, 0, 0, 0, 0];
 
198
 *  \endcode
 
199
 *
 
200
 *  \note \p scatter_if is the inverse of thrust::gather_if.
 
201
 */
 
202
template<typename DerivedPolicy,
 
203
         typename InputIterator1,
 
204
         typename InputIterator2,
 
205
         typename InputIterator3,
 
206
         typename RandomAccessIterator>
 
207
  void scatter_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
 
208
                  InputIterator1 first,
 
209
                  InputIterator1 last,
 
210
                  InputIterator2 map,
 
211
                  InputIterator3 stencil,
 
212
                  RandomAccessIterator output);
 
213
 
 
214
 
 
215
/*! \p scatter_if conditionally copies elements from a source range into an 
 
216
 *  output array according to a map. For each iterator \c i in the 
 
217
 *  range <tt>[first, last)</tt> such that <tt>*(stencil + (i - first))</tt> is
 
218
 *  true, the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>.
 
219
 *  The output iterator must permit random access. If the same index 
 
220
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>
 
221
 *  the result is undefined.
 
222
 *
 
223
 *  \param first Beginning of the sequence of values to scatter.
 
224
 *  \param last End of the sequence of values to scatter.
 
225
 *  \param map Beginning of the sequence of output indices.
 
226
 *  \param stencil Beginning of the sequence of predicate values.
 
227
 *  \param output Beginning of the destination range.
 
228
 *
 
229
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
 
230
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
 
231
 *  \tparam InputIterator3 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator3's \c value_type must be convertible to \c bool.
 
232
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
233
 *
 
234
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
235
 *
 
236
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
237
 *
 
238
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
239
 *
 
240
 *  \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `*(stencil + i) != false`.
101
241
 *
102
242
 *  \code
103
243
 *  #include <thrust/scatter.h>
123
263
                  InputIterator2 map,
124
264
                  InputIterator3 stencil,
125
265
                  RandomAccessIterator output);
 
266
 
 
267
 
 
268
/*! \p scatter_if conditionally copies elements from a source range into an 
 
269
 *  output array according to a map. For each iterator \c i in the 
 
270
 *  range <tt>[first, last)</tt> such that <tt>pred(*(stencil + (i - first)))</tt> is
 
271
 *  \c true, the value \c *i is assigned to <tt>output[*(map + (i - first))]</tt>.
 
272
 *  The output iterator must permit random access. If the same index 
 
273
 *  appears more than once in the range <tt>[map, map + (last - first))</tt>
 
274
 *  the result is undefined.
 
275
 *
 
276
 *  The algorithm's execution is parallelized as determined by \p exec.
 
277
 *
 
278
 *  \param exec The execution policy to use for parallelization.
 
279
 *  \param first Beginning of the sequence of values to scatter.
 
280
 *  \param last End of the sequence of values to scatter.
 
281
 *  \param map Beginning of the sequence of output indices.
 
282
 *  \param stencil Beginning of the sequence of predicate values.
 
283
 *  \param output Beginning of the destination range.
 
284
 *  \param pred Predicate to apply to the stencil values.
 
285
 *
 
286
 *  \tparam DerivedPolicy The name of the derived execution policy.
 
287
 *  \tparam InputIterator1 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type.
 
288
 *  \tparam InputIterator2 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c difference_type.
 
289
 *  \tparam InputIterator3 must be a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a> and \c InputIterator3's \c value_type must be convertible to \c Predicate's \c argument_type.
 
290
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
 
291
 *  \tparam Predicate must be a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
 
292
 *
 
293
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
294
 *
 
295
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
296
 *
 
297
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
298
 *
 
299
 *  \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `pred(*(stencil + i)) != false`.
 
300
 *
 
301
 *  \code
 
302
 *  #include <thrust/scatter.h>
 
303
 *  #include <thrust/execution_policy.h>
 
304
 *
 
305
 *  struct is_even
 
306
 *  {
 
307
 *    __host__ __device__
 
308
 *    bool operator()(int x)
 
309
 *    {
 
310
 *      return (x % 2) == 0;
 
311
 *    }
 
312
 *  };
 
313
 *
 
314
 *  ...
 
315
 *
 
316
 *  int V[8] = {10, 20, 30, 40, 50, 60, 70, 80};
 
317
 *  int M[8] = {0, 5, 1, 6, 2, 7, 3, 4};
 
318
 *  int S[8] = {2, 1, 2, 1, 2, 1, 2, 1};
 
319
 *  int D[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 
320
 * 
 
321
 *  is_even pred;
 
322
 *  thrust::scatter_if(thrust::host, V, V + 8, M, S, D, pred);
 
323
 * 
 
324
 *  // D contains [10, 30, 50, 70, 0, 0, 0, 0];
 
325
 *  \endcode
 
326
 *  
 
327
 *  \note \p scatter_if is the inverse of thrust::gather_if.
 
328
 */
 
329
template<typename DerivedPolicy,
 
330
         typename InputIterator1,
 
331
         typename InputIterator2,
 
332
         typename InputIterator3,
 
333
         typename RandomAccessIterator,
 
334
         typename Predicate>
 
335
  void scatter_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
 
336
                  InputIterator1 first,
 
337
                  InputIterator1 last,
 
338
                  InputIterator2 map,
 
339
                  InputIterator3 stencil,
 
340
                  RandomAccessIterator output,
 
341
                  Predicate pred);
126
342
                  
127
343
 
128
344
/*! \p scatter_if conditionally copies elements from a source range into an 
146
362
 *  \tparam RandomAccessIterator must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access iterator</a>.
147
363
 *  \tparam Predicate must be a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
148
364
 *
 
365
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`.
 
366
 *
 
367
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
368
 *
 
369
 *  \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`.
 
370
 *
 
371
 *  \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for which the following condition holds: `pred(*(stencil + i)) != false`.
 
372
 *
149
373
 *  \code
150
374
 *  #include <thrust/scatter.h>
151
375
 *
185
409
                  RandomAccessIterator output,
186
410
                  Predicate pred);
187
411
 
 
412
 
188
413
/*! \} // end scattering
189
414
 */
190
415
 
 
416
 
191
417
} // end namespace thrust
192
418
 
193
419
#include <thrust/detail/scatter.inl>