/
usr
/
include
/
boost
/
compute
/
algorithm
/
/usr/include/boost/compute/algorithm
mkdir
upload
Name
Size
Mode
Actions
detail/
-
0755
rm
accumulate.hpp
6375
0644
edit
dl
rm
adjacent_difference.hpp
4416
0644
edit
dl
rm
adjacent_find.hpp
5313
0644
edit
dl
rm
all_of.hpp
1427
0644
edit
dl
rm
any_of.hpp
1544
0644
edit
dl
rm
binary_search.hpp
1480
0644
edit
dl
rm
copy.hpp
31483
0644
edit
dl
rm
copy_if.hpp
2574
0644
edit
dl
rm
copy_n.hpp
1940
0644
edit
dl
rm
count.hpp
2103
0644
edit
dl
rm
count_if.hpp
2388
0644
edit
dl
rm
equal.hpp
2209
0644
edit
dl
rm
equal_range.hpp
1636
0644
edit
dl
rm
exclusive_scan.hpp
4042
0644
edit
dl
rm
fill.hpp
10030
0644
edit
dl
rm
fill_n.hpp
1367
0644
edit
dl
rm
find.hpp
2004
0644
edit
dl
rm
find_end.hpp
4772
0644
edit
dl
rm
find_if.hpp
1504
0644
edit
dl
rm
find_if_not.hpp
1652
0644
edit
dl
rm
for_each.hpp
2131
0644
edit
dl
rm
for_each_n.hpp
1423
0644
edit
dl
rm
gather.hpp
2796
0644
edit
dl
rm
generate.hpp
1903
0644
edit
dl
rm
generate_n.hpp
1277
0644
edit
dl
rm
includes.hpp
5615
0644
edit
dl
rm
inclusive_scan.hpp
3402
0644
edit
dl
rm
inner_product.hpp
3849
0644
edit
dl
rm
inplace_merge.hpp
2047
0644
edit
dl
rm
iota.hpp
1735
0644
edit
dl
rm
is_partitioned.hpp
1785
0644
edit
dl
rm
is_permutation.hpp
2744
0644
edit
dl
rm
is_sorted.hpp
2436
0644
edit
dl
rm
lexicographical_compare.hpp
4950
0644
edit
dl
rm
lower_bound.hpp
1573
0644
edit
dl
rm
max_element.hpp
2781
0644
edit
dl
rm
merge.hpp
5037
0644
edit
dl
rm
minmax_element.hpp
2668
0644
edit
dl
rm
min_element.hpp
2780
0644
edit
dl
rm
mismatch.hpp
3409
0644
edit
dl
rm
next_permutation.hpp
5703
0644
edit
dl
rm
none_of.hpp
1426
0644
edit
dl
rm
nth_element.hpp
2868
0644
edit
dl
rm
partial_sum.hpp
1676
0644
edit
dl
rm
partition.hpp
1523
0644
edit
dl
rm
partition_copy.hpp
2592
0644
edit
dl
rm
partition_point.hpp
1858
0644
edit
dl
rm
prev_permutation.hpp
5695
0644
edit
dl
rm
random_shuffle.hpp
3010
0644
edit
dl
rm
reduce.hpp
11454
0644
edit
dl
rm
reduce_by_key.hpp
5933
0644
edit
dl
rm
remove.hpp
2002
0644
edit
dl
rm
remove_if.hpp
1850
0644
edit
dl
rm
replace.hpp
2588
0644
edit
dl
rm
replace_copy.hpp
2230
0644
edit
dl
rm
reverse.hpp
2438
0644
edit
dl
rm
reverse_copy.hpp
2678
0644
edit
dl
rm
rotate.hpp
1813
0644
edit
dl
rm
rotate_copy.hpp
1529
0644
edit
dl
rm
scatter.hpp
3435
0644
edit
dl
rm
scatter_if.hpp
4730
0644
edit
dl
rm
search.hpp
2967
0644
edit
dl
rm
search_n.hpp
4428
0644
edit
dl
rm
set_difference.hpp
6941
0644
edit
dl
rm
set_intersection.hpp
6646
0644
edit
dl
rm
set_symmetric_difference.hpp
7533
0644
edit
dl
rm
set_union.hpp
7384
0644
edit
dl
rm
sort.hpp
6569
0644
edit
dl
rm
sort_by_key.hpp
6156
0644
edit
dl
rm
stable_partition.hpp
2737
0644
edit
dl
rm
stable_sort.hpp
3809
0644
edit
dl
rm
stable_sort_by_key.hpp
6071
0644
edit
dl
rm
swap_ranges.hpp
1870
0644
edit
dl
rm
transform.hpp
3252
0644
edit
dl
rm
transform_if.hpp
4737
0644
edit
dl
rm
transform_reduce.hpp
3683
0644
edit
dl
rm
unique.hpp
2565
0644
edit
dl
rm
unique_copy.hpp
6429
0644
edit
dl
rm
upper_bound.hpp
1561
0644
edit
dl
rm
Edit:
/usr/include/boost/compute/algorithm/accumulate.hpp
(6375B)
//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_ALGORITHM_ACCUMULATE_HPP #define BOOST_COMPUTE_ALGORITHM_ACCUMULATE_HPP #include <boost/static_assert.hpp> #include <boost/preprocessor/seq/for_each.hpp> #include <boost/compute/system.hpp> #include <boost/compute/functional.hpp> #include <boost/compute/command_queue.hpp> #include <boost/compute/algorithm/reduce.hpp> #include <boost/compute/algorithm/detail/serial_accumulate.hpp> #include <boost/compute/container/array.hpp> #include <boost/compute/container/vector.hpp> #include <boost/compute/type_traits/is_device_iterator.hpp> #include <boost/compute/detail/iterator_range_size.hpp> namespace boost { namespace compute { namespace detail { // Space complexity O(1) template<class InputIterator, class T, class BinaryFunction> inline T generic_accumulate(InputIterator first, InputIterator last, T init, BinaryFunction function, command_queue &queue) { const context &context = queue.get_context(); size_t size = iterator_range_size(first, last); if(size == 0){ return init; } // accumulate on device array<T, 1> device_result(context); detail::serial_accumulate( first, last, device_result.begin(), init, function, queue ); // copy result to host T result; ::boost::compute::copy_n(device_result.begin(), 1, &result, queue); return result; } // returns true if we can use reduce() instead of accumulate() when // accumulate() this is true when the function is commutative (such as // addition of integers) and the initial value is the identity value // for the operation (zero for addition, one for multiplication). template<class T, class F> inline bool can_accumulate_with_reduce(T init, F function) { (void) init; (void) function; return false; } /// \internal_ #define BOOST_COMPUTE_DETAIL_DECLARE_CAN_ACCUMULATE_WITH_REDUCE(r, data, type) \ inline bool can_accumulate_with_reduce(type init, plus<type>) \ { \ return init == type(0); \ } \ inline bool can_accumulate_with_reduce(type init, multiplies<type>) \ { \ return init == type(1); \ } BOOST_PP_SEQ_FOR_EACH( BOOST_COMPUTE_DETAIL_DECLARE_CAN_ACCUMULATE_WITH_REDUCE, _, (char_)(uchar_)(short_)(ushort_)(int_)(uint_)(long_)(ulong_) ) template<class T> inline bool can_accumulate_with_reduce(T init, min<T>) { return init == (std::numeric_limits<T>::max)(); } template<class T> inline bool can_accumulate_with_reduce(T init, max<T>) { return init == (std::numeric_limits<T>::min)(); } #undef BOOST_COMPUTE_DETAIL_DECLARE_CAN_ACCUMULATE_WITH_REDUCE template<class InputIterator, class T, class BinaryFunction> inline T dispatch_accumulate(InputIterator first, InputIterator last, T init, BinaryFunction function, command_queue &queue) { size_t size = iterator_range_size(first, last); if(size == 0){ return init; } if(can_accumulate_with_reduce(init, function)){ T result; reduce(first, last, &result, function, queue); return result; } else { return generic_accumulate(first, last, init, function, queue); } } } // end detail namespace /// Returns the result of applying \p function to the elements in the /// range [\p first, \p last) and \p init. /// /// If no function is specified, \c plus will be used. /// /// \param first first element in the input range /// \param last last element in the input range /// \param init initial value /// \param function binary reduction function /// \param queue command queue to perform the operation /// /// \return the accumulated result value /// /// In specific situations the call to \c accumulate() can be automatically /// optimized to a call to the more efficient \c reduce() algorithm. This /// occurs when the binary reduction function is recognized as associative /// (such as the \c plus<int> function). /// /// Note that because floating-point addition is not associative, calling /// \c accumulate() with \c plus<float> results in a less efficient serial /// reduction algorithm being executed. If a slight loss in precision is /// acceptable, the more efficient parallel \c reduce() algorithm should be /// used instead. /// /// For example: /// \code /// // with vec = boost::compute::vector<int> /// accumulate(vec.begin(), vec.end(), 0, plus<int>()); // fast /// reduce(vec.begin(), vec.end(), &result, plus<int>()); // fast /// /// // with vec = boost::compute::vector<float> /// accumulate(vec.begin(), vec.end(), 0, plus<float>()); // slow /// reduce(vec.begin(), vec.end(), &result, plus<float>()); // fast /// \endcode /// /// Space complexity: \Omega(1)<br> /// Space complexity when optimized to \c reduce(): \Omega(n) /// /// \see reduce() template<class InputIterator, class T, class BinaryFunction> inline T accumulate(InputIterator first, InputIterator last, T init, BinaryFunction function, command_queue &queue = system::default_queue()) { BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value); return detail::dispatch_accumulate(first, last, init, function, queue); } /// \overload template<class InputIterator, class T> inline T accumulate(InputIterator first, InputIterator last, T init, command_queue &queue = system::default_queue()) { BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value); typedef typename std::iterator_traits<InputIterator>::value_type IT; return detail::dispatch_accumulate(first, last, init, plus<IT>(), queue); } } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_ALGORITHM_ACCUMULATE_HPP
Save
cmd:
run