template<typename DerivedPolicy , typename InputIterator , typename OutputIterator , typename BinaryFunction >
__host__ __device__ OutputIterator thrust::adjacent_difference |
( |
const thrust::detail::execution_policy_base< DerivedPolicy > & |
exec, |
|
|
InputIterator |
first, |
|
|
InputIterator |
last, |
|
|
OutputIterator |
result, |
|
|
BinaryFunction |
binary_op |
|
) |
| |
adjacent_difference
calculates the differences of adjacent elements in the range [first, last)
. That is, *first
is assigned to *result
, and, for each iterator i
in the range [first + 1, last)
, binary_op(*i, *(i - 1))
is assigned to *(result + (i - first))
.
This version of adjacent_difference
uses the binary function binary_op
to calculate differences.
The algorithm's execution is parallelized as determined by exec
.
- Parameters
-
exec | The execution policy to use for parallelization. |
first | The beginning of the input range. |
last | The end of the input range. |
result | The beginning of the output range. |
binary_op | The binary function used to compute differences. |
- Returns
- The iterator
result + (last - first)
- Template Parameters
-
DerivedPolicy | The name of the derived execution policy. |
InputIterator | is a model of Input Iterator, and InputIterator's value_type is convertible to BinaryFunction's first_argument_type and second_argument_type , and InputIterator's value_type is convertible to a type in OutputIterator's set of value_types . |
OutputIterator | is a model of Output Iterator. |
BinaryFunction's | result_type is convertible to a type in OutputIterator's set of value_types . |
The following code snippet demonstrates how to use adjacent_difference
to compute the sum between adjacent elements of a range using the thrust::device
execution policy:
...
int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
- See also
- https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
-
inclusive_scan