SkePU(integratedwithStarPU) 0.8
Classes | Public Member Functions | Friends
skepu::Matrix< T > Class Template Reference

A matrix container class (2D matrix), internally uses 1D container (std::vector). More...

#include <matrix.h>

List of all members.

Classes

class  col_iterator
class  iterator
 An matrix iterator class that tranverses row-wise. More...
class  proxy_elem
 A proxy class representing one element of Matrix. More...

Public Member Functions

starpu_data_handle_t registerMatrix ()
 To register Matrix with StarPU. Does not create partitions of Matrix.
void unregisterMatrix (bool update=true)
starpu_data_handle_t registerPartitions (int _xparts=1, int _yparts=1)
 To register Matrix to StarPU. This method can create partitions of the matrix.
T * GetArrayRep ()
void randomize (int min=0, int max=RAND_MAX)
 Randomizes the Matrix.
void save (const std::string &filename)
 Saves content of Matrix to a file.
void load (const std::string &filename, int rowWidth, int numRows=0)
 Loads the Matrix from a file.
 ~Matrix ()
 Matrix (size_type _rows, size_type _cols)
 Matrix (size_type _rows, size_type _cols, const T &val)
 Matrix (const Matrix< T > &copy)
size_type size () const
size_type total_rows () const
size_type total_cols () const
void change_layout ()
Matrix< T > & operator= (Matrix< T > &other)
Matrix< T > & operator= (const T &elem)
bool operator== (const Matrix< T > &c1)
bool operator!= (const Matrix< T > &c1)
bool operator< (const Matrix< T > &c1)
bool operator> (const Matrix< T > &c1)
bool operator<= (const Matrix< T > &c1)
bool operator>= (const Matrix< T > &c1)
Matrix< T > & subsection (size_type row, size_type col, size_type rowWidth, size_type colWidth)
iterator begin ()
const_iterator begin () const
iterator begin (unsigned row)
const_iterator begin (unsigned row) const
iterator end ()
const_iterator end () const
iterator end (unsigned row)
const_iterator end (unsigned row) const
std::pair< const_iterator,
const_iterator > 
col_iterator_range ()
col_iterator col_begin ()
col_iterator col_end ()
size_type capacity () const
void flush ()
bool empty () const
void clear ()
void swap (Matrix< T > &from)
void acquireRead () const
void acquireReadWrite ()
const Matrix< T > & operator+= (const Matrix< T > &rhs)
const Matrix< T > & operator+= (const T &rhs)
const Matrix< T > & operator-= (const Matrix< T > &rhs)
const Matrix< T > & operator-= (const T &rhs)
const Matrix< T > & operator*= (const Matrix< T > &rhs)
const Matrix< T > & operator*= (const T &rhs)
const Matrix< T > & operator/= (const Matrix< T > &rhs)
const Matrix< T > & operator/= (const T &rhs)
const Matrix< T > & operator%= (const Matrix< T > &rhs)
const Matrix< T > & operator%= (const T &rhs)

Friends

std::ostream & operator<< (std::ostream &os, Matrix< T > &matrix)
 Overloaded stream operator, for testing purposes.

Detailed Description

template<typename T>
class skepu::Matrix< T >

A matrix container class (2D matrix), internally uses 1D container (std::vector).

A skepu::Matrix is a 2D container that internally stores in a 1D std::vector. Its interface and behaviour is largely compatible with skepu::Vector and std::vector but with some additions and variations for 2D. Instead of the regular element, it sometimes returns a proxy element so it can distinguish between reads and writes. In this version, it just register/unregister data back to StarPU and does not keep track of data by itself (no lazy memory copying).


Constructor & Destructor Documentation

template<typename T>
skepu::Matrix< T >::~Matrix ( ) [inline]

Destructor, used to deallocate memory mainly, device memory.

References skepu::Matrix< T >::total_cols(), and skepu::Matrix< T >::total_rows().

Here is the call graph for this function:

template<typename T>
skepu::Matrix< T >::Matrix ( size_type  _rows,
size_type  _cols 
) [inline]

Constructor, used to allocate memory ($_rows * _cols$).

Parameters:
_rowsNumber of rows in the matrix.
_colsNumber of columns in the matrix.
template<typename T>
skepu::Matrix< T >::Matrix ( size_type  _rows,
size_type  _cols,
const T &  val 
) [inline]

Constructor, used to allocate memory ($_rows * _cols$). With a value ot initialize all elements.

Parameters:
_rowsNumber of rows in the matrix.
_colsNumber of columns in the matrix.
valA value to initialize all elements.
template<typename T>
skepu::Matrix< T >::Matrix ( const Matrix< T > &  copy) [inline]

Copy Constructor, used to assign copy of another matrix.

Parameters:
copyMatrix that is being assigned.

Update the matrix before assigning it to assign latest copy.

References skepu::Matrix< T >::acquireRead(), skepu::Matrix< T >::total_cols(), and skepu::Matrix< T >::total_rows().

Here is the call graph for this function:


Member Function Documentation

template<typename T >
void skepu::Matrix< T >::acquireRead ( ) const [inline]

Ensure that data is most updated for reading purpose on CPU

template<typename T >
void skepu::Matrix< T >::acquireReadWrite ( ) [inline]

Ensure that data is most updated for reading and writing purpose on CPU

template<typename T >
Matrix< T >::iterator skepu::Matrix< T >::begin ( )

Please refer to the documentation of std::vector and skepu::Matrix::iterator.

template<typename T >
Matrix< T >::const_iterator skepu::Matrix< T >::begin ( ) const

Please refer to the documentation of std::vector and skepu::Matrix::iterator.

template<typename T >
Matrix< T >::const_iterator skepu::Matrix< T >::begin ( unsigned  row) const

Please refer to the documentation of std::vector and skepu::Matrix::iterator. Uses row to get an iterator for that row.

Parameters:
rowThe index of row from where to start iterator.
template<typename T >
Matrix< T >::iterator skepu::Matrix< T >::begin ( unsigned  row)

Please refer to the documentation of std::vector and skepu::Matrix::iterator. Uses row to get an iterator for that row.

Parameters:
rowThe index of row from where to start iterator.
template<typename T >
Matrix< T >::size_type skepu::Matrix< T >::capacity ( ) const

Please refer to the documentation of std::vector.

template<typename T>
void skepu::Matrix< T >::change_layout ( ) [inline]

A small utility to change rows and columns numbers with each other. A Matrix (4x7) will become (7x4) after this function call without changing the actual values. Not similar to transpose where you actually change the values.

template<typename T >
void skepu::Matrix< T >::clear ( )

Please refer to the documentation of std::vector. Invalidates all copies before clear.

template<typename T >
Matrix< T >::col_iterator skepu::Matrix< T >::col_begin ( )

This works by taking a transpose of current matrix.

template<typename T >
Matrix< T >::col_iterator skepu::Matrix< T >::col_end ( )

This works by taking a transpose of current matrix.

template<typename T >
std::pair< typename Matrix< T >::const_iterator, typename Matrix< T >::const_iterator > skepu::Matrix< T >::col_iterator_range ( )

This works by taking a transpose of current matrix. Returns begin and end iterator as std::pair. Can be used to make read-onkly traversal.

template<typename T >
bool skepu::Matrix< T >::empty ( ) const

Please refer to the documentation of std::vector.

template<typename T >
Matrix< T >::iterator skepu::Matrix< T >::end ( )

Please refer to the documentation of std::vector and skepu::Matrix::iterator.

template<typename T >
Matrix< T >::const_iterator skepu::Matrix< T >::end ( ) const

Please refer to the documentation of std::vector and skepu::Matrix::iterator.

template<typename T >
Matrix< T >::const_iterator skepu::Matrix< T >::end ( unsigned  row) const

Please refer to the documentation of std::vector and skepu::Matrix::iterator. Get iterator to last element of row.

Parameters:
rowIndex of row the iterator will point to the last element.
template<typename T >
Matrix< T >::iterator skepu::Matrix< T >::end ( unsigned  row)

Please refer to the documentation of std::vector and skepu::Matrix::iterator. Get iterator to last element of row.

Parameters:
rowIndex of row the iterator will point to the last element.
template<typename T >
void skepu::Matrix< T >::flush ( )

Flushes the matrix, synchronizing it with the device then release all device allocations.

template<typename T>
T* skepu::Matrix< T >::GetArrayRep ( ) [inline]

Get array representation

template<typename T>
void skepu::Matrix< T >::load ( const std::string &  filename,
int  rowWidth,
int  numRows = 0 
) [inline]

Loads the Matrix from a file.

Reads a variable number of elements from a file. In the file, all elemets should be in ASCII on one line with whitespace between each element. Mainly for testing purposes.

Parameters:
filenameName of file to save to.
rowWidthThe width of a row. All rows get same amount of width.
numRowsThe number of rows to be loaded. Default value 0 means all rows.

References skepu::Matrix< T >::clear(), and skepu::Matrix< T >::size().

Here is the call graph for this function:

template<typename T>
bool skepu::Matrix< T >::operator!= ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator%= ( const Matrix< T > &  rhs)

Taking Mod with rhs matrix, element wise to current matrix. Two matrices must be of same size.

Parameters:
rhsThe value which is used in taking mod to current matrix.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator%= ( const T &  rhs)

Taking Mod with a scalar value to all elements in the current matrix.

Parameters:
rhsThe value which is used in taking mod to current matrix.
template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator*= ( const T &  rhs)

Multiplies a scalar value to all elements in the current matrix.

Parameters:
rhsThe value which is used in multiplication to current matrix.
template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator*= ( const Matrix< T > &  rhs)

Multiplies rhs matrix operation element wise to current matrix. Two matrices must be of same size. NB it is not matrix multiplication

Parameters:
rhsThe matrix which is used in multiplication to current matrix.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator+= ( const T &  rhs)

Adds a scalar value to all elements in the current matrix.

Parameters:
rhsThe value which is used in addition to current matrix.
template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator+= ( const Matrix< T > &  rhs)

Add rhs matrix operation element wise to current matrix. Two matrices must be of same size.

Parameters:
rhsThe matrix which is used in addition to current matrix.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator-= ( const Matrix< T > &  rhs)

Subtract rhs matrix operation element wise to current matrix. Two matrices must be of same size.

Parameters:
rhsThe matrix which is used in subtraction to current matrix.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator-= ( const T &  rhs)

Subtracts a scalar value to all elements in the current matrix.

Parameters:
rhsThe value which is used in subtraction to current matrix.
template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator/= ( const Matrix< T > &  rhs)

Divides rhs matrix operation element wise to current matrix. Two matrices must be of same size. NB it is not matrix multiplication

Parameters:
rhsThe matrix which is used in division to current matrix.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
const Matrix< T > & skepu::Matrix< T >::operator/= ( const T &  rhs)

Divides a scalar value to all elements in the current matrix.

Parameters:
rhsThe value which is used in division to current matrix.
template<typename T>
bool skepu::Matrix< T >::operator< ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
bool skepu::Matrix< T >::operator<= ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
Matrix< T > & skepu::Matrix< T >::operator= ( const T &  elem)

To initialize a matrix with some scalar value.

Parameters:
elemThe element you want to assign to all matrix.
template<typename T>
Matrix< T > & skepu::Matrix< T >::operator= ( Matrix< T > &  other)

copy matrix,,, copy row and column count as well along with data

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
bool skepu::Matrix< T >::operator== ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
bool skepu::Matrix< T >::operator> ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
bool skepu::Matrix< T >::operator>= ( const Matrix< T > &  c1)

Please refer to the documentation of std::vector.

References skepu::Matrix< T >::acquireRead().

Here is the call graph for this function:

template<typename T>
void skepu::Matrix< T >::randomize ( int  min = 0,
int  max = RAND_MAX 
) [inline]

Randomizes the Matrix.

Sets each element of the Matrix to a random number between min and max. The numbers are generated as integers but are cast to the type of the matrix.

Parameters:
minThe smallest number an element can become.
maxThe largest number an element can become.

References skepu::Matrix< T >::size(), and skepu::Matrix< T >::unregisterMatrix().

Here is the call graph for this function:

template<typename T>
void skepu::Matrix< T >::save ( const std::string &  filename) [inline]

Saves content of Matrix to a file.

Outputs the matrix as text on one line with space between elements to the specified file. Mainly for testing purposes.

Parameters:
filenameName of file to save to.
template<typename T>
size_type skepu::Matrix< T >::size ( ) const [inline]

Returns total size of Matrix.

Returns:
size of the Matrix.
template<typename T>
Matrix< T > & skepu::Matrix< T >::subsection ( size_type  row,
size_type  col,
size_type  rowWidth,
size_type  colWidth 
)

To get a subsection of matrix. This will creat a separate copy.

Parameters:
rowIndex of row to get.
rowWidthWidth of the row of new Matrix.
colIndex of column to get.
colWidthWidth of column of new Matrix.

References skepu::Matrix< T >::total_cols(), and skepu::Matrix< T >::total_rows().

Here is the call graph for this function:

template<typename T>
void skepu::Matrix< T >::swap ( Matrix< T > &  from)

Please refer to the documentation of std::vector. Updates and invalidate both Matrices before swapping.

References skepu::Matrix< T >::unregisterMatrix().

Here is the call graph for this function:

template<typename T>
size_type skepu::Matrix< T >::total_cols ( ) const [inline]

Returns total number of columns in the Matrix.

Returns:
columns in the Matrix.
template<typename T>
size_type skepu::Matrix< T >::total_rows ( ) const [inline]

Returns total number of rows in the Matrix.

Returns:
rows in the Matrix.
template<typename T>
void skepu::Matrix< T >::unregisterMatrix ( bool  update = true) [inline]

Used to unregister data handle with StarPU (pass "false" to not ensure most updated value is returned back)


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
Matrix< T > &  matrix 
) [friend]

Overloaded stream operator, for testing purposes.

Outputs the matrix rowwise having one row on each line.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Enumerations Friends Defines