CUSP
Loading...
Searching...
No Matches
cusp::array1d_view< RandomAccessIterator > Class Template Reference

#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.
 
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.
 
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
 

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);
}
1D array of elements that may reside in "host" or "device" memory space
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition array1d.h:99
void print(const Printable &p)
print a textual representation of an object
Print textual representation of an object.

Definition at line 361 of file array1d.h.

Constructor & Destructor Documentation

◆ array1d_view() [1/3]

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

This constructor creates an empty array1d_view vector.

Definition at line 394 of file array1d.h.

◆ array1d_view() [2/3]

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 402 of file array1d.h.

◆ array1d_view() [3/3]

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 410 of file array1d.h.

Member Function Documentation

◆ back()

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.

◆ begin()

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

◆ capacity()

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.

◆ end()

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().

◆ front()

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.

◆ operator=()

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

◆ operator[]()

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.

◆ resize()

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.

◆ size()

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

Returns the number of elements in this array1d_view.

◆ subarray()

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;

◆ swap()

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.

Friends And Related Symbol Documentation

◆ thrust::iterator_core_access

template<typename RandomAccessIterator >
friend class thrust::iterator_core_access
friend

Definition at line 367 of file array1d.h.

Member Data Documentation

◆ m_capacity

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 528 of file array1d.h.

◆ m_size

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 523 of file array1d.h.