OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Matrix< T > Class Template Reference

Matrix. More...

#include <Matrix.h>

Inheritance diagram for Matrix< T >:
Collaboration diagram for Matrix< T >:

Public Types

typedef T value_type
 The value type of the array.
typedef T * iterator
 The iterator type for sequential access to all elements.
typedef const T * const_iterator
 The iterator type for sequential access to all elements.
typedef T * row_iterator
 The iterator type for access by rows.
typedef const T * const_row_iterator
 The iterator type for access by rows for a constant array.
typedef SliceIterator< T > col_iterator
 The iterator type for access by columns.
typedef ConstSliceIterator< T > const_col_iterator
 The iterator type for access by columns for a constant array.

Public Member Functions

 Matrix ()
 Default constructor.
 Matrix (const Array2D< T > &)
 Conversion.
 Matrix (int rows, int cols)
 Constructor.
 Matrix (int rows, int cols, const T &t)
 Constructor.
 Matrix (const Matrix &)
 ~Matrix ()
Matrix< T > & operator= (const Matrix< T > &)
Matrix< T > & operator= (const Array2D< T > &)
 Convert and assign.
Matrix< T > & operator*= (const T &)
 Multiply by scalar and assign.
Matrix< T > & operator/= (const T &)
 Divide by scalar and assign.
Matrix< T > & operator+= (const Matrix< T > &)
 Add matrix and assign..
Matrix< T > & operator-= (const Matrix< T > &)
 Subtract matrix and assign.
Matrix< T > & operator+= (const T &)
 Add scalar.
Matrix< T > & operator-= (const T &)
 Subtract scalar.
Matrix< T > & operator*= (const Matrix< T > &)
 Multiply by matrix and assign.
Matrix< T > transpose () const
 Matrix transpose.
Matrix< T > dotm (const Matrix< T > &) const
 Matrix product.
Vector< T > dotcv (const Vector< T > &) const
 Matrix times column vector.
Vector< T > dotrv (const Vector< T > &) const
 Row vector times matrix.
T & operator() (int r, int c)
 Get element reference.
const T & operator() (int r, int c) const
 Get element value.
int nrows () const
 Get number of rows.
int ncols () const
 Get number of columns.
int size () const
 Get total size (rows times columns).
iterator begin ()
 Get pointer to beginning of data.
const_iterator begin () const
 Get pointer to beginning of data.
iterator end ()
 Get pointer past end of data.
const_iterator end () const
 Get pointer past end of data.
row_iterator row_begin (int r)
 Get row iterator.
const_row_iterator row_begin (int r) const
 Get row iterator.
row_iterator row_end (int r)
 Get row iterator.
const_row_iterator row_end (int r) const
 Get row iterator.
row_iterator operator[] (int r)
 Get row iterator.
const_row_iterator operator[] (int r) const
 Get row iterator.
col_iterator col_begin (int c)
 Get column iterator.
const_col_iterator col_begin (int c) const
 Get column iterator.
col_iterator col_end (int c)
 Get column iterator.
const_col_iterator col_end (int c) const
 Get column iterator.
void getColumn (Array1D< T > &toArray, int c) const
 Fetch column.
void getRow (Array1D< T > &toArray, int r) const
 Fetch row.
void putColumn (const Array1D< T > &fromArray, int c)
 Store column.
void putRow (const Array1D< T > &fromArray, int r)
 Store row.
void swapColumns (int c1, int c2)
 Exchange columns.
void swapRows (int row1, int row2)
 Exchange rows.

Protected Attributes

int rows
int cols
int len
T * data

Detailed Description

template<class T>
class Matrix< T >

Matrix.

Definition at line 39 of file Matrix.h.

Member Typedef Documentation

◆ col_iterator

template<class T>
typedef SliceIterator<T> Array2D< T >::col_iterator
inherited

The iterator type for access by columns.

Definition at line 61 of file Array2D.h.

◆ const_col_iterator

template<class T>
typedef ConstSliceIterator<T> Array2D< T >::const_col_iterator
inherited

The iterator type for access by columns for a constant array.

Definition at line 64 of file Array2D.h.

◆ const_iterator

template<class T>
typedef const T* Array2D< T >::const_iterator
inherited

The iterator type for sequential access to all elements.

Definition at line 52 of file Array2D.h.

◆ const_row_iterator

template<class T>
typedef const T* Array2D< T >::const_row_iterator
inherited

The iterator type for access by rows for a constant array.

Definition at line 58 of file Array2D.h.

◆ iterator

template<class T>
typedef T* Array2D< T >::iterator
inherited

The iterator type for sequential access to all elements.

Definition at line 48 of file Array2D.h.

◆ row_iterator

template<class T>
typedef T* Array2D< T >::row_iterator
inherited

The iterator type for access by rows.

Definition at line 55 of file Array2D.h.

◆ value_type

template<class T>
typedef T Array2D< T >::value_type
inherited

The value type of the array.

Definition at line 45 of file Array2D.h.

Constructor & Destructor Documentation

◆ Matrix() [1/5]

template<class T>
Matrix< T >::Matrix ( )

Default constructor.

Definition at line 140 of file Matrix.h.

References Array2D< T >::Array2D().

Referenced by dotm(), Matrix(), operator*=(), operator*=(), operator+=(), operator+=(), operator-=(), operator-=(), operator/=(), operator=(), operator=(), and transpose().

Here is the call graph for this function:

◆ Matrix() [2/5]

template<class T>
Matrix< T >::Matrix ( const Array2D< T > & rhs)

Conversion.

Definition at line 152 of file Matrix.h.

References Array2D< T >::Array2D().

Here is the call graph for this function:

◆ Matrix() [3/5]

template<class T>
Matrix< T >::Matrix ( int rows,
int cols )

Constructor.

Definition at line 158 of file Matrix.h.

References Array2D< T >::Array2D(), Array2D< T >::cols, and Array2D< T >::rows.

Here is the call graph for this function:

◆ Matrix() [4/5]

template<class T>
Matrix< T >::Matrix ( int rows,
int cols,
const T & t )

Constructor.

Definition at line 164 of file Matrix.h.

References Array2D< T >::Array2D(), Array2D< T >::cols, Array2D< T >::data, and Array2D< T >::rows.

Here is the call graph for this function:

◆ Matrix() [5/5]

template<class T>
Matrix< T >::Matrix ( const Matrix< T > & rhs)

Definition at line 146 of file Matrix.h.

References Array2D< T >::Array2D(), and Matrix().

Here is the call graph for this function:

◆ ~Matrix()

template<class T>
Matrix< T >::~Matrix ( )

Definition at line 173 of file Matrix.h.

Member Function Documentation

◆ begin() [1/2]

template<class T>
Array2D< T >::iterator Array2D< T >::begin ( )
inlineinherited

Get pointer to beginning of data.

Definition at line 319 of file Array2D.h.

References data.

Referenced by Array2D(), Array2D(), Matrix< T >::operator+=(), operator-(), Matrix< T >::operator-=(), and operator=().

◆ begin() [2/2]

template<class T>
Array2D< T >::const_iterator Array2D< T >::begin ( ) const
inlineinherited

Get pointer to beginning of data.

Definition at line 331 of file Array2D.h.

References data.

◆ col_begin() [1/2]

template<class T>
Array2D< T >::col_iterator Array2D< T >::col_begin ( int c)
inherited

Get column iterator.

Definition at line 391 of file Array2D.h.

References c, cols, and data.

Referenced by LUMatrix< T >::backSubstitute(), Matrix< T >::dotm(), getColumn(), Matrix< T >::operator+=(), Matrix< T >::operator-=(), putColumn(), and swapColumns().

◆ col_begin() [2/2]

template<class T>
Array2D< T >::const_col_iterator Array2D< T >::col_begin ( int c) const
inherited

Get column iterator.

Definition at line 409 of file Array2D.h.

References c, cols, and data.

◆ col_end() [1/2]

template<class T>
Array2D< T >::col_iterator Array2D< T >::col_end ( int c)
inherited

Get column iterator.

Definition at line 400 of file Array2D.h.

References c, cols, data, and len.

Referenced by getColumn(), and swapColumns().

◆ col_end() [2/2]

template<class T>
Array2D< T >::const_col_iterator Array2D< T >::col_end ( int c) const
inherited

Get column iterator.

Definition at line 418 of file Array2D.h.

References c, cols, data, and len.

◆ dotcv()

template<class T>
Vector< T > Matrix< T >::dotcv ( const Vector< T > & B) const

Matrix times column vector.

Definition at line 362 of file Matrix.h.

References Array1D< T >::begin(), Array2D< T >::ncols(), nr, Array2D< T >::nrows(), Array2D< T >::row_begin(), Array2D< T >::row_end(), and Array1D< T >::size().

Referenced by operator*().

Here is the call graph for this function:

◆ dotm()

template<class T>
Matrix< T > Matrix< T >::dotm ( const Matrix< T > & B) const

Matrix product.

Definition at line 340 of file Matrix.h.

References Array2D< T >::col_begin(), Matrix(), Array2D< T >::ncols(), Array2D< T >::nrows(), Array2D< T >::row_begin(), and Array2D< T >::row_end().

Referenced by operator*().

Here is the call graph for this function:

◆ dotrv()

template<class T>
Vector< T > Matrix< T >::dotrv ( const Vector< T > & B) const

Row vector times matrix.

Definition at line 379 of file Matrix.h.

References Array1D< T >::begin(), Array1D< T >::end(), Array2D< T >::ncols(), Array2D< T >::nrows(), and Array1D< T >::size().

Referenced by operator*().

Here is the call graph for this function:

◆ end() [1/2]

template<class T>
Array2D< T >::iterator Array2D< T >::end ( )
inlineinherited

Get pointer past end of data.

Definition at line 325 of file Array2D.h.

References data, and len.

Referenced by Array2D(), Array2D(), and operator=().

◆ end() [2/2]

template<class T>
Array2D< T >::const_iterator Array2D< T >::end ( ) const
inlineinherited

Get pointer past end of data.

Definition at line 337 of file Array2D.h.

References data, and len.

◆ getColumn()

template<class T>
void Array2D< T >::getColumn ( Array1D< T > & toArray,
int c ) const
inherited

Fetch column.

Definition at line 427 of file Array2D.h.

References Array1D< T >::begin(), c, col_begin(), col_end(), rows, and Array1D< T >::size().

Here is the call graph for this function:

◆ getRow()

template<class T>
void Array2D< T >::getRow ( Array1D< T > & toArray,
int r ) const
inherited

Fetch row.

Definition at line 434 of file Array2D.h.

References Array1D< T >::begin(), cols, row_begin(), row_end(), and Array1D< T >::size().

Here is the call graph for this function:

◆ ncols()

◆ nrows()

◆ operator()() [1/2]

template<class T>
T & Array2D< T >::operator() ( int r,
int c )
inlineinherited

Get element reference.

Definition at line 283 of file Array2D.h.

References c, cols, data, ncols(), and rows.

Here is the call graph for this function:

◆ operator()() [2/2]

template<class T>
const T & Array2D< T >::operator() ( int r,
int c ) const
inlineinherited

Get element value.

Definition at line 292 of file Array2D.h.

References c, cols, data, ncols(), and rows.

Here is the call graph for this function:

◆ operator*=() [1/2]

template<class T>
Matrix< T > & Matrix< T >::operator*= ( const Matrix< T > & array)

Multiply by matrix and assign.

Definition at line 252 of file Matrix.h.

References Matrix().

Here is the call graph for this function:

◆ operator*=() [2/2]

template<class T>
Matrix< T > & Matrix< T >::operator*= ( const T & val)

Multiply by scalar and assign.

Definition at line 192 of file Matrix.h.

References begin(), end(), and Matrix().

Here is the call graph for this function:

◆ operator+=() [1/2]

template<class T>
Matrix< T > & Matrix< T >::operator+= ( const Matrix< T > & array)

Add matrix and assign..

Definition at line 208 of file Matrix.h.

References Array2D< T >::begin(), begin(), end(), Matrix(), Array2D< T >::ncols(), and Array2D< T >::nrows().

Here is the call graph for this function:

◆ operator+=() [2/2]

template<class T>
Matrix< T > & Matrix< T >::operator+= ( const T & val)

Add scalar.

Definition at line 230 of file Matrix.h.

References Array2D< T >::col_begin(), Matrix(), Array2D< T >::ncols(), and Array2D< T >::nrows().

Here is the call graph for this function:

◆ operator-=() [1/2]

template<class T>
Matrix< T > & Matrix< T >::operator-= ( const Matrix< T > & array)

Subtract matrix and assign.

Definition at line 219 of file Matrix.h.

References Array2D< T >::begin(), begin(), end(), Matrix(), Array2D< T >::ncols(), and Array2D< T >::nrows().

Here is the call graph for this function:

◆ operator-=() [2/2]

template<class T>
Matrix< T > & Matrix< T >::operator-= ( const T & val)

Subtract scalar.

Definition at line 241 of file Matrix.h.

References Array2D< T >::col_begin(), Matrix(), Array2D< T >::ncols(), and Array2D< T >::nrows().

Here is the call graph for this function:

◆ operator/=()

template<class T>
Matrix< T > & Matrix< T >::operator/= ( const T & val)

Divide by scalar and assign.

Definition at line 200 of file Matrix.h.

References begin(), end(), and Matrix().

Here is the call graph for this function:

◆ operator=() [1/2]

template<class T>
Matrix< T > & Matrix< T >::operator= ( const Array2D< T > & rhs)

Convert and assign.

Definition at line 185 of file Matrix.h.

References Array2D< T >::Array2D(), Matrix(), and Array2D< T >::operator=().

Here is the call graph for this function:

◆ operator=() [2/2]

template<class T>
Matrix< T > & Matrix< T >::operator= ( const Matrix< T > & rhs)

Definition at line 178 of file Matrix.h.

References Matrix(), and Array2D< T >::operator=().

Here is the call graph for this function:

◆ operator[]() [1/2]

template<class T>
Array2D< T >::row_iterator Array2D< T >::operator[] ( int r)
inherited

Get row iterator.

Definition at line 379 of file Array2D.h.

References cols, and data.

◆ operator[]() [2/2]

template<class T>
Array2D< T >::const_row_iterator Array2D< T >::operator[] ( int r) const
inherited

Get row iterator.

Definition at line 385 of file Array2D.h.

References cols, and data.

◆ putColumn()

template<class T>
void Array2D< T >::putColumn ( const Array1D< T > & fromArray,
int c )
inherited

Store column.

Definition at line 441 of file Array2D.h.

References Array1D< T >::begin(), c, col_begin(), Array1D< T >::end(), rows, and Array1D< T >::size().

Here is the call graph for this function:

◆ putRow()

template<class T>
void Array2D< T >::putRow ( const Array1D< T > & fromArray,
int r )
inherited

Store row.

Definition at line 450 of file Array2D.h.

References Array1D< T >::begin(), cols, Array1D< T >::end(), row_begin(), and Array1D< T >::size().

Here is the call graph for this function:

◆ row_begin() [1/2]

template<class T>
Array2D< T >::row_iterator Array2D< T >::row_begin ( int r)
inherited

Get row iterator.

Definition at line 343 of file Array2D.h.

References cols, data, and rows.

Referenced by Matrix< T >::dotcv(), Matrix< T >::dotm(), getRow(), putRow(), swapRows(), and Matrix< T >::transpose().

◆ row_begin() [2/2]

template<class T>
Array2D< T >::const_row_iterator Array2D< T >::row_begin ( int r) const
inherited

Get row iterator.

Definition at line 361 of file Array2D.h.

References cols, data, and rows.

◆ row_end() [1/2]

template<class T>
Array2D< T >::row_iterator Array2D< T >::row_end ( int r)
inherited

Get row iterator.

Definition at line 352 of file Array2D.h.

References cols, data, and rows.

Referenced by Matrix< T >::dotcv(), Matrix< T >::dotm(), getRow(), swapRows(), and Matrix< T >::transpose().

◆ row_end() [2/2]

template<class T>
Array2D< T >::const_row_iterator Array2D< T >::row_end ( int r) const
inherited

Get row iterator.

Definition at line 370 of file Array2D.h.

References cols, data, and rows.

◆ size()

template<class T>
int Array2D< T >::size ( ) const
inlineinherited

Get total size (rows times columns).

Definition at line 313 of file Array2D.h.

References len.

◆ swapColumns()

template<class T>
void Array2D< T >::swapColumns ( int c1,
int c2 )
inherited

Exchange columns.

Definition at line 459 of file Array2D.h.

References col_begin(), and col_end().

Here is the call graph for this function:

◆ swapRows()

template<class T>
void Array2D< T >::swapRows ( int row1,
int row2 )
inherited

Exchange rows.

Definition at line 465 of file Array2D.h.

References row_begin(), and row_end().

Here is the call graph for this function:

◆ transpose()

template<class T>
Matrix< T > Matrix< T >::transpose ( ) const

Matrix transpose.

Definition at line 259 of file Matrix.h.

References Matrix(), Array2D< T >::ncols(), nr, Array2D< T >::nrows(), Array2D< T >::row_begin(), and Array2D< T >::row_end().

Here is the call graph for this function:

Member Data Documentation

◆ cols

◆ data

◆ len

template<class T>
int Array2D< T >::len
protectedinherited

Definition at line 222 of file Array2D.h.

Referenced by Array2D(), Array2D(), Array2D(), Array2D(), col_end(), col_end(), end(), end(), operator=(), and size().

◆ rows

template<class T>
int Array2D< T >::rows
protectedinherited

The documentation for this class was generated from the following file: