| 31 | // Space complexity O(1) |
| 32 | template<class InputIterator, class T, class BinaryFunction> |
| 33 | inline T generic_accumulate(InputIterator first, |
| 34 | InputIterator last, |
| 35 | T init, |
| 36 | BinaryFunction function, |
| 37 | command_queue &queue) |
| 38 | { |
| 39 | const context &context = queue.get_context(); |
| 40 | |
| 41 | size_t size = iterator_range_size(first, last); |
| 42 | if(size == 0){ |
| 43 | return init; |
| 44 | } |
| 45 | |
| 46 | // accumulate on device |
| 47 | array<T, 1> device_result(context); |
| 48 | detail::serial_accumulate( |
| 49 | first, last, device_result.begin(), init, function, queue |
| 50 | ); |
| 51 | |
| 52 | // copy result to host |
| 53 | T result; |
| 54 | ::boost::compute::copy_n(device_result.begin(), 1, &result, queue); |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | // returns true if we can use reduce() instead of accumulate() when |
| 59 | // accumulate() this is true when the function is commutative (such as |
no test coverage detected