38 #ifndef _GLIBCXX_PARALLEL_NUMERIC_H
39 #define _GLIBCXX_PARALLEL_NUMERIC_H 1
54 template<
typename InputIterator,
typename T>
56 accumulate(InputIterator begin, InputIterator end, T init,
58 {
return _GLIBCXX_STD_P::accumulate(begin, end, init); }
60 template<
typename InputIterator,
typename T,
typename BinaryOperation>
62 accumulate(InputIterator begin, InputIterator end, T init,
64 {
return _GLIBCXX_STD_P::accumulate(begin, end, init, binary_op); }
67 template<
typename InputIterator,
typename T,
typename IteratorTag>
69 accumulate_switch(InputIterator begin, InputIterator end,
73 template<
typename InputIterator,
typename T,
typename BinaryOperation,
76 accumulate_switch(InputIterator begin, InputIterator end, T init,
77 BinaryOperation binary_op, IteratorTag)
78 {
return accumulate(begin, end, init, binary_op,
82 template<
typename _RandomAccessIterator,
typename T,
83 typename BinaryOperation>
85 accumulate_switch(_RandomAccessIterator begin, _RandomAccessIterator end,
86 T init, BinaryOperation binary_op,
92 static_cast<__gnu_parallel::sequence_index_t>(end - begin)
94 && __gnu_parallel::is_parallel(parallelism_tag)))
104 accumulate_binop_reduct
105 <BinaryOperation>(binary_op),
110 return accumulate(begin, end, init, binary_op,
115 template<
typename InputIterator,
typename T>
117 accumulate(InputIterator begin, InputIterator end, T init,
121 typedef typename iterator_traits::value_type value_type;
122 typedef typename iterator_traits::iterator_category iterator_category;
124 return accumulate_switch(begin, end, init,
126 iterator_category(), parallelism_tag);
129 template<
typename InputIterator,
typename T>
131 accumulate(InputIterator begin, InputIterator end, T init)
134 typedef typename iterator_traits::value_type value_type;
135 typedef typename iterator_traits::iterator_category iterator_category;
137 return accumulate_switch(begin, end, init,
139 iterator_category());
142 template<
typename InputIterator,
typename T,
typename BinaryOperation>
144 accumulate(InputIterator begin, InputIterator end, T init,
145 BinaryOperation binary_op,
149 typedef typename iterator_traits::iterator_category iterator_category;
150 return accumulate_switch(begin, end, init, binary_op,
151 iterator_category(), parallelism_tag);
154 template<
typename InputIterator,
typename T,
typename BinaryOperation>
156 accumulate(InputIterator begin, InputIterator end, T init,
157 BinaryOperation binary_op)
160 typedef typename iterator_traits::iterator_category iterator_category;
161 return accumulate_switch(begin, end, init, binary_op,
162 iterator_category());
167 template<
typename InputIterator1,
typename InputIterator2,
typename T>
169 inner_product(InputIterator1 first1, InputIterator1 last1,
170 InputIterator2 first2, T init,
172 {
return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init); }
174 template<
typename InputIterator1,
typename InputIterator2,
typename T,
175 typename BinaryFunction1,
typename BinaryFunction2>
177 inner_product(InputIterator1 first1, InputIterator1 last1,
178 InputIterator2 first2, T init, BinaryFunction1 binary_op1,
180 {
return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init,
181 binary_op1, binary_op2); }
184 template<
typename RandomAccessIterator1,
typename RandomAccessIterator2,
185 typename T,
typename BinaryFunction1,
typename BinaryFunction2>
187 inner_product_switch(RandomAccessIterator1 first1,
188 RandomAccessIterator1 last1,
189 RandomAccessIterator2 first2, T init,
190 BinaryFunction1 binary_op1,
191 BinaryFunction2 binary_op2,
201 is_parallel(parallelism_tag)))
206 RandomAccessIterator2, T> my_selector(first1, first2);
209 my_selector, binary_op1,
214 return inner_product(first1, last1, first2, init,
219 template<
typename InputIterator1,
typename InputIterator2,
typename T,
220 typename BinaryFunction1,
typename BinaryFunction2,
221 typename IteratorTag1,
typename IteratorTag2>
223 inner_product_switch(InputIterator1 first1, InputIterator1 last1,
224 InputIterator2 first2, T init,
225 BinaryFunction1 binary_op1,
226 BinaryFunction2 binary_op2,
227 IteratorTag1, IteratorTag2)
228 {
return inner_product(first1, last1, first2, init,
229 binary_op1, binary_op2,
232 template<
typename InputIterator1,
typename InputIterator2,
typename T,
233 typename BinaryFunction1,
typename BinaryFunction2>
235 inner_product(InputIterator1 first1, InputIterator1 last1,
236 InputIterator2 first2, T init, BinaryFunction1 binary_op1,
237 BinaryFunction2 binary_op2,
241 typedef typename traits1_type::iterator_category iterator1_category;
244 typedef typename traits2_type::iterator_category iterator2_category;
246 return inner_product_switch(first1, last1, first2, init, binary_op1,
247 binary_op2, iterator1_category(),
248 iterator2_category(), parallelism_tag);
251 template<
typename InputIterator1,
typename InputIterator2,
typename T,
252 typename BinaryFunction1,
typename BinaryFunction2>
254 inner_product(InputIterator1 first1, InputIterator1 last1,
255 InputIterator2 first2, T init, BinaryFunction1 binary_op1,
256 BinaryFunction2 binary_op2)
259 typedef typename traits1_type::iterator_category iterator1_category;
262 typedef typename traits2_type::iterator_category iterator2_category;
264 return inner_product_switch(first1, last1, first2, init, binary_op1,
265 binary_op2, iterator1_category(),
266 iterator2_category());
269 template<
typename InputIterator1,
typename InputIterator2,
typename T>
271 inner_product(InputIterator1 first1, InputIterator1 last1,
272 InputIterator2 first2, T init,
276 typedef typename traits_type1::value_type value_type1;
278 typedef typename traits_type2::value_type value_type2;
282 multiplies_result_type;
283 return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init,
290 template<
typename InputIterator1,
typename InputIterator2,
typename T>
292 inner_product(InputIterator1 first1, InputIterator1 last1,
293 InputIterator2 first2, T init)
296 typedef typename traits_type1::value_type value_type1;
298 typedef typename traits_type2::value_type value_type2;
302 multiplies_result_type;
303 return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init,
310 template<
typename InputIterator,
typename OutputIterator>
311 inline OutputIterator
312 partial_sum(InputIterator begin, InputIterator end, OutputIterator result,
314 {
return _GLIBCXX_STD_P::partial_sum(begin, end, result); }
317 template<
typename InputIterator,
typename OutputIterator,
318 typename BinaryOperation>
319 inline OutputIterator
320 partial_sum(InputIterator begin, InputIterator end, OutputIterator result,
322 {
return _GLIBCXX_STD_P::partial_sum(begin, end, result, bin_op); }
325 template<
typename InputIterator,
typename OutputIterator,
326 typename BinaryOperation,
typename IteratorTag1,
327 typename IteratorTag2>
328 inline OutputIterator
329 partial_sum_switch(InputIterator begin, InputIterator end,
330 OutputIterator result, BinaryOperation bin_op,
331 IteratorTag1, IteratorTag2)
332 {
return _GLIBCXX_STD_P::partial_sum(begin, end, result, bin_op); }
335 template<
typename InputIterator,
typename OutputIterator,
336 typename BinaryOperation>
338 partial_sum_switch(InputIterator begin, InputIterator end,
339 OutputIterator result, BinaryOperation bin_op,
343 static_cast<__gnu_parallel::sequence_index_t>(end - begin)
348 return partial_sum(begin, end, result, bin_op,
353 template<
typename InputIterator,
typename OutputIterator>
354 inline OutputIterator
355 partial_sum(InputIterator begin, InputIterator end, OutputIterator result)
357 typedef typename iterator_traits<InputIterator>::value_type value_type;
358 return _GLIBCXX_STD_P::partial_sum(begin, end, result,
363 template<
typename InputIterator,
typename OutputIterator,
364 typename BinaryOperation>
365 inline OutputIterator
366 partial_sum(InputIterator begin, InputIterator end, OutputIterator result,
367 BinaryOperation binary_op)
370 typedef typename traitsi_type::iterator_category iteratori_category;
373 typedef typename traitso_type::iterator_category iteratoro_category;
375 return partial_sum_switch(begin, end, result, binary_op,
376 iteratori_category(), iteratoro_category());
380 template<
typename InputIterator,
typename OutputIterator>
381 inline OutputIterator
382 adjacent_difference(InputIterator begin, InputIterator end,
384 {
return _GLIBCXX_STD_P::adjacent_difference(begin, end, result); }
387 template<
typename InputIterator,
typename OutputIterator,
388 typename BinaryOperation>
389 inline OutputIterator
390 adjacent_difference(InputIterator begin, InputIterator end,
391 OutputIterator result, BinaryOperation bin_op,
393 {
return _GLIBCXX_STD_P::adjacent_difference(begin, end, result, bin_op); }
396 template<
typename InputIterator,
typename OutputIterator,
397 typename BinaryOperation,
typename IteratorTag1,
398 typename IteratorTag2>
399 inline OutputIterator
400 adjacent_difference_switch(InputIterator begin, InputIterator end,
401 OutputIterator result, BinaryOperation bin_op,
402 IteratorTag1, IteratorTag2)
403 {
return adjacent_difference(begin, end, result, bin_op,
407 template<
typename InputIterator,
typename OutputIterator,
408 typename BinaryOperation>
410 adjacent_difference_switch(InputIterator begin, InputIterator end,
411 OutputIterator result, BinaryOperation bin_op,
418 static_cast<__gnu_parallel::sequence_index_t>(end - begin)
420 && __gnu_parallel::is_parallel(parallelism_tag)))
426 ip begin_pair(begin + 1, result + 1),
427 end_pair(end, result + (end - begin));
437 return adjacent_difference(begin, end, result, bin_op,
442 template<
typename InputIterator,
typename OutputIterator>
443 inline OutputIterator
444 adjacent_difference(InputIterator begin, InputIterator end,
445 OutputIterator result,
449 typedef typename traits_type::value_type value_type;
454 template<
typename InputIterator,
typename OutputIterator>
455 inline OutputIterator
456 adjacent_difference(InputIterator begin, InputIterator end,
457 OutputIterator result)
460 typedef typename traits_type::value_type value_type;
464 template<
typename InputIterator,
typename OutputIterator,
465 typename BinaryOperation>
466 inline OutputIterator
467 adjacent_difference(InputIterator begin, InputIterator end,
468 OutputIterator result, BinaryOperation binary_op,
472 typedef typename traitsi_type::iterator_category iteratori_category;
475 typedef typename traitso_type::iterator_category iteratoro_category;
477 return adjacent_difference_switch(begin, end, result, binary_op,
478 iteratori_category(),
479 iteratoro_category(), parallelism_tag);
482 template<
typename InputIterator,
typename OutputIterator,
483 typename BinaryOperation>
484 inline OutputIterator
485 adjacent_difference(InputIterator begin, InputIterator end,
486 OutputIterator result, BinaryOperation binary_op)
489 typedef typename traitsi_type::iterator_category iteratori_category;
492 typedef typename traitso_type::iterator_category iteratoro_category;
494 return adjacent_difference_switch(begin, end, result, binary_op,
495 iteratori_category(),
496 iteratoro_category());