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.inl
19 *  \brief Inline file for transform.h.
20 */
21
22#include <thrust/transform.h>
23#include <thrust/iterator/iterator_traits.h>
24#include <thrust/system/detail/generic/select_system.h>
25#include <thrust/system/detail/generic/transform.h>
26#include <thrust/system/detail/adl/transform.h>
27
28namespace thrust
29{
30
31
32__thrust_exec_check_disable__
33template<typename DerivedPolicy,
34         typename InputIterator,
35         typename OutputIterator,
36         typename UnaryFunction>
37__host__ __device__
38  OutputIterator transform(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
39                           InputIterator first, InputIterator last,
40                           OutputIterator result,
41                           UnaryFunction op)
42{
43  using thrust::system::detail::generic::transform;
44  return transform(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, op);
45} // end transform()
46
47
48__thrust_exec_check_disable__
49template<typename DerivedPolicy,
50         typename InputIterator1,
51         typename InputIterator2,
52         typename OutputIterator,
53         typename BinaryFunction>
54__host__ __device__
55  OutputIterator transform(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
56                           InputIterator1 first1, InputIterator1 last1,
57                           InputIterator2 first2,
58                           OutputIterator result,
59                           BinaryFunction op)
60{
61  using thrust::system::detail::generic::transform;
62  return transform(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, op);
63} // end transform()
64
65
66__thrust_exec_check_disable__
67template<typename DerivedPolicy,
68         typename InputIterator,
69         typename ForwardIterator,
70         typename UnaryFunction,
71         typename Predicate>
72__host__ __device__
73  ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
74                               InputIterator first, InputIterator last,
75                               ForwardIterator result,
76                               UnaryFunction op,
77                               Predicate pred)
78{
79  using thrust::system::detail::generic::transform_if;
80  return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, op, pred);
81} // end transform_if()
82
83
84__thrust_exec_check_disable__
85template<typename DerivedPolicy,
86         typename InputIterator1,
87         typename InputIterator2,
88         typename ForwardIterator,
89         typename UnaryFunction,
90         typename Predicate>
91__host__ __device__
92  ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
93                               InputIterator1 first, InputIterator1 last,
94                               InputIterator2 stencil,
95                               ForwardIterator result,
96                               UnaryFunction op,
97                               Predicate pred)
98{
99  using thrust::system::detail::generic::transform_if;
100  return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, op, pred);
101} // end transform_if()
102
103
104__thrust_exec_check_disable__
105template<typename DerivedPolicy,
106         typename InputIterator1,
107         typename InputIterator2,
108         typename InputIterator3,
109         typename ForwardIterator,
110         typename BinaryFunction,
111         typename Predicate>
112__host__ __device__
113  ForwardIterator transform_if(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
114                               InputIterator1 first1, InputIterator1 last1,
115                               InputIterator2 first2,
116                               InputIterator3 stencil,
117                               ForwardIterator result,
118                               BinaryFunction binary_op,
119                               Predicate pred)
120{
121  using thrust::system::detail::generic::transform_if;
122  return transform_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, stencil, result, binary_op, pred);
123} // end transform_if()
124
125
126template<typename InputIterator,
127         typename OutputIterator,
128         typename UnaryFunction>
129  OutputIterator transform(InputIterator first,
130                           InputIterator last,
131                           OutputIterator result,
132                           UnaryFunction op)
133{
134  using thrust::system::detail::generic::select_system;
135
136  typedef typename thrust::iterator_system<InputIterator>::type  System1;
137  typedef typename thrust::iterator_system<OutputIterator>::type System2;
138
139  System1 system1;
140  System2 system2;
141
142  return thrust::transform(select_system(system1,system2), first, last, result, op);
143} // end transform()
144
145
146template<typename InputIterator1,
147         typename InputIterator2,
148         typename OutputIterator,
149         typename BinaryFunction>
150  OutputIterator transform(InputIterator1 first1,
151                           InputIterator1 last1,
152                           InputIterator2 first2,
153                           OutputIterator result,
154                           BinaryFunction op)
155{
156  using thrust::system::detail::generic::select_system;
157
158  typedef typename thrust::iterator_system<InputIterator1>::type System1;
159  typedef typename thrust::iterator_system<InputIterator2>::type System2;
160  typedef typename thrust::iterator_system<OutputIterator>::type System3;
161
162  System1 system1;
163  System2 system2;
164  System3 system3;
165
166  return thrust::transform(select_system(system1,system2,system3), first1, last1, first2, result, op);
167} // end transform()
168
169
170template<typename InputIterator,
171         typename ForwardIterator,
172         typename UnaryFunction,
173         typename Predicate>
174  ForwardIterator transform_if(InputIterator first,
175                               InputIterator last,
176                               ForwardIterator result,
177                               UnaryFunction unary_op,
178                               Predicate pred)
179{
180  using thrust::system::detail::generic::select_system;
181
182  typedef typename thrust::iterator_system<InputIterator>::type   System1;
183  typedef typename thrust::iterator_system<ForwardIterator>::type System2;
184
185  System1 system1;
186  System2 system2;
187
188  return thrust::transform_if(select_system(system1,system2), first, last, result, unary_op, pred);
189} // end transform_if()
190
191
192template<typename InputIterator1,
193         typename InputIterator2,
194         typename ForwardIterator,
195         typename UnaryFunction,
196         typename Predicate>
197  ForwardIterator transform_if(InputIterator1 first,
198                               InputIterator1 last,
199                               InputIterator2 stencil,
200                               ForwardIterator result,
201                               UnaryFunction unary_op,
202                               Predicate pred)
203{
204  using thrust::system::detail::generic::select_system;
205
206  typedef typename thrust::iterator_system<InputIterator1>::type  System1;
207  typedef typename thrust::iterator_system<InputIterator2>::type  System2;
208  typedef typename thrust::iterator_system<ForwardIterator>::type System3;
209
210  System1 system1;
211  System2 system2;
212  System3 system3;
213
214  return thrust::transform_if(select_system(system1,system2,system3), first, last, stencil, result, unary_op, pred);
215} // end transform_if()
216
217
218template<typename InputIterator1,
219         typename InputIterator2,
220         typename InputIterator3,
221         typename ForwardIterator,
222         typename BinaryFunction,
223         typename Predicate>
224  ForwardIterator transform_if(InputIterator1 first1,
225                               InputIterator1 last1,
226                               InputIterator2 first2,
227                               InputIterator3 stencil,
228                               ForwardIterator result,
229                               BinaryFunction binary_op,
230                               Predicate pred)
231{
232  using thrust::system::detail::generic::select_system;
233
234  typedef typename thrust::iterator_system<InputIterator1>::type  System1;
235  typedef typename thrust::iterator_system<InputIterator2>::type  System2;
236  typedef typename thrust::iterator_system<InputIterator3>::type  System3;
237  typedef typename thrust::iterator_system<ForwardIterator>::type System4;
238
239  System1 system1;
240  System2 system2;
241  System3 system3;
242  System4 system4;
243
244  return thrust::transform_if(select_system(system1,system2,system3,system4), first1, last1, first2, stencil, result, binary_op, pred);
245} // end transform_if()
246
247
248} // end namespace thrust
249
250