transform_output_iterator#
-
template<class _Fn, class _Iter>
class transform_output_iterator# transform_output_iteratoris 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_iteratorfacilitates 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_iteratorwhich appliessqrtfto the assigning value.#include <cuda/iterator> #include <thrust/device_vector.h> struct square_root { __host__ __device__ float operator()(float x) const { return cuda::std::sqrtf(x); } }; int main() { thrust::device_vector<float> v(4); cuda::transform_output_iterator iter(v.begin(), square_root()); 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; }
Public Types
-
using iterator_concept = ::cuda::std::conditional_t<::cuda::std::__has_random_access_traversal<_Iter>, ::cuda::std::random_access_iterator_tag, ::cuda::std::conditional_t<::cuda::std::__has_bidirectional_traversal<_Iter>, ::cuda::std::bidirectional_iterator_tag, ::cuda::std::conditional_t<::cuda::std::__has_forward_traversal<_Iter>, ::cuda::std::forward_iterator_tag, ::cuda::std::output_iterator_tag>>>#
-
using iterator_category = ::cuda::std::output_iterator_tag#
-
using value_type = void#
-
using pointer = void#
-
using reference = void#
Public Functions
-
template<class _Iter2 = _Iter, class _Fn2 = _Fn>
inline constexpr transform_output_iterator( Default constructs a
transform_output_iteratorwith a value initialized iterator and functor.
- inline constexpr transform_output_iterator( ) noexcept(::cuda::std::is_nothrow_move_constructible_v<_Iter> && ::cuda::std::is_nothrow_move_constructible_v<_Fn>)#
Constructs a
transform_output_iteratorwith a given iterator and output functor.- Parameters:
__iter – The iterator to transform
__func – The output function to apply to the iterator on assignment
-
inline constexpr const _Iter &base() const & noexcept#
Returns a const reference to the stored iterator.
- inline constexpr _Iter base(
Extracts the stored iterator.
- inline constexpr auto operator*(
Returns a proxy that transforms the input upon assignment.
- inline constexpr auto operator*(
Returns a proxy that transforms the input upon assignment.
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_subscript<_Iter2>, int> = 0>
inline constexpr auto operator[]( - difference_type __n,
Subscripts the
transform_output_iterator.- Parameters:
__n – The number of elements to advance by
- Returns:
A proxy that transforms the input upon assignment storing the current iterator advanced by a given
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_subscript<_Iter2>, int> = 0>
inline constexpr auto operator[]( - difference_type __n,
Subscripts the
transform_output_iterator.- Parameters:
__n – The number of elements to advance by
- Returns:
A proxy that transforms the input upon assignment storing the current iterator advanced by a given
- inline constexpr transform_output_iterator &operator++(
Increments the stored iterator.
- inline constexpr auto operator++(
- int,
Increments the stored iterator.
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_decrement<_Iter2>, int> = 0>
inline constexpr transform_output_iterator &operator--( Decrements the stored iterator.
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_decrement<_Iter2>, int> = 0>
inline constexpr transform_output_iterator operator--( - int,
Decrements the stored iterator.
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_plus_equal<_Iter2>, int> = 0>
inline constexpr transform_output_iterator &operator+=( - difference_type __n,
Increments the
transform_output_iteratorby a given number of elements.- Parameters:
__n – The number of elements to increment
-
template<class _Iter2 = _Iter, ::cuda::std::enable_if_t<::cuda::std::__iter_can_minus_equal<_Iter2>, int> = 0>
inline constexpr transform_output_iterator &operator-=( - difference_type __n,
Decrements the
transform_output_iteratorby a given number of elements.- Parameters:
__n – The number of elements to decrement
Friends
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator+( - const transform_output_iterator &__iter,
- difference_type __n,
Returns a copy of a
transform_output_iteratorincremented by a given number of elements.- Parameters:
__iter – The
transform_output_iteratorto increment__n – The number of elements to increment
requires (::cuda::std::__iter_can_plus<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator+( - difference_type __n,
- const transform_output_iterator &__iter,
Returns a copy of a
transform_output_iteratorincremented by a given number of elements.- Parameters:
__n – The number of elements to increment
__iter – The
transform_output_iteratorto increment
requires (::cuda::std::__iter_can_plus<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator-( - const transform_output_iterator &__iter,
- difference_type __n,
Returns a copy of a
transform_output_iteratordecremented by a given number of elements.- Parameters:
__iter – The
transform_output_iteratorto decrement__n – The number of elements to decrement
requires (::cuda::std::__iter_can_minus<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator-( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Returns the distance between two
transform_output_iterator.
requires (__can_difference<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator==( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Compares two
transform_output_iteratorfor equality by comparing the stored iterators.
requires (::cuda::std::equality_comparable<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator<( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Compares two
transform_output_iteratorfor less than by comparing the stored iterators.
requires (::cuda::std::__has_random_access_traversal<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator>( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Compares two
transform_output_iteratorfor greater than by comparing the stored iterators.
requires (::cuda::std::__has_random_access_traversal<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator<=( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Compares two
transform_output_iteratorfor less equal by comparing the stored iterators.
requires (::cuda::std::__has_random_access_traversal<_Iter2>)
-
template<class _Iter2 = _Iter>
inline friend constexpr auto operator>=( - const transform_output_iterator &__lhs,
- const transform_output_iterator &__rhs,
Compares two
transform_output_iteratorfor greater equal by comparing the stored iterators.
requires (::cuda::std::__has_random_access_traversal<_Iter2>)
-
template<class _InputFn, class _OutputFn, class _Iter>
inline constexpr auto make_transform_input_output_iterator(
)# make_transform_output_iterator creates a
transform_output_iteratorfrom an iterator, an input functor and an output functor- Parameters:
__iter – The iterator pointing to the input range of the newly created
transform_output_iterator.__input_fun – The input functor used to transform the range when read
__output_fun – The output functor used to transform the range when written
-
template<class _Fn, class _Iter>
inline constexpr auto make_transform_output_iterator(
)# Creates a
transform_output_iteratorfrom an iterator and an output function.- Parameters:
__iter – The iterator of the input range
__fun – The output function
-
using iterator_concept = ::cuda::std::conditional_t<::cuda::std::__has_random_access_traversal<_Iter>, ::cuda::std::random_access_iterator_tag, ::cuda::std::conditional_t<::cuda::std::__has_bidirectional_traversal<_Iter>, ::cuda::std::bidirectional_iterator_tag, ::cuda::std::conditional_t<::cuda::std::__has_forward_traversal<_Iter>, ::cuda::std::forward_iterator_tag, ::cuda::std::output_iterator_tag>>>#