2 * Copyright 2008-2013 NVIDIA Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <thrust/detail/config.h>
18 #include <thrust/system/detail/generic/tabulate.h>
19 #include <thrust/iterator/iterator_traits.h>
20 #include <thrust/transform.h>
21 #include <thrust/distance.h>
22 #include <thrust/iterator/counting_iterator.h>
34 template<typename DerivedPolicy,
35 typename ForwardIterator,
36 typename UnaryOperation>
37 void tabulate(thrust::execution_policy<DerivedPolicy> &exec,
38 ForwardIterator first,
40 UnaryOperation unary_op)
42 typedef typename iterator_difference<ForwardIterator>::type difference_type;
44 // by default, counting_iterator uses a 64b difference_type on 32b platforms to avoid overflowing its counter.
45 // this causes problems when a zip_iterator is created in transform's implementation -- ForwardIterator is
46 // incremented by a 64b difference_type and some compilers warn
47 // to avoid this, specify the counting_iterator's difference_type to be the same as ForwardIterator's.
48 thrust::counting_iterator<difference_type, thrust::use_default, thrust::use_default, difference_type> iter(0);
50 thrust::transform(exec, iter, iter + thrust::distance(first, last), first, unary_op);
54 } // end namespace generic
55 } // end namespace detail
56 } // end namespace system
57 } // end namespace thrust