OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / transform.h
1 /*
2  *  Copyright 2008-2013 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17
18 /*! \file transform.h
19  *  \brief Transforms input ranges using a function object
20  */
21
22 #pragma once
23
24 #include <thrust/detail/config.h>
25 #include <thrust/detail/execution_policy.h>
26
27 namespace thrust
28 {
29
30
31 /*! \addtogroup algorithms
32  */
33
34 /*! \addtogroup transformations
35  *  \ingroup algorithms
36  *  \{
37  */
38
39
40 /*! This version of \p transform applies a unary function to each element
41  *  of an input sequence and stores the result in the corresponding 
42  *  position in an output sequence.  Specifically, for each iterator 
43  *  <tt>i</tt> in the range [\p first, \p last) the operation 
44  *  <tt>op(*i)</tt> is performed and the result is assigned to <tt>*o</tt>,
45  *  where <tt>o</tt> is the corresponding output iterator in the range
46  *  [\p result, \p result + (\p last - \p first) ).  The input and
47  *  output sequences may coincide, resulting in an in-place transformation.
48  *
49  *  The algorithm's execution is parallelized as determined by \p exec.
50  *    
51  *  \param exec The execution policy to use for parallelization.
52  *  \param first The beginning of the input sequence.
53  *  \param last The end of the input sequence.
54  *  \param result The beginning of the output sequence.
55  *  \param op The tranformation operation.
56  *  \return The end of the output sequence.
57  *
58  *  \tparam DerivedPolicy The name of the derived execution policy.
59  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
60  *                        and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type.
61  *  \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
62  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
63  *                              and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
64  *
65  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
66  *
67  *  The following code snippet demonstrates how to use \p transform to negate a range in-place
68  *  using the \p thrust::host execution policy for parallelization:
69  *
70  *  \code
71  *  #include <thrust/transform.h>
72  *  #include <thrust/functional.h>
73  *  #include <thrust/execution_policy.h>
74  *  ...
75  *  
76  *  int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
77  * 
78  *  thrust::negate<int> op;
79  *
80  *  thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation
81  *
82  *  // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
83  *  \endcode
84  *
85  *  \see http://www.sgi.com/tech/stl/transform.html
86  */
87 template<typename DerivedPolicy,
88          typename InputIterator,
89          typename OutputIterator,
90          typename UnaryFunction>
91   OutputIterator transform(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
92                            InputIterator first, InputIterator last,
93                            OutputIterator result,
94                            UnaryFunction op);
95
96         
97 /*! This version of \p transform applies a unary function to each element
98  *  of an input sequence and stores the result in the corresponding 
99  *  position in an output sequence.  Specifically, for each iterator 
100  *  <tt>i</tt> in the range [\p first, \p last) the operation 
101  *  <tt>op(*i)</tt> is performed and the result is assigned to <tt>*o</tt>,
102  *  where <tt>o</tt> is the corresponding output iterator in the range
103  *  [\p result, \p result + (\p last - \p first) ).  The input and
104  *  output sequences may coincide, resulting in an in-place transformation.
105  *    
106  *  \param first The beginning of the input sequence.
107  *  \param last The end of the input sequence.
108  *  \param result The beginning of the output sequence.
109  *  \param op The tranformation operation.
110  *  \return The end of the output sequence.
111  *
112  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
113  *                        and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type.
114  *  \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
115  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
116  *                              and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
117  *
118  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
119  *
120  *  The following code snippet demonstrates how to use \p transform
121  *
122  *  \code
123  *  #include <thrust/transform.h>
124  *  #include <thrust/functional.h>
125  *  
126  *  int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
127  * 
128  *  thrust::negate<int> op;
129  *
130  *  thrust::transform(data, data + 10, data, op); // in-place transformation
131  *
132  *  // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
133  *  \endcode
134  *
135  *  \see http://www.sgi.com/tech/stl/transform.html
136  */
137 template<typename InputIterator,
138          typename OutputIterator,
139          typename UnaryFunction>
140   OutputIterator transform(InputIterator first, InputIterator last,
141                            OutputIterator result,
142                            UnaryFunction op);
143
144
145 /*! This version of \p transform applies a binary function to each pair
146  *  of elements from two input sequences and stores the result in the
147  *  corresponding position in an output sequence.  Specifically, for
148  *  each iterator <tt>i</tt> in the range [\p first1, \p last1) and 
149  *  <tt>j = first + (i - first1)</tt> in the range [\p first2, \p last2)
150  *  the operation <tt>op(*i,*j)</tt> is performed and the result is 
151  *  assigned to <tt>*o</tt>,  where <tt>o</tt> is the corresponding
152  *  output iterator in the range [\p result, \p result + (\p last - \p first) ).
153  *  The input and output sequences may coincide, resulting in an 
154  *  in-place transformation.
155  *
156  *  The algorithm's execution is parallelized as determined by \p exec.
157  *    
158  *  \param exec The execution policy to use for parallelization.
159  *  \param first1 The beginning of the first input sequence.
160  *  \param last1 The end of the first input sequence.
161  *  \param first2 The beginning of the second input sequence.
162  *  \param result The beginning of the output sequence.
163  *  \param op The tranformation operation.
164  *  \return The end of the output sequence.
165  *
166  *  \tparam DerivedPolicy The name of the derived execution policy.
167  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
168  *                        and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type.
169  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
170  *                        and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type.
171  *  \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
172  *  \tparam BinaryFunction is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
173  *                              and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
174  *
175  *  \pre \p first1 may equal \p result, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
176  *  \pre \p first2 may equal \p result, but the range <tt>[first2, first2 + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
177  *
178  *  The following code snippet demonstrates how to use \p transform to compute the sum of two
179  *  ranges using the \p thrust::host execution policy for parallelization:
180  *
181  *  \code
182  *  #include <thrust/transform.h>
183  *  #include <thrust/functional.h>
184  *  #include <thrust/execution_policy.h>
185  *  ...
186  *  
187  *  int input1[6] = {-5,  0,  2,  3,  2,  4};
188  *  int input2[6] = { 3,  6, -2,  1,  2,  3};
189  *  int output[6];
190  * 
191  *  thrust::plus<int> op;
192  *
193  *  thrust::transform(thrust::host, input1, input1 + 6, input2, output, op);
194  *
195  *  // output is now {-2,  6,  0,  4,  4,  7};
196  *  \endcode
197  *
198  *  \see http://www.sgi.com/tech/stl/transform.html
199  */
200 template<typename DerivedPolicy,
201          typename InputIterator1,
202          typename InputIterator2,
203          typename OutputIterator,
204          typename BinaryFunction>
205   OutputIterator transform(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
206                            InputIterator1 first1, InputIterator1 last1,
207                            InputIterator2 first2,
208                            OutputIterator result,
209                            BinaryFunction op);
210
211
212 /*! This version of \p transform applies a binary function to each pair
213  *  of elements from two input sequences and stores the result in the
214  *  corresponding position in an output sequence.  Specifically, for
215  *  each iterator <tt>i</tt> in the range [\p first1, \p last1) and 
216  *  <tt>j = first + (i - first1)</tt> in the range [\p first2, \p last2)
217  *  the operation <tt>op(*i,*j)</tt> is performed and the result is 
218  *  assigned to <tt>*o</tt>,  where <tt>o</tt> is the corresponding
219  *  output iterator in the range [\p result, \p result + (\p last - \p first) ).
220  *  The input and output sequences may coincide, resulting in an 
221  *  in-place transformation.
222  *    
223  *  \param first1 The beginning of the first input sequence.
224  *  \param last1 The end of the first input sequence.
225  *  \param first2 The beginning of the second input sequence.
226  *  \param result The beginning of the output sequence.
227  *  \param op The tranformation operation.
228  *  \return The end of the output sequence.
229  *
230  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
231  *                        and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type.
232  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
233  *                        and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type.
234  *  \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
235  *  \tparam BinaryFunction is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
236  *                              and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
237  *
238  *  \pre \p first1 may equal \p result, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
239  *  \pre \p first2 may equal \p result, but the range <tt>[first2, first2 + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
240  *
241  *  The following code snippet demonstrates how to use \p transform
242  *
243  *  \code
244  *  #include <thrust/transform.h>
245  *  #include <thrust/functional.h>
246  *  
247  *  int input1[6] = {-5,  0,  2,  3,  2,  4};
248  *  int input2[6] = { 3,  6, -2,  1,  2,  3};
249  *  int output[6];
250  * 
251  *  thrust::plus<int> op;
252  *
253  *  thrust::transform(input1, input1 + 6, input2, output, op);
254  *
255  *  // output is now {-2,  6,  0,  4,  4,  7};
256  *  \endcode
257  *
258  *  \see http://www.sgi.com/tech/stl/transform.html
259  */
260 template<typename InputIterator1,
261          typename InputIterator2,
262          typename OutputIterator,
263          typename BinaryFunction>
264   OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
265                            InputIterator2 first2,
266                            OutputIterator result,
267                            BinaryFunction op);
268
269
270 /*! This version of \p transform_if conditionally applies a unary function
271  *  to each element of an input sequence and stores the result in the corresponding 
272  *  position in an output sequence if the corresponding position in the input sequence
273  *  satifies a predicate. Otherwise, the corresponding position in the
274  *  output sequence is not modified.
275  *
276  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first, last)</tt> the
277  *  predicate <tt>pred(*i)</tt> is evaluated. If this predicate
278  *  evaluates to \c true, the result of <tt>op(*i)</tt> is assigned to <tt>*o</tt>,
279  *  where <tt>o</tt> is the corresponding output iterator in the range
280  *  <tt>[result, result + (last - first) )</tt>. Otherwise, <tt>op(*i)</tt> is
281  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
282  *  resulting in an in-place transformation.
283  *
284  *  The algorithm's execution is parallelized as determined by \p exec.
285  *    
286  *  \param exec The execution policy to use for parallelization.
287  *  \param first The beginning of the input sequence.
288  *  \param last The end of the input sequence.
289  *  \param result The beginning of the output sequence.
290  *  \param op The tranformation operation.
291  *  \param pred The predicate operation.
292  *  \return The end of the output sequence.
293  *
294  *  \tparam DerivedPolicy The name of the derived execution policy.
295  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
296  *                        and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type,
297  *                        and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type.
298  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
299  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
300  *                        and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
301  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
302  *
303  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
304  *
305  *  The following code snippet demonstrates how to use \p transform_if to negate the odd-valued
306  *  elements of a range using the \p thrust::host execution policy for parallelization:
307  *
308  *  \code
309  *  #include <thrust/transform.h>
310  *  #include <thrust/functional.h>
311  *  #include <thrust/execution_policy.h>
312  *  ...
313  *  
314  *  int data[10]    = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
315  *
316  *  struct is_odd
317  *  {
318  *    __host__ __device__
319  *    bool operator()(int x)
320  *    {
321  *      return x % 2;
322  *    }
323  *  };
324  * 
325  *  thrust::negate<int> op;
326  *  thrust::identity<int> identity;
327  *
328  *  // negate odd elements
329  *  thrust::transform_if(thrust::host, data, data + 10, data, op, is_odd()); // in-place transformation
330  *
331  *  // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8};
332  *  \endcode
333  *
334  *  \see thrust::transform
335  */
336 template<typename DerivedPolicy,
337          typename InputIterator,
338          typename ForwardIterator,
339          typename UnaryFunction,
340          typename Predicate>
341   ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
342                                InputIterator first, InputIterator last,
343                                ForwardIterator result,
344                                UnaryFunction op,
345                                Predicate pred);
346
347
348 /*! This version of \p transform_if conditionally applies a unary function
349  *  to each element of an input sequence and stores the result in the corresponding 
350  *  position in an output sequence if the corresponding position in the input sequence
351  *  satifies a predicate. Otherwise, the corresponding position in the
352  *  output sequence is not modified.
353  *
354  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first, last)</tt> the
355  *  predicate <tt>pred(*i)</tt> is evaluated. If this predicate
356  *  evaluates to \c true, the result of <tt>op(*i)</tt> is assigned to <tt>*o</tt>,
357  *  where <tt>o</tt> is the corresponding output iterator in the range
358  *  <tt>[result, result + (last - first) )</tt>. Otherwise, <tt>op(*i)</tt> is
359  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
360  *  resulting in an in-place transformation.
361  *    
362  *  \param first The beginning of the input sequence.
363  *  \param last The end of the input sequence.
364  *  \param result The beginning of the output sequence.
365  *  \param op The tranformation operation.
366  *  \param pred The predicate operation.
367  *  \return The end of the output sequence.
368  *
369  *  \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>,
370  *                        and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type,
371  *                        and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type.
372  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
373  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
374  *                        and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
375  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
376  *
377  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
378  *
379  *  The following code snippet demonstrates how to use \p transform_if:
380  *
381  *  \code
382  *  #include <thrust/transform.h>
383  *  #include <thrust/functional.h>
384  *  
385  *  int data[10]    = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
386  *
387  *  struct is_odd
388  *  {
389  *    __host__ __device__
390  *    bool operator()(int x)
391  *    {
392  *      return x % 2;
393  *    }
394  *  };
395  * 
396  *  thrust::negate<int> op;
397  *  thrust::identity<int> identity;
398  *
399  *  // negate odd elements
400  *  thrust::transform_if(data, data + 10, data, op, is_odd()); // in-place transformation
401  *
402  *  // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8};
403  *  \endcode
404  *
405  *  \see thrust::transform
406  */
407 template<typename InputIterator,
408          typename ForwardIterator,
409          typename UnaryFunction,
410          typename Predicate>
411   ForwardIterator transform_if(InputIterator first, InputIterator last,
412                                ForwardIterator result,
413                                UnaryFunction op,
414                                Predicate pred);
415
416
417 /*! This version of \p transform_if conditionally applies a unary function
418  *  to each element of an input sequence and stores the result in the corresponding 
419  *  position in an output sequence if the corresponding position in a stencil sequence
420  *  satisfies a predicate. Otherwise, the corresponding position in the
421  *  output sequence is not modified.
422  *
423  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first, last)</tt> the
424  *  predicate <tt>pred(*s)</tt> is evaluated, where <tt>s</tt> is the corresponding input
425  *  iterator in the range <tt>[stencil, stencil + (last - first) )</tt>. If this predicate
426  *  evaluates to \c true, the result of <tt>op(*i)</tt> is assigned to <tt>*o</tt>,
427  *  where <tt>o</tt> is the corresponding output iterator in the range
428  *  <tt>[result, result + (last - first) )</tt>. Otherwise, <tt>op(*i)</tt> is
429  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
430  *  resulting in an in-place transformation.
431  *
432  *  The algorithm's execution is parallelized as determined by \p exec.
433  *    
434  *  \param exec The execution policy to use for parallelization.
435  *  \param first The beginning of the input sequence.
436  *  \param last The end of the input sequence.
437  *  \param stencil The beginning of the stencil sequence.
438  *  \param result The beginning of the output sequence.
439  *  \param op The tranformation operation.
440  *  \param pred The predicate operation.
441  *  \return The end of the output sequence.
442  *
443  *  \tparam DerivedPolicy The name of the derived execution policy.
444  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
445  *                         and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type.
446  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
447  *                         and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type.
448  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
449  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
450  *                        and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
451  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
452  *
453  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
454  *  \pre \p stencil may equal \p result, but the range <tt>[stencil, stencil + (last - first))</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
455  *
456  *  The following code snippet demonstrates how to use \p transform_if using the \p thrust::host
457  *  execution policy for parallelization:
458  *
459  *  \code
460  *  #include <thrust/transform.h>
461  *  #include <thrust/functional.h>
462  *  #include <thrust/execution_policy.h>
463  *  ...
464  *  
465  *  int data[10]    = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
466  *  int stencil[10] = { 1, 0, 1,  0, 1, 0, 1,  0, 1, 0};
467  * 
468  *  thrust::negate<int> op;
469  *  thrust::identity<int> identity;
470  *
471  *  thrust::transform_if(thrust::host, data, data + 10, stencil, data, op, identity); // in-place transformation
472  *
473  *  // data is now {5, 0, -2, -3, -2,  4, 0, -1, -2,  8};
474  *  \endcode
475  *
476  *  \see thrust::transform
477  */
478 template<typename DerivedPolicy,
479          typename InputIterator1,
480          typename InputIterator2,
481          typename ForwardIterator,
482          typename UnaryFunction,
483          typename Predicate>
484   ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
485                                InputIterator1 first, InputIterator1 last,
486                                InputIterator2 stencil,
487                                ForwardIterator result,
488                                UnaryFunction op,
489                                Predicate pred);
490
491
492 /*! This version of \p transform_if conditionally applies a unary function
493  *  to each element of an input sequence and stores the result in the corresponding 
494  *  position in an output sequence if the corresponding position in a stencil sequence
495  *  satisfies a predicate. Otherwise, the corresponding position in the
496  *  output sequence is not modified.
497  *
498  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first, last)</tt> the
499  *  predicate <tt>pred(*s)</tt> is evaluated, where <tt>s</tt> is the corresponding input
500  *  iterator in the range <tt>[stencil, stencil + (last - first) )</tt>. If this predicate
501  *  evaluates to \c true, the result of <tt>op(*i)</tt> is assigned to <tt>*o</tt>,
502  *  where <tt>o</tt> is the corresponding output iterator in the range
503  *  <tt>[result, result + (last - first) )</tt>. Otherwise, <tt>op(*i)</tt> is
504  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
505  *  resulting in an in-place transformation.
506  *    
507  *  \param first The beginning of the input sequence.
508  *  \param last The end of the input sequence.
509  *  \param stencil The beginning of the stencil sequence.
510  *  \param result The beginning of the output sequence.
511  *  \param op The tranformation operation.
512  *  \param pred The predicate operation.
513  *  \return The end of the output sequence.
514  *
515  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
516  *                         and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type.
517  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
518  *                         and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type.
519  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
520  *  \tparam UnaryFunction is a model of <a href="http://www.sgi.com/tech/stl/UnaryFunction.html">Unary Function</a>
521  *                        and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
522  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
523  *
524  *  \pre \p first may equal \p result, but the range <tt>[first, last)</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
525  *  \pre \p stencil may equal \p result, but the range <tt>[stencil, stencil + (last - first))</tt> shall not overlap the range <tt>[result, result + (last - first))</tt> otherwise.
526  *
527  *  The following code snippet demonstrates how to use \p transform_if:
528  *
529  *  \code
530  *  #include <thrust/transform.h>
531  *  #include <thrust/functional.h>
532  *  
533  *  int data[10]    = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8};
534  *  int stencil[10] = { 1, 0, 1,  0, 1, 0, 1,  0, 1, 0};
535  * 
536  *  thrust::negate<int> op;
537  *  thrust::identity<int> identity;
538  *
539  *  thrust::transform_if(data, data + 10, stencil, data, op, identity); // in-place transformation
540  *
541  *  // data is now {5, 0, -2, -3, -2,  4, 0, -1, -2,  8};
542  *  \endcode
543  *
544  *  \see thrust::transform
545  */
546 template<typename InputIterator1,
547          typename InputIterator2,
548          typename ForwardIterator,
549          typename UnaryFunction,
550          typename Predicate>
551   ForwardIterator transform_if(InputIterator1 first, InputIterator1 last,
552                                InputIterator2 stencil,
553                                ForwardIterator result,
554                                UnaryFunction op,
555                                Predicate pred);
556
557
558 /*! This version of \p transform_if conditionally applies a binary function
559  *  to each pair of elements from two input sequences and stores the result in the corresponding 
560  *  position in an output sequence if the corresponding position in a stencil sequence
561  *  satifies a predicate. Otherwise, the corresponding position in the
562  *  output sequence is not modified.
563  *
564  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first1, last1)</tt> and 
565  *  <tt>j = first2 + (i - first1)</tt> in the range <tt>[first2, first2 + (last1 - first1) )</tt>,
566  *  the predicate <tt>pred(*s)</tt> is evaluated, where <tt>s</tt> is the corresponding input
567  *  iterator in the range <tt>[stencil, stencil + (last1 - first1) )</tt>. If this predicate
568  *  evaluates to \c true, the result of <tt>binary_op(*i,*j)</tt> is assigned to <tt>*o</tt>,
569  *  where <tt>o</tt> is the corresponding output iterator in the range
570  *  <tt>[result, result + (last1 - first1) )</tt>. Otherwise, <tt>binary_op(*i,*j)</tt> is
571  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
572  *  resulting in an in-place transformation.
573  *
574  *  The algorithm's execution is parallelized as determined by \p exec.
575  *    
576  *  \param exec The execution policy to use for parallelization.
577  *  \param first1 The beginning of the first input sequence.
578  *  \param last1 The end of the first input sequence.
579  *  \param first2 The beginning of the second input sequence.
580  *  \param stencil The beginning of the stencil sequence.
581  *  \param result The beginning of the output sequence.
582  *  \param binary_op The transformation operation.
583  *  \param pred The predicate operation.
584  *  \return The end of the output sequence.
585  *
586  *  \tparam DerivedPolicy The name of the derived execution policy.
587  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
588  *                         and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type.
589  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
590  *                         and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type.
591  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
592  *  \tparam BinaryFunction is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
593  *                         and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
594  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
595  *
596  *  \pre \p first1 may equal \p result, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
597  *  \pre \p first2 may equal \p result, but the range <tt>[first2, first2 + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
598  *  \pre \p stencil may equal \p result, but the range <tt>[stencil, stencil + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
599  *
600  *  The following code snippet demonstrates how to use \p transform_if using the \p thrust::host
601  *  execution policy for parallelization:
602  *
603  *  \code
604  *  #include <thrust/transform.h>
605  *  #include <thrust/functional.h>
606  *  #include <thrust/execution_policy.h>
607  *  ...
608  *  
609  *  int input1[6]  = {-5,  0,  2,  3,  2,  4};
610  *  int input2[6]  = { 3,  6, -2,  1,  2,  3};
611  *  int stencil[8] = { 1,  0,  1,  0,  1,  0};
612  *  int output[6];
613  * 
614  *  thrust::plus<int> op;
615  *  thrust::identity<int> identity;
616  *
617  *  thrust::transform_if(thrust::host, input1, input1 + 6, input2, stencil, output, op, identity);
618  *
619  *  // output is now {-2,  0,  0,  3,  4,  4};
620  *  \endcode
621  *
622  *  \see thrust::transform
623  */
624 template<typename DerivedPolicy,
625          typename InputIterator1,
626          typename InputIterator2,
627          typename InputIterator3,
628          typename ForwardIterator,
629          typename BinaryFunction,
630          typename Predicate>
631   ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
632                                InputIterator1 first1, InputIterator1 last1,
633                                InputIterator2 first2,
634                                InputIterator3 stencil,
635                                ForwardIterator result,
636                                BinaryFunction binary_op,
637                                Predicate pred);
638
639
640 /*! This version of \p transform_if conditionally applies a binary function
641  *  to each pair of elements from two input sequences and stores the result in the corresponding 
642  *  position in an output sequence if the corresponding position in a stencil sequence
643  *  satifies a predicate. Otherwise, the corresponding position in the
644  *  output sequence is not modified.
645  *
646  *  Specifically, for each iterator <tt>i</tt> in the range <tt>[first1, last1)</tt> and 
647  *  <tt>j = first2 + (i - first1)</tt> in the range <tt>[first2, first2 + (last1 - first1) )</tt>,
648  *  the predicate <tt>pred(*s)</tt> is evaluated, where <tt>s</tt> is the corresponding input
649  *  iterator in the range <tt>[stencil, stencil + (last1 - first1) )</tt>. If this predicate
650  *  evaluates to \c true, the result of <tt>binary_op(*i,*j)</tt> is assigned to <tt>*o</tt>,
651  *  where <tt>o</tt> is the corresponding output iterator in the range
652  *  <tt>[result, result + (last1 - first1) )</tt>. Otherwise, <tt>binary_op(*i,*j)</tt> is
653  *  not evaluated and no assignment occurs. The input and output sequences may coincide,
654  *  resulting in an in-place transformation.
655  *    
656  *  \param first1 The beginning of the first input sequence.
657  *  \param last1 The end of the first input sequence.
658  *  \param first2 The beginning of the second input sequence.
659  *  \param stencil The beginning of the stencil sequence.
660  *  \param result The beginning of the output sequence.
661  *  \param binary_op The transformation operation.
662  *  \param pred The predicate operation.
663  *  \return The end of the output sequence.
664  *
665  *  \tparam InputIterator1 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
666  *                         and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type.
667  *  \tparam InputIterator2 is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
668  *                         and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type.
669  *  \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>.
670  *  \tparam BinaryFunction is a model of <a href="http://www.sgi.com/tech/stl/BinaryFunction.html">Binary Function</a>
671  *                         and \c BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type.
672  *  \tparam Predicate is a model of <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>.
673  *
674  *  \pre \p first1 may equal \p result, but the range <tt>[first1, last1)</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
675  *  \pre \p first2 may equal \p result, but the range <tt>[first2, first2 + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
676  *  \pre \p stencil may equal \p result, but the range <tt>[stencil, stencil + (last1 - first1))</tt> shall not overlap the range <tt>[result, result + (last1 - first1))</tt> otherwise.
677  *
678  *  The following code snippet demonstrates how to use \p transform_if:
679  *
680  *  \code
681  *  #include <thrust/transform.h>
682  *  #include <thrust/functional.h>
683  *  
684  *  int input1[6]  = {-5,  0,  2,  3,  2,  4};
685  *  int input2[6]  = { 3,  6, -2,  1,  2,  3};
686  *  int stencil[8] = { 1,  0,  1,  0,  1,  0};
687  *  int output[6];
688  * 
689  *  thrust::plus<int> op;
690  *  thrust::identity<int> identity;
691  *
692  *  thrust::transform_if(input1, input1 + 6, input2, stencil, output, op, identity);
693  *
694  *  // output is now {-2,  0,  0,  3,  4,  4};
695  *  \endcode
696  *
697  *  \see thrust::transform
698  */
699 template<typename InputIterator1,
700          typename InputIterator2,
701          typename InputIterator3,
702          typename ForwardIterator,
703          typename BinaryFunction,
704          typename Predicate>
705   ForwardIterator transform_if(InputIterator1 first1, InputIterator1 last1,
706                                InputIterator2 first2,
707                                InputIterator3 stencil,
708                                ForwardIterator result,
709                                BinaryFunction binary_op,
710                                Predicate pred);
711
712
713 /*! \} // end transformations
714  */
715
716
717 } // end namespace thrust
718
719 #include <thrust/detail/transform.inl>
720