OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / system / detail / generic / scatter.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/scatter.h>
19 #include <thrust/iterator/iterator_traits.h>
20 #include <thrust/functional.h>
21 #include <thrust/transform.h>
22 #include <thrust/iterator/permutation_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 InputIterator1,
36          typename InputIterator2,
37          typename RandomAccessIterator>
38   void scatter(thrust::execution_policy<DerivedPolicy> &exec,
39                InputIterator1 first,
40                InputIterator1 last,
41                InputIterator2 map,
42                RandomAccessIterator output)
43 {
44   thrust::transform(exec,
45                     first,
46                     last,
47                     thrust::make_permutation_iterator(output, map),
48                     thrust::identity<typename thrust::iterator_value<InputIterator1>::type>());
49 } // end scatter()
50
51
52 template<typename DerivedPolicy,
53          typename InputIterator1,
54          typename InputIterator2,
55          typename InputIterator3,
56          typename RandomAccessIterator>
57   void scatter_if(thrust::execution_policy<DerivedPolicy> &exec,
58                   InputIterator1 first,
59                   InputIterator1 last,
60                   InputIterator2 map,
61                   InputIterator3 stencil,
62                   RandomAccessIterator output)
63 {
64   // default predicate is identity
65   typedef typename thrust::iterator_value<InputIterator3>::type StencilType;
66   thrust::scatter_if(exec, first, last, map, stencil, output, thrust::identity<StencilType>());
67 } // end scatter_if()
68
69
70 template<typename DerivedPolicy,
71          typename InputIterator1,
72          typename InputIterator2,
73          typename InputIterator3,
74          typename RandomAccessIterator,
75          typename Predicate>
76   void scatter_if(thrust::execution_policy<DerivedPolicy> &exec,
77                   InputIterator1 first,
78                   InputIterator1 last,
79                   InputIterator2 map,
80                   InputIterator3 stencil,
81                   RandomAccessIterator output,
82                   Predicate pred)
83 {
84   typedef typename thrust::iterator_value<InputIterator1>::type InputType;
85   thrust::transform_if(exec, first, last, stencil, thrust::make_permutation_iterator(output, map), thrust::identity<InputType>(), pred);
86 } // end scatter_if()
87
88
89 } // end namespace generic
90 } // end namespace detail
91 } // end namespace system
92 } // end namespace thrust
93