thrust::adjacent_difference#
Overloads#
adjacent_difference(exec, first, last, result)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator>
OutputIterator thrust::adjacent_difference( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
adjacent_differencecalculates the differences of adjacent elements in the range[first, last). That is,*firstis assigned to*result, and, for each iteratoriin the range[first + 1, last), the difference of*iand*(i - 1)is assigned to*(result + (i - first)).This version of
adjacent_differenceusesoperator-to calculate differences.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
adjacent_differenceto compute the difference between adjacent elements of a range using thethrust::deviceexecution policy:Remark
Note that
resultis permitted to be the same iterator asfirst. This is useful for computing differences “in place”.#include <thrust/adjacent_difference.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; thrust::device_vector<int> d_data(h_data, h_data + 8); thrust::device_vector<int> d_result(8); thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin()); // d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
See also
- 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.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator, and
xandyare objects ofInputIterator'svalue_type, thenx-isdefined, andInputIterator'svalue_typeis convertible to a type inOutputIterator'sset ofvalue_types, and the return type ofx - yis convertible to a type inOutputIterator'sset ofvalue_types.OutputIterator – is a model of Output Iterator.
- Returns:
The iterator
result + (last - first)
adjacent_difference(exec, first, last, result, binary_op)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename BinaryFunction>
OutputIterator thrust::adjacent_difference( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
- BinaryFunction binary_op,
adjacent_differencecalculates the differences of adjacent elements in the range[first, last). That is,*firstis assigned to*result, and, for each iteratoriin the range[first + 1, last),binary_op(*i, *(i - 1))is assigned to*(result + (i - first)).This version of
adjacent_differenceuses the binary functionbinary_opto calculate differences.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
adjacent_differenceto compute the sum between adjacent elements of a range using thethrust::deviceexecution policy:Remark
Note that
resultis permitted to be the same iterator asfirst. This is useful for computing differences “in place”.#include <thrust/adjacent_difference.h> #include <thrust/functional.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; thrust::device_vector<int> d_data(h_data, h_data + 8); thrust::device_vector<int> d_result(8); thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin(), ::cuda::std::plus<int>()); // d_result is now [1, 3, 3, 3, 3, 3, 3, 3]
See also
- 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.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toBinaryFunction'sfirst and second argument type, andInputIterator'svalue_typeis convertible to a type inOutputIterator'sset ofvalue_types.OutputIterator – is a model of Output Iterator.
BinaryFunction – The functions’s return type convertible to a type in
OutputIterator'sset ofvalue_types.
- Returns:
The iterator
result + (last - first)
adjacent_difference(first, last, result)#
-
template<typename InputIterator, typename OutputIterator>
OutputIterator thrust::adjacent_difference( - InputIterator first,
- InputIterator last,
- OutputIterator result,
adjacent_differencecalculates the differences of adjacent elements in the range[first, last). That is,*firstis assigned to*result, and, for each iteratoriin the range[first + 1, last), the difference of*iand*(i - 1)is assigned to*(result + (i - first)).This version of
adjacent_differenceusesoperator-to calculate differences.The following code snippet demonstrates how to use
adjacent_differenceto compute the difference between adjacent elements of a range.Remark
Note that
resultis permitted to be the same iterator asfirst. This is useful for computing differences “in place”.#include <thrust/adjacent_difference.h> #include <thrust/device_vector.h> ... int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; thrust::device_vector<int> d_data(h_data, h_data + 8); thrust::device_vector<int> d_result(8); thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin()); // d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
See also
- Parameters:
first – The beginning of the input range.
last – The end of the input range.
result – The beginning of the output range.
- Template Parameters:
InputIterator – is a model of Input Iterator, and
xandyare objects ofInputIterator'svalue_type, thenx-isdefined, andInputIterator'svalue_typeis convertible to a type inOutputIterator'sset ofvalue_types, and the return type ofx - yis convertible to a type inOutputIterator'sset ofvalue_types.OutputIterator – is a model of Output Iterator.
- Returns:
The iterator
result + (last - first)
adjacent_difference(first, last, result, binary_op)#
-
template<typename InputIterator, typename OutputIterator, typename BinaryFunction>
OutputIterator thrust::adjacent_difference( - InputIterator first,
- InputIterator last,
- OutputIterator result,
- BinaryFunction binary_op,
adjacent_differencecalculates the differences of adjacent elements in the range[first, last). That is,*firstis assigned to*result, and, for each iteratoriin the range[first + 1, last),binary_op(*i, *(i - 1))is assigned to*(result + (i - first)).This version of
adjacent_differenceuses the binary functionbinary_opto calculate differences.The following code snippet demonstrates how to use
adjacent_differenceto compute the sum between adjacent elements of a range.Remark
Note that
resultis permitted to be the same iterator asfirst. This is useful for computing differences “in place”.#include <thrust/adjacent_difference.h> #include <thrust/functional.h> #include <thrust/device_vector.h> ... int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; thrust::device_vector<int> d_data(h_data, h_data + 8); thrust::device_vector<int> d_result(8); thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin(), ::cuda::std::plus<int>()); // d_result is now [1, 3, 3, 3, 3, 3, 3, 3]
See also
- Parameters:
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.
- Template Parameters:
InputIterator – is a model of Input Iterator, and
InputIterator'svalue_typeis convertible toBinaryFunction'sfirst and second argument type, andInputIterator'svalue_typeis convertible to a type inOutputIterator'sset ofvalue_types.OutputIterator – is a model of Output Iterator.
BinaryFunction – The function’s return type must be convertible to a type in
OutputIterator'sset ofvalue_types.
- Returns:
The iterator
result + (last - first)