Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
Public Methods | Protected Members | Friends | List of all members
cusp::array1d_view< RandomAccessIterator > Class Template Reference

Detailed description

template<typename RandomAccessIterator>
class cusp::array1d_view< RandomAccessIterator >

The array1d_view class is a 1D vector container that wraps data from various iterators in a array1d datatype.

Template Parameters
RandomAccessIteratorThe iterator type used to encapsulate the underlying data.
Overview
array1d_view vector is a container that wraps existing iterators in array1d datatypes to interoperate with cusp algorithms. array1d_view datatypes are interoperable with a wide range of iterators exposed by Thrust and the STL library.
Example
// include cusp array1d header file
#include <cusp/array1d.h>
#include <cusp/print.h>
int main()
{
// Define the container type
// Get reference to array view type
typedef Array::view View;
// Allocate array1d container with 10 elements
Array array(10,0);
// Create view to the first 5 elements of the array
View first_half(array.begin(), array.begin() + 5);
// Update entries in first_half
first_half[0] = 0; first_half[1] = 1; first_half[2] = 2;
// print the array with updated values
cusp::print(array);
}
Examples:
array2d_raw.cu, cg_raw.cu, csr_raw.cu, and csr_view.cu.

Definition at line 43 of file array1d.h.

#include <array1d.h>

Inheritance diagram for cusp::array1d_view< RandomAccessIterator >:

Public Methods

 array1d_view (void)
 
template<typename ArrayType >
 array1d_view (ArrayType &v)
 
template<typename InputIterator >
 array1d_view (InputIterator begin, InputIterator end)
 
array1d_viewoperator= (const array1d_view &v)
 
reference front (void) const
 
reference back (void) const
 
reference operator[] (size_type n) const
 Subscript access to the data contained in this array1d_view. More...
 
iterator begin (void) const
 
iterator end (void) const
 
size_type size (void) const
 
size_type capacity (void) const
 
void resize (size_type new_size)
 Resizes this array1d_view to the specified number of elements. More...
 
view subarray (size_type start_index, size_type num_entries)
 
void swap (array1d_view &v)
 

Protected Members

size_type m_size
 
size_type m_capacity
 

Friends

class thrust::iterator_core_access
 

Constructor & Destructor Documentation

template<typename RandomAccessIterator>
cusp::array1d_view< RandomAccessIterator >::array1d_view ( void  )
inline

This constructor creates an empty array1d_view vector.

Definition at line 392 of file array1d.h.

template<typename RandomAccessIterator>
template<typename ArrayType >
cusp::array1d_view< RandomAccessIterator >::array1d_view ( ArrayType &  v)
inline

Copy constructor copies from an exemplar array with iterator

Template Parameters
ArrayInput array type supporting iterators
Parameters
vThe vector to copy.

Definition at line 400 of file array1d.h.

template<typename RandomAccessIterator>
template<typename InputIterator >
cusp::array1d_view< RandomAccessIterator >::array1d_view ( InputIterator  begin,
InputIterator  end 
)
inline

This constructor builds a array1d_view vector from a range.

Parameters
beginThe beginning of the range.
endThe end of the range.

Definition at line 408 of file array1d.h.

Member Function Documentation

template<typename RandomAccessIterator>
reference cusp::array1d_view< RandomAccessIterator >::back ( void  ) const

This method returns a reference referring to the last element of this array1d_view.

Returns
The last element of this array1d_view.
template<typename RandomAccessIterator>
iterator cusp::array1d_view< RandomAccessIterator >::begin ( void  ) const

This method returns an iterator pointing to the beginning of this array1d_view.

Returns
base iterator
template<typename RandomAccessIterator>
size_type cusp::array1d_view< RandomAccessIterator >::capacity ( void  ) const

Returns the number of elements which have been reserved in this array1d_view.

template<typename RandomAccessIterator>
iterator cusp::array1d_view< RandomAccessIterator >::end ( void  ) const

This method returns an iterator pointing to one element past the last of this array1d_view.

Returns
begin() + size().
template<typename RandomAccessIterator>
reference cusp::array1d_view< RandomAccessIterator >::front ( void  ) const

This method returns a reference pointing to the first element of this array1d_view.

Returns
The first element of this array1d_view.
template<typename RandomAccessIterator>
array1d_view& cusp::array1d_view< RandomAccessIterator >::operator= ( const array1d_view< RandomAccessIterator > &  v)

Assign operator copies from an exemplar array1d_view vector.

Parameters
vThe array1d_view vector to copy.
Returns
array1d_view copy of input vector
template<typename RandomAccessIterator>
reference cusp::array1d_view< RandomAccessIterator >::operator[] ( size_type  n) const

Subscript access to the data contained in this array1d_view.

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

This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined.

template<typename RandomAccessIterator>
void cusp::array1d_view< RandomAccessIterator >::resize ( size_type  new_size)

Resizes this array1d_view to the specified number of elements.

Parameters
new_sizeNumber of elements this array1d_view should contain.
Exceptions
std::length_errorIf n exceeds max_size9).

This method will resize this vector_base to the specified number of elements. If the number is smaller than this array1d_view's current size this array1d_view is truncated, otherwise throws an error.

template<typename RandomAccessIterator>
size_type cusp::array1d_view< RandomAccessIterator >::size ( void  ) const

Returns the number of elements in this array1d_view.

template<typename RandomAccessIterator>
view cusp::array1d_view< RandomAccessIterator >::subarray ( size_type  start_index,
size_type  num_entries 
)

Extract a small vector from a array1d_view vector.

Parameters
start_indexThe starting index of the sub-array.
num_entriesThe number of entries in the sub-array.
Returns
array1d_view containing elements [start_index,...,start_index+num_entries)
// include cusp array1d header file
#include <cusp/array1d.h>
#include <cusp/print.h>
int main()
{
typedef typename Array::view ArrayView;
// Allocate a array of size 2 in "host" memory
Array a(2);
// Set the first element to 0 and second element to 1
a[0] = 0;
a[1] = 1;
ArrayView a_view(a);
// create a view starting from element 1 of length 1
cusp::print(a_view.subarray(1,1));
}
return 0;
template<typename RandomAccessIterator>
void cusp::array1d_view< RandomAccessIterator >::swap ( array1d_view< RandomAccessIterator > &  v)

This method swaps the contents of this array1d_view with another array1d_view.

Parameters
vThe array1d_view with which to swap.

Member Data Documentation

template<typename RandomAccessIterator>
size_type cusp::array1d_view< RandomAccessIterator >::m_capacity
protected

The capacity of this array1d_view, in number of elements.

Definition at line 526 of file array1d.h.

template<typename RandomAccessIterator>
size_type cusp::array1d_view< RandomAccessIterator >::m_size
protected

The size of this array1d_view, in number of elements.

Definition at line 521 of file array1d.h.