CUSP
Loading...
Searching...
No Matches
cusp::random_iterator< T > Class Template Reference

#include <random_iterator.h>

Public Methods

 random_iterator (const size_t seed=0)
 This constructor builds a random_iterator using a specified seed.
 
iterator begin (void) const
 This method returns an iterator pointing to the beginning of this random sequence of entries.
 
value_type operator[] (size_type n) const
 Subscript access to the data contained in this iterator.
 

Detailed description

template<typename T>
class cusp::random_iterator< T >

Iterator for generating random values.

Template Parameters
TThe type used to encapsulate the underlying data.
Overview
random_iterator is an iterator which represents a pointer into a range of random values. This iterator is useful for creating a range filled with random values without explicitly storing it in memory. Using random_iterator saves both memory capacity and bandwidth.
Example
The following code snippet demonstrates how to create a random_iterator whose value_type is int and whose seed is 5.
#include <cusp/array1d.h>
#include <iostream>
int main(void)
{
std::cout << iter[0] << std::endl;
std::cout << iter[1] << std::endl;
std::cout << iter[2] << std::endl;
}
1D array of elements that may reside in "host" or "device" memory space
Iterator for generating random values.
An iterator which generates random entries.

Definition at line 81 of file random_iterator.h.

Constructor & Destructor Documentation

◆ random_iterator()

template<typename T >
cusp::random_iterator< T >::random_iterator ( const size_t  seed = 0)
inline

This constructor builds a random_iterator using a specified seed.

Parameters
seedThe seed initial value used to generate the random sequence.

Definition at line 107 of file random_iterator.h.

Member Function Documentation

◆ begin()

template<typename T >
iterator cusp::random_iterator< T >::begin ( void  ) const
inline

This method returns an iterator pointing to the beginning of this random sequence of entries.

Returns
mStart

Definition at line 114 of file random_iterator.h.

◆ operator[]()

template<typename T >
value_type cusp::random_iterator< T >::operator[] ( size_type  n) const
inline

Subscript access to the data contained in this iterator.

Parameters
nThe index of the element for which data should be accessed.
Returns
Read reference to data.

This operator allows for easy, array-style, data access.

Definition at line 125 of file random_iterator.h.