thrust::transform#
Overloads#
transform(exec, first, last, result, op)#
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename UnaryFunction>
OutputIterator thrust::transform( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator first,
- InputIterator last,
- OutputIterator result,
- UnaryFunction op,
This version of
transformapplies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence.Specifically, for each iterator
iin the range [first,last) the operationop(*i)is performed and the result is assigned to*o, whereois the corresponding output iterator in the range [result,result+ (last-first) ). The input and output sequences may coincide, resulting in an in-place transformation.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
transformto negate a range in-place using thethrust::hostexecution policy for parallelization:#include <thrust/transform.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> ... int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; ::cuda::std::negate<int> op; thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
\verbatim embed:rst Some backends of transform may take advantage knowing if the transformation operation supports :ref:
copyable arguments <address-stability>. \endverbatim- Parameters:
exec – The execution policy to use for parallelization.
first – The beginning of the input sequence.
last – The end of the input sequence.
result – The beginning of the output sequence.
op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible toUnaryFunction'sargument type.OutputIterator – is a model of Output Iterator.
UnaryFunction – is a unary function type which’s return type is convertible to
OutputIterator'svalue_type.
- Returns:
The end of the output sequence.
- Pre:
firstmay equalresult, but the range[first, last)shall not overlap the range[result, result + (last - first))otherwise.
transform(first, last, result, op)#
-
template<typename InputIterator, typename OutputIterator, typename UnaryFunction>
OutputIterator thrust::transform( - InputIterator first,
- InputIterator last,
- OutputIterator result,
- UnaryFunction op,
This version of
transformapplies a unary function to each element of an input sequence and stores the result in the corresponding position in an output sequence.Specifically, for each iterator
iin the range [first,last) the operationop(*i)is performed and the result is assigned to*o, whereois the corresponding output iterator in the range [result,result+ (last-first) ). The input and output sequences may coincide, resulting in an in-place transformation.The following code snippet demonstrates how to use
transform#include <thrust/transform.h> #include <thrust/functional.h> int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; ::cuda::std::negate<int> op; thrust::transform(data, data + 10, data, op); // in-place transformation // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8};
\verbatim embed:rst Some backends of transform may take advantage knowing if the transformation operation supports :ref:
copyable arguments <address-stability>. \endverbatim- Parameters:
first – The beginning of the input sequence.
last – The end of the input sequence.
result – The beginning of the output sequence.
op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated.
- Template Parameters:
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible toUnaryFunction'sargument type.OutputIterator – is a model of Output Iterator.
UnaryFunction – is a unary function type which’s return type is convertible to
OutputIterator'svalue_type.
- Returns:
The end of the output sequence.
- Pre:
firstmay equalresult, but the range[first, last)shall not overlap the range[result, result + (last - first))otherwise.
transform(exec, first1, last1, first2, result, op)#
-
template<typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryFunction>
OutputIterator thrust::transform( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- OutputIterator result,
- BinaryFunction op,
This version of
transformapplies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence.Specifically, for each iterator
iin the range [first1,last1) andj = first + (i - first1)in the range [first2,last2) the operationop(*i,*j)is performed and the result is assigned to*o, whereois the corresponding output iterator in the range [result,result+ (last-first) ). The input and output sequences may coincide, resulting in an in-place transformation.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
transformto compute the sum of two ranges using thethrust::hostexecution policy for parallelization:#include <thrust/transform.h> #include <thrust/functional.h> #include <thrust/execution_policy.h> ... int input1[6] = {-5, 0, 2, 3, 2, 4}; int input2[6] = { 3, 6, -2, 1, 2, 3}; int output[6]; ::cuda::std::plus<int> op; thrust::transform(thrust::host, input1, input1 + 6, input2, output, op); // output is now {-2, 6, 0, 4, 4, 7};
\verbatim embed:rst Some backends of transform may take advantage knowing if the transformation operation supports :ref:
copyable arguments <address-stability>. \endverbatim- Parameters:
exec – The execution policy to use for parallelization.
first1 – The beginning of the first input sequence.
last1 – The end of the first input sequence.
first2 – The beginning of the second input sequence.
result – The beginning of the output sequence.
op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated.
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
InputIterator1 – is a model of Input Iterator and
InputIterator1'svalue_typeis convertible toBinaryFunction'sfirst argument type.InputIterator2 – is a model of Input Iterator and
InputIterator2'svalue_typeis convertible toBinaryFunction'ssecond argument type.OutputIterator – is a model of Output Iterator.
BinaryFunction – is a binary function type which’s return type is convertible to
OutputIterator'svalue_type.
- Returns:
The end of the output sequence.
- Pre:
first1may equalresult, but the range[first1, last1)shall not overlap the range[result, result + (last1 - first1))otherwise.- Pre:
first2may equalresult, but the range[first2, first2 + (last1 - first1))shall not overlap the range[result, result + (last1 - first1))otherwise.
transform(first1, last1, first2, result, op)#
-
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryFunction>
OutputIterator thrust::transform( - InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- OutputIterator result,
- BinaryFunction op,
This version of
transformapplies a binary function to each pair of elements from two input sequences and stores the result in the corresponding position in an output sequence.Specifically, for each iterator
iin the range [first1,last1) andj = first + (i - first1)in the range [first2,last2) the operationop(*i,*j)is performed and the result is assigned to*o, whereois the corresponding output iterator in the range [result,result+ (last-first) ). The input and output sequences may coincide, resulting in an in-place transformation.The following code snippet demonstrates how to use
transform#include <thrust/transform.h> #include <thrust/functional.h> int input1[6] = {-5, 0, 2, 3, 2, 4}; int input2[6] = { 3, 6, -2, 1, 2, 3}; int output[6]; ::cuda::std::plus<int> op; thrust::transform(input1, input1 + 6, input2, output, op); // output is now {-2, 6, 0, 4, 4, 7};
\verbatim embed:rst Some backends of transform may take advantage knowing if the transformation operation supports :ref:
copyable arguments <address-stability>. \endverbatim- Parameters:
first1 – The beginning of the first input sequence.
last1 – The end of the first input sequence.
first2 – The beginning of the second input sequence.
result – The beginning of the output sequence.
op – The transformation operation. Relying on the address of op’s arguments in its implementation is deprecated.
- Template Parameters:
InputIterator1 – is a model of Input Iterator and
InputIterator1'svalue_typeis convertible toBinaryFunction'sfirst argument type.InputIterator2 – is a model of Input Iterator and
InputIterator2'svalue_typeis convertible toBinaryFunction'ssecond argument type.OutputIterator – is a model of Output Iterator.
BinaryFunction – is a binary function type which’s return type is convertible to
OutputIterator'svalue_type.
- Returns:
The end of the output sequence.
- Pre:
first1may equalresult, but the range[first1, last1)shall not overlap the range[result, result + (last1 - first1))otherwise.- Pre:
first2may equalresult, but the range[first2, first2 + (last1 - first1))shall not overlap the range[result, result + (last1 - first1))otherwise.