OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / system / detail / generic / tabulate.inl
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 #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>
23
24 namespace thrust
25 {
26 namespace system
27 {
28 namespace detail
29 {
30 namespace generic
31 {
32
33
34 template<typename DerivedPolicy,
35          typename ForwardIterator,
36          typename UnaryOperation>
37   void tabulate(thrust::execution_policy<DerivedPolicy> &exec,
38                 ForwardIterator first,
39                 ForwardIterator last,
40                 UnaryOperation unary_op)
41 {
42   typedef typename iterator_difference<ForwardIterator>::type difference_type;
43
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);
49
50   thrust::transform(exec, iter, iter + thrust::distance(first, last), first, unary_op);
51 } // end tabulate()
52
53
54 } // end namespace generic
55 } // end namespace detail
56 } // end namespace system
57 } // end namespace thrust
58
59