Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
Public Methods | List of all members
cusp::array1d< T, MemorySpace > Class Template Reference

Detailed description

template<typename T, typename MemorySpace>
class cusp::array1d< T, MemorySpace >

The array1d class is a 1D vector container that may contain elements stored in "host" or "device" memory space.

Template Parameters
Tvalue_type of the array
MemorySpacememory space of the array (cusp::host_memory or cusp::device_memory)
Overview
A array1d vector is a container that supports random access to elements. The memory associated with a array1d vector may reside in either "host" or "device" memory depending on the supplied allocator embedded in the MemorySpace template argument. array1d vectors inherit a considerable amount of functionality from the thrust::detail::vector_base case.
See Also
http://thrust.github.io/doc/classthrust_1_1host__vector.html
http://thrust.github.io/doc/classthrust_1_1device__vector.html
Example
// include cusp array1d header file
#include <cusp/array1d.h>
int main()
{
// Allocate a array of size 2 in "host" memory
// Set the first element to 0 and second element to 1
a[0] = 0;
a[1] = 1;
// Allocate a seceond array in "device" memory that is
// a copy of the first
}
Examples:
array1d.cu, blas.cu, csr_view.cu, maximal_independent_set.cu, monitor.cu, multiply.cu, stencil.cu, unordered_triplets.cu, and verbose_monitor.cu.

Definition at line 98 of file array1d.h.

#include <array1d.h>

Inheritance diagram for cusp::array1d< T, MemorySpace >:

Public Methods

 array1d (void)
 
 array1d (size_type n)
 
 array1d (size_type n, const value_type &value)
 
 array1d (const array1d &v)
 
array1doperator= (const array1d &v)
 
template<typename OtherT , typename OtherMem >
 array1d (const array1d< OtherT, OtherMem > &v)
 
template<typename OtherT , typename OtherMem >
array1doperator= (const array1d< OtherT, OtherMem > &v)
 
template<typename OtherT , typename OtherAlloc >
 array1d (const std::vector< OtherT, OtherAlloc > &v)
 
template<typename OtherT , typename OtherAlloc >
array1doperator= (const std::vector< OtherT, OtherAlloc > &v)
 
template<typename OtherT , typename OtherAlloc >
 array1d (const thrust::host_vector< OtherT, OtherAlloc > &v)
 
template<typename OtherT , typename OtherAlloc >
array1doperator= (const thrust::host_vector< OtherT, OtherAlloc > &v)
 
template<typename OtherT , typename OtherAlloc >
 array1d (const thrust::device_vector< OtherT, OtherAlloc > &v)
 
template<typename OtherT , typename OtherAlloc >
array1doperator= (const thrust::device_vector< OtherT, OtherAlloc > &v)
 
template<typename InputIterator >
 array1d (InputIterator first, InputIterator last)
 
template<typename InputIterator >
 array1d (const array1d_view< InputIterator > &v)
 
view subarray (size_type start_index, size_type num_entries)
 
const_view subarray (size_type start_index, size_type num_entries) const
 

Constructor & Destructor Documentation

template<typename T, typename MemorySpace>
cusp::array1d< T, MemorySpace >::array1d ( void  )
inline

This constructor creates an empty array1d vector.

Definition at line 126 of file array1d.h.

template<typename T, typename MemorySpace>
cusp::array1d< T, MemorySpace >::array1d ( size_type  n)
inlineexplicit

This constructor creates a array1d vector with the given size.

Parameters
nThe number of elements to initially create.

Definition at line 133 of file array1d.h.

template<typename T, typename MemorySpace>
cusp::array1d< T, MemorySpace >::array1d ( size_type  n,
const value_type &  value 
)
inlineexplicit

This constructor creates a array1d vector with copies of an exemplar element.

Parameters
nThe number of elements to initially create.
valueAn element to copy.

Definition at line 141 of file array1d.h.

template<typename T, typename MemorySpace>
cusp::array1d< T, MemorySpace >::array1d ( const array1d< T, MemorySpace > &  v)
inline

Copy constructor copies from an exemplar array1d

Parameters
vThe array1d to copy.

Definition at line 147 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherMem >
cusp::array1d< T, MemorySpace >::array1d ( const array1d< OtherT, OtherMem > &  v)
inline

Copy constructor copies from an exemplar array1d with different type

Template Parameters
OtherTType of array1d
OtherMemAllocator of array1d
Parameters
vThe array1d to copy.

Definition at line 162 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
cusp::array1d< T, MemorySpace >::array1d ( const std::vector< OtherT, OtherAlloc > &  v)
inline

Copy constructor copies from an exemplar std::vector with different type

Template Parameters
OtherTType of std::vector
OtherAllocAllocator of std::vector
Parameters
vThe std::vector to copy.

Definition at line 180 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
cusp::array1d< T, MemorySpace >::array1d ( const thrust::host_vector< OtherT, OtherAlloc > &  v)
inline

Copy constructor copies from an exemplar thrust::host_vector with different type

Template Parameters
OtherTType of thrust::host_vector
OtherAllocAllocator of thrust::host_vector
Parameters
vThe thrust::host_vector to copy.

Definition at line 198 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
cusp::array1d< T, MemorySpace >::array1d ( const thrust::device_vector< OtherT, OtherAlloc > &  v)
inline

Copy constructor copies from an exemplar thrust::device_vector with different type

Template Parameters
OtherTType of thrust::device_vector
OtherAllocAllocator of thrust::device_vector
Parameters
vThe thrust::device_vector to copy.

Definition at line 216 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename InputIterator >
cusp::array1d< T, MemorySpace >::array1d ( InputIterator  first,
InputIterator  last 
)
inline

This constructor builds a array1d vector from a range.

Template Parameters
Iteratoriterator type of copy elements
Parameters
firstThe beginning of the range.
lastThe end of the range.

Definition at line 234 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename InputIterator >
cusp::array1d< T, MemorySpace >::array1d ( const array1d_view< InputIterator > &  v)
inline

Copy constructor copies from an exemplar array1d_view

Template Parameters
InputIteratoriterator type of copy elements
Parameters
vThe array1d_view to copy.

Definition at line 242 of file array1d.h.

Member Function Documentation

template<typename T, typename MemorySpace>
array1d& cusp::array1d< T, MemorySpace >::operator= ( const array1d< T, MemorySpace > &  v)
inline

Assign operator copies from an exemplar array1d.

Parameters
vThe array1d to copy.

Definition at line 153 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherMem >
array1d& cusp::array1d< T, MemorySpace >::operator= ( const array1d< OtherT, OtherMem > &  v)
inline

Assign operator copies from an exemplar array1d.

Template Parameters
OtherTType of array1d
OtherMemAllocator of array1d
Parameters
vThe array1d to copy.

Definition at line 171 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
array1d& cusp::array1d< T, MemorySpace >::operator= ( const std::vector< OtherT, OtherAlloc > &  v)
inline

Assign operator copies from an exemplar std::vector.

Template Parameters
OtherTType of std::vector
OtherAllocAllocator of std::vector
Parameters
vThe std::vector to copy.

Definition at line 189 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
array1d& cusp::array1d< T, MemorySpace >::operator= ( const thrust::host_vector< OtherT, OtherAlloc > &  v)
inline

Assign operator copies from an exemplar thrust::host_vector.

Template Parameters
OtherTType of thrust::host_vector
OtherAllocAllocator of thrust::host_vector
Parameters
vThe thrust::host_vector to copy.

Definition at line 207 of file array1d.h.

template<typename T, typename MemorySpace>
template<typename OtherT , typename OtherAlloc >
array1d& cusp::array1d< T, MemorySpace >::operator= ( const thrust::device_vector< OtherT, OtherAlloc > &  v)
inline

Assign operator copies from an exemplar thrust::device_vector.

Template Parameters
OtherTType of thrust::device_vector
OtherAllocAllocator of thrust::device_vector
Parameters
vThe thrust::device_vector to copy.

Definition at line 225 of file array1d.h.

template<typename T, typename MemorySpace>
view cusp::array1d< T, MemorySpace >::subarray ( size_type  start_index,
size_type  num_entries 
)

Extract a array from a array1d container.

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;
// create a view starting from element 1 of length 1
ArrayView first(a.subarray(1,1));
cusp::print(first);
return 0;
}
template<typename T, typename MemorySpace>
const_view cusp::array1d< T, MemorySpace >::subarray ( size_type  start_index,
size_type  num_entries 
) const

Extract a const array from a array1d container.

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::const_view ConstArrayView;
// 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;
// create a view starting from element 1 of length 1
ConstArrayView first(a.subarray(1,1));
cusp::print(first);
return 0;
}