cub::ArgIndexInputIterator
Defined in cub/iterator/arg_index_input_iterator.cuh
-
template<typename InputIteratorT, typename OffsetT = ptrdiff_t, typename OutputValueT = cub::detail::value_t<InputIteratorT>>
class ArgIndexInputIterator A random-access input wrapper for pairing dereferenced values with their corresponding indices (forming
KeyValuePair
tuples).- Overview
ArgIndexInputIterator wraps a random access input iterator
itr
of typeInputIteratorT
. Dereferencing an ArgIndexInputIterator at offseti
produces aKeyValuePair
value whosekey
field isi
and whosevalue
field isitr[i]
.Can be used with any data type.
Can be constructed, manipulated, and exchanged within and between host and device functions. Wrapped host memory can only be dereferenced on the host, and wrapped device memory can only be dereferenced on the device.
Compatible with Thrust API v1.7 or newer.
- Snippet
The code snippet below illustrates the use of
ArgIndexInputIterator
to dereference an array of doubles#include <cub/cub.cuh> // or equivalently <cub/iterator/arg_index_input_iterator.cuh> // Declare, allocate, and initialize a device array double *d_in; // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0] // Create an iterator wrapper cub::ArgIndexInputIterator<double*> itr(d_in); // Within device code: cub::ArgIndexInputIterator<double*>::value_type tup = *itr; printf("%f @ %ld\n", tup.value, tup.key); // 8.0 @ 0 itr = itr + 6; tup = *itr; printf("%f @ %ld\n", tup.value, tup.key); // 9.0 @ 6
- Template Parameters
InputIteratorT – The value type of the wrapped input iterator
OffsetT – The difference type of this iterator (Default:
ptrdiff_t
)OutputValueT – The paired value type of the <offset,value> tuple (Default: value type of input iterator)
Public Types
-
using self_type = ArgIndexInputIterator
My own type.
-
using difference_type = OffsetT
Type to express the result of subtracting one iterator from another.
-
using value_type = KeyValuePair<difference_type, OutputValueT>
The type of the element the iterator can point to.
-
using pointer = value_type*
The type of a pointer to an element the iterator can point to.
-
using reference = value_type
The type of a reference to an element the iterator can point to.
-
using iterator_category = typename THRUST_NS_QUALIFIER::detail::iterator_facade_category<THRUST_NS_QUALIFIER::any_system_tag, THRUST_NS_QUALIFIER::random_access_traversal_tag, value_type, reference>::type
The iterator category.
Public Functions
-
inline ArgIndexInputIterator(InputIteratorT itr, difference_type offset = 0)
- Parameters
itr – Input iterator to wrap
offset – OffsetT (in items) from
itr
denoting the position of the iterator
-
inline difference_type operator-(self_type other) const
Distance.
-
inline void normalize()
Normalize.