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/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>
34 template<typename DerivedPolicy,
35 typename InputIterator1,
36 typename InputIterator2,
37 typename RandomAccessIterator>
38 void scatter(thrust::execution_policy<DerivedPolicy> &exec,
42 RandomAccessIterator output)
44 thrust::transform(exec,
47 thrust::make_permutation_iterator(output, map),
48 thrust::identity<typename thrust::iterator_value<InputIterator1>::type>());
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,
61 InputIterator3 stencil,
62 RandomAccessIterator output)
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>());
70 template<typename DerivedPolicy,
71 typename InputIterator1,
72 typename InputIterator2,
73 typename InputIterator3,
74 typename RandomAccessIterator,
76 void scatter_if(thrust::execution_policy<DerivedPolicy> &exec,
80 InputIterator3 stencil,
81 RandomAccessIterator output,
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);
89 } // end namespace generic
90 } // end namespace detail
91 } // end namespace system
92 } // end namespace thrust