thrust
List of all members
thrust::transform_output_iterator< UnaryFunction, OutputIterator > Class Template Reference

#include <thrust/iterator/transform_output_iterator.h>

Inherits type< UnaryFunction, OutputIterator >.

Detailed Description

template<typename UnaryFunction, typename OutputIterator>
class thrust::transform_output_iterator< UnaryFunction, OutputIterator >

transform_output_iterator is a special kind of output iterator which transforms a value written upon dereference. This iterator is useful for transforming an output from algorithms without explicitly storing the intermediate result in the memory and applying subsequent transformation, thereby avoiding wasting memory capacity and bandwidth. Using transform_iterator facilitates kernel fusion by deferring execution of transformation until the value is written while saving both memory capacity and bandwidth.

The following code snippet demonstrated how to create a transform_output_iterator which applies sqrtf to the assigning value.

// note: functor inherits form unary function
// note: functor inherits from unary_function
struct square_root : public thrust::unary_function<float,float>
{
__host__ __device__
float operator()(float x) const
{
return sqrtf(x);
}
};
int main()
{
iter[0] = 1.0f; // stores sqrtf( 1.0f)
iter[1] = 4.0f; // stores sqrtf( 4.0f)
iter[2] = 9.0f; // stores sqrtf( 9.0f)
iter[3] = 16.0f; // stores sqrtf(16.0f)
// iter[4] is an out-of-bounds error
v[0]; // returns 1.0f;
v[1]; // returns 2.0f;
v[2]; // returns 3.0f;
v[3]; // returns 4.0f;
}
See also
make_transform_output_iterator

The documentation for this class was generated from the following file: