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

Detailed description

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
class cusp::array2d< ValueType, MemorySpace, Orientation >

The array2d class is a 2D 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)
Orientationorientation of the array (cusp::row_major or cusp::column_major)
Overview
A array2d vector is a container that supports random access to elements. The memory associated with a array2d vector may reside in either "host" or "device" memory depending on the supplied allocator embedded in the MemorySpace template argument. array2d vectors represent 2D matrices in either row-major or column-major format.
Example
// include cusp array2d header file
#include <cusp/array2d.h>
#include <cusp/print.h>
int main()
{
// Allocate a array of size 2 in "host" memory
// Set the entries in the matrix using shorthand operator
a(0,0) = 0; a(0,1) = 1; a(0,2) = 2;
a(1,0) = 3; a(1,1) = 4; a(1,2) = 5;
a(2,0) = 6; a(2,1) = 7; a(2,2) = 8;
// Allocate a seceond array2d in "device" memory that is
// a copy of the first but in column major
// print row-major layout of data
// [0, 1, 2, 3, 4, 5, 6, 7, 8]
cusp::print(a.values);
// print column-major layout of data
// [0, 3, 6, 1, 4, 7, 2, 5, 8]
cusp::print(b.values);
}
Examples:
matrix_market.cu, multiply.cu, and transpose.cu.

Definition at line 93 of file array2d.h.

#include <array2d.h>

Inheritance diagram for cusp::array2d< ValueType, MemorySpace, Orientation >:

Public Methods

 array2d (void)
 
 array2d (size_t num_rows, size_t num_cols)
 
 array2d (size_t num_rows, size_t num_cols, const ValueType &value)
 
 array2d (const size_t num_rows, const size_t num_cols, const ValueType &value, const size_t pitch)
 
template<typename MatrixType >
 array2d (const MatrixType &matrix)
 
values_array_type::reference operator() (const size_t i, const size_t j)
 
values_array_type::const_reference operator() (const size_t i, const size_t j) const
 
void resize (const size_t num_rows, const size_t num_cols)
 
void resize (const size_t num_rows, const size_t num_cols, const size_t pitch)
 
void swap (array2d &matrix)
 
row_view row (const size_t i)
 
column_view column (const size_t i)
 
const_row_view row (const size_t i) const
 
const_column_view column (const size_t i) const
 
array2doperator= (const array2d &matrix)
 
template<typename MatrixType >
array2doperator= (const MatrixType &matrix)
 

Public Members

size_t pitch
 
values_array_type values
 

Constructor & Destructor Documentation

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
cusp::array2d< ValueType, MemorySpace, Orientation >::array2d ( void  )
inline

This constructor creates an empty array2d vector.

Definition at line 149 of file array2d.h.

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
cusp::array2d< ValueType, MemorySpace, Orientation >::array2d ( size_t  num_rows,
size_t  num_cols 
)
inline

This constructor creates a array2d vector with the given shape.

Parameters
num_rowsThe number of elements to initially create.
num_colsThe number of elements to initially create.

Definition at line 157 of file array2d.h.

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
cusp::array2d< ValueType, MemorySpace, Orientation >::array2d ( size_t  num_rows,
size_t  num_cols,
const ValueType &  value 
)
inline

This constructor creates a array2d vector with the given shape and fills the entries with a given value.

Parameters
num_rowsThe number of array2d rows.
num_colsThe number of array2d columns.
valueThe initial value of all entries.

Definition at line 168 of file array2d.h.

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
cusp::array2d< ValueType, MemorySpace, Orientation >::array2d ( const size_t  num_rows,
const size_t  num_cols,
const ValueType &  value,
const size_t  pitch 
)

This constructor creates a array2d vector with the given shape, fills the entries with a given value and sets the pitch

Parameters
num_rowsThe number of array2d rows.
num_colsThe number of array2d columns.
valueThe initial value of all entries.
pitchThe stride between entries in the major dimension.
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
template<typename MatrixType >
cusp::array2d< ValueType, MemorySpace, Orientation >::array2d ( const MatrixType &  matrix)

This constructor creates a array2d vector from another matrix

Template Parameters
MatrixTypeType of the input matrix
Parameters
matrixInput matrix used to create array2d matrix

Member Function Documentation

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
column_view cusp::array2d< ValueType, MemorySpace, Orientation >::column ( const size_t  i)

This method generates a array1d_view of column i of this array2d matrix

Parameters
iThe column index used to create array1d_view
Returns
array1d_view of column i
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
const_column_view cusp::array2d< ValueType, MemorySpace, Orientation >::column ( const size_t  i) const

This method generates a const array1d_view of column i of this array2d matrix

Parameters
iThe column index used to create array1d_view
Returns
const array1d_view of column i
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
values_array_type::reference cusp::array2d< ValueType, MemorySpace, Orientation >::operator() ( const size_t  i,
const size_t  j 
)

Subscript access to the data contained in this array2d.

Parameters
iRow index for which data should be accessed.
jColumn index for which data should be accessed.
Returns
Read/write reference to data.
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
values_array_type::const_reference cusp::array2d< ValueType, MemorySpace, Orientation >::operator() ( const size_t  i,
const size_t  j 
) const

Subscript access to the data contained in this array2d.

Parameters
iRow index for which data should be accessed.
jColumn index for which data should be accessed.
Returns
Read reference to data.
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
array2d& cusp::array2d< ValueType, MemorySpace, Orientation >::operator= ( const array2d< ValueType, MemorySpace, Orientation > &  matrix)

Assign operator copies from an exemplar array2d container.

Parameters
matrixThe array2d container to copy.
Returns
array2d copy of input matrix
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
template<typename MatrixType >
array2d& cusp::array2d< ValueType, MemorySpace, Orientation >::operator= ( const MatrixType &  matrix)

Assign operator copies from an exemplar matrix container.

Template Parameters
MatrixTypeThe type of matrix to copy.
Parameters
matrixThe matrix to copy.
Returns
array2d copy of input matrix.
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
void cusp::array2d< ValueType, MemorySpace, Orientation >::resize ( const size_t  num_rows,
const size_t  num_cols 
)

This method will resize this array2d to the specified dimensions. If the number of total entries is smaller than this array2d's current size this array2d is truncated, otherwise this array2d is extended with the value of new entries undefined.

Parameters
num_rowsThe number of rows this array2d should contain
num_colsThe number of columns this array2d should contain
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
void cusp::array2d< ValueType, MemorySpace, Orientation >::resize ( const size_t  num_rows,
const size_t  num_cols,
const size_t  pitch 
)

This method will resize this array2d to the specified dimensions. If the number of total entries is smaller than this array2d's current size this array2d is truncated, otherwise this array2d is extended with the value of new entries undefined.

Parameters
num_rowsThe number of rows this array2d should contain
num_colsThe number of columns this array2d should contain
pitchThe stride between major dimension entries this array2d should contain
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
row_view cusp::array2d< ValueType, MemorySpace, Orientation >::row ( const size_t  i)

This method generates a array1d_view of row i of this array2d matrix

Parameters
iThe row index used to create array1d_view
Returns
array1d_view of row i
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
const_row_view cusp::array2d< ValueType, MemorySpace, Orientation >::row ( const size_t  i) const

This method generates a const array1d_view of row i of this array2d matrix

Parameters
iThe row index used to create array1d_view
Returns
const array1d_view of row i
template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
void cusp::array2d< ValueType, MemorySpace, Orientation >::swap ( array2d< ValueType, MemorySpace, Orientation > &  matrix)

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

Parameters
matrixThe array2d with which to swap.

Member Data Documentation

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
size_t cusp::array2d< ValueType, MemorySpace, Orientation >::pitch

The stride between consecutive elements along the major dimension

Definition at line 141 of file array2d.h.

template<typename ValueType, typename MemorySpace, typename Orientation = cusp::row_major>
values_array_type cusp::array2d< ValueType, MemorySpace, Orientation >::values

1D array of values

Definition at line 145 of file array2d.h.