fmatvec  0.0.0
Fast Matrix/Vector Library
Public Types | Public Member Functions | Static Public Attributes | List of all members
fmatvec::Matrix< General, Ref, Ref, AT > Class Template Reference

This is a matrix class for general matrices. More...

#include <general_matrix.h>

Inheritance diagram for fmatvec::Matrix< General, Ref, Ref, AT >:
[legend]

Public Types

typedef AT value_type
 
typedef General shape_type
 
typedef Iterator< false > iterator
 
typedef Iterator< true > const_iterator
 

Public Member Functions

 Matrix ()
 Standard constructor. More...
 
 Matrix (int m_, int n_, Noinit)
 
 Matrix (int m_, int n_, Init ini=INIT, const AT &a=AT())
 
 Matrix (int m_, int n_, Eye ini, const AT &a=1)
 
 Matrix (const Matrix< General, Ref, Ref, AT > &A)
 Copy Constructor. More...
 
template<class Row , class Col >
 Matrix (const Matrix< General, Row, Col, AT > &A)
 Copy Constructor. More...
 
template<class Type , class Row , class Col >
 Matrix (const Matrix< Type, Row, Col, AT > &A)
 Copy Constructor. More...
 
 Matrix (int m_, int n_, AT *ele_)
 Regular Constructor. More...
 
 Matrix (const std::string &strs)
 String Constructor. More...
 
 Matrix (const char *strs)
 
 ~Matrix ()=default
 Destructor.
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
Matrix< General, Ref, Ref, AT > & resize (int m_, int n_, Noinit)
 
Matrix< General, Ref, Ref, AT > & resize (int m, int n, Init ini=INIT, const AT &a=AT())
 
Matrix< General, Ref, Ref, AT > & resize (int m, int n, Eye ini, const AT &a=1)
 
Matrix< General, Ref, Ref, AT > & operator= (const Matrix< General, Ref, Ref, AT > &A)
 Assignment operator. More...
 
template<class Type , class Row , class Col >
Matrix< General, Ref, Ref, AT > & operator= (const Matrix< Type, Row, Col, AT > &A)
 Assignment operator. More...
 
Matrix< General, Ref, Ref, AT > & operator&= (Matrix< General, Ref, Ref, AT > &A)
 Reference operator. More...
 
template<class Type , class Row , class Col >
Matrix< General, Ref, Ref, AT > & operator<<= (const Matrix< Type, Row, Col, AT > &A)
 Matrix assignment. More...
 
template<class AT2 >
 operator Matrix< General, Ref, Ref, AT2 > () const
 
AT & operator() (int i, int j)
 Element operator. More...
 
const AT & operator() (int i, int j) const
 Element operator. More...
 
AT & e (int i, int j)
 
const AT & e (int i, int j) const
 
AT * operator() ()
 Pointer operator. More...
 
const AT * operator() () const
 Pointer operator. More...
 
int rows () const
 Number of rows. More...
 
int cols () const
 Number of columns. More...
 
int ldim () const
 Leading dimension. More...
 
const CBLAS_TRANSPOSE blasTrans () const
 Transposed status. More...
 
const CBLAS_ORDER blasOrder () const
 Storage convention. More...
 
const Matrix< General, Ref, Ref, AT > operator() (const Range< Var, Var > &I, const Range< Var, Var > &J) const
 Submatrix operator. More...
 
const SquareMatrix< Ref, AT > operator() (const Range< Var, Var > &I) const
 Submatrix operator.
 
const RowVector< Ref, AT > row (int i) const
 Row operator.
 
const Vector< Ref, AT > col (int j) const
 Column operator.
 
Matrix< General, Ref, Ref, AT > & init (const AT &val=AT())
 Initialization. More...
 
Matrix< General, Ref, Ref, AT > & init (Init, const AT &a=AT())
 
Matrix< General, Ref, Ref, AT > & init (Eye, const AT &val=1)
 
Matrix< General, Ref, Ref, AT > & init (Noinit, const AT &a=AT())
 
Matrix< General, Ref, Ref, AT > & init0 (const AT &val=AT())
 
Matrix< General, Ref, Ref, AT > & init0 (Init, const AT &a=AT())
 
 operator std::vector< std::vector< AT >> () const
 Cast to std::vector<std::vector<AT>>. More...
 
 Matrix (const std::vector< std::vector< AT >> &m)
 std::vector<std::vector<AT>> Constructor. Constructs and initializes a matrix with a std::vector<std::vector<AT>> object. An FMATVEC_ASSERT checks for constant length of each row. More...
 
const Matrix< General, Ref, Ref, AT > T () const
 Cast to AT. More...
 
template<class Row >
void set (int j, const Vector< Row, AT > &x)
 
template<class Col >
void set (int i, const RowVector< Col, AT > &x)
 
template<class Type , class Row , class Col >
void set (const fmatvec::Range< Var, Var > &I, const fmatvec::Range< Var, Var > &J, const Matrix< Type, Row, Col, AT > &A)
 
template<class Row >
void add (int j, const Vector< Row, AT > &x)
 
template<class Col >
void add (int i, const RowVector< Col, AT > &x)
 
template<class Type , class Row , class Col >
void add (const fmatvec::Range< Var, Var > &I, const fmatvec::Range< Var, Var > &J, const Matrix< Type, Row, Col, AT > &A)
 
template<class Type , class Row , class Col >
void sub (const fmatvec::Range< Var, Var > &I, const fmatvec::Range< Var, Var > &J, const Matrix< Type, Row, Col, AT > &A)
 
void ref (Matrix< General, Ref, Ref, AT > &A, const fmatvec::Range< Var, Var > &I, const fmatvec::Range< Var, Var > &J)
 
void ref (Matrix< Symmetric, Ref, Ref, AT > &A, const fmatvec::Range< Var, Var > &I, const fmatvec::Range< Var, Var > &J)
 
int countElements () const
 Count nonzero elements. More...
 

Static Public Attributes

static constexpr bool isVector {false}
 

Detailed Description

template<class AT>
class fmatvec::Matrix< General, Ref, Ref, AT >

This is a matrix class for general matrices.

Template class Matrix with shape type General and atomic type AT. The storage form is dense. The template parameter AT defines the atomic type of the matrix. Valid types are int, float, double, complex<float> and complex<double>

Constructor & Destructor Documentation

◆ Matrix() [1/7]

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( )
inlineexplicit

Standard constructor.

Constructs a matrix with no size.

◆ Matrix() [2/7]

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( const Matrix< General, Ref, Ref, AT > &  A)
inline

Copy Constructor.

Constructs a copy of the matrix A.

Parameters
AThe matrix that will be copied.

◆ Matrix() [3/7]

template<class AT >
template<class Row , class Col >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( const Matrix< General, Row, Col, AT > &  A)
inline

Copy Constructor.

Constructs a copy of the matrix A.

Parameters
AThe matrix that will be copied.

◆ Matrix() [4/7]

template<class AT >
template<class Type , class Row , class Col >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( const Matrix< Type, Row, Col, AT > &  A)
inlineexplicit

Copy Constructor.

Constructs a copy of the matrix A.

Parameters
AThe matrix that will be copied.

◆ Matrix() [5/7]

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( int  m_,
int  n_,
AT *  ele_ 
)
inlineexplicit

Regular Constructor.

Constructs a matrix of size m x n with the pyhsical memory given by ele_.

Parameters
m_The number of rows.
n_The number of columns.
ele_The physical memory the matrix will point to.

◆ Matrix() [6/7]

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( const std::string &  strs)

String Constructor.

Constructs and initializes a matrix with a string in a matlab-like notation. The rows are seperated by semicolons, the columns by commas. For example

Matrix<General<Ref,Ref>double> A("[3,2;1,2]");

constructs the matrix

\[ A=\begin{pmatrix}3 & 2\\ 1 & 2\end{pmatrix} \]

Parameters
strThe string the matrix will be initialized with.

◆ Matrix() [7/7]

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::Matrix ( const std::vector< std::vector< AT >> &  m)
inlineexplicit

std::vector<std::vector<AT>> Constructor. Constructs and initializes a matrix with a std::vector<std::vector<AT>> object. An FMATVEC_ASSERT checks for constant length of each row.

Parameters
mThe std::vector<std::vector<AT>> the matrix will be initialized with.

Member Function Documentation

◆ blasOrder()

template<class AT >
const CBLAS_ORDER fmatvec::Matrix< General, Ref, Ref, AT >::blasOrder ( ) const
inline

Storage convention.

Returns the blas-conform storage convention. The elements are stored in columnmajor form, i.e. the elements are stored columnwise.

Returns
CblasColMajor.

◆ blasTrans()

template<class AT >
const CBLAS_TRANSPOSE fmatvec::Matrix< General, Ref, Ref, AT >::blasTrans ( ) const
inline

Transposed status.

Returns the blas-conform transposed status.

Returns
CblasTrans if the matrix is in transposed form, CblasNoTrans otherwise.

◆ cols()

template<class AT >
int fmatvec::Matrix< General, Ref, Ref, AT >::cols ( ) const
inline

Number of columns.

Returns
The number of columns of the matrix.

◆ countElements()

template<class AT >
int fmatvec::Matrix< General, Ref, Ref, AT >::countElements ( ) const

Count nonzero elements.

This function counts the nonzero elements of a matrix. ALL diagonal elements are treated as NONZERO!!! (See the storage format for sparse matrix)

Returns
The number of nonzero or diagonal elemets.

◆ init()

template<class AT >
Matrix< General, Ref, Ref, AT > & fmatvec::Matrix< General, Ref, Ref, AT >::init ( const AT &  val = AT())
inline

Initialization.

Initializes all elements of the calling matrix with the value given by a.

Parameters
aValue all elements will be initialized with.
Returns
A reference to the calling matrix.

◆ ldim()

template<class AT >
int fmatvec::Matrix< General, Ref, Ref, AT >::ldim ( ) const
inline

Leading dimension.

Returns
The leading dimension of the matrix.

◆ operator std::vector< std::vector< AT >>()

template<class AT >
fmatvec::Matrix< General, Ref, Ref, AT >::operator std::vector< std::vector< AT >> ( ) const
inlineexplicit

Cast to std::vector<std::vector<AT>>.

Returns
The std::vector<std::vector<AT>> representation of the matrix

◆ operator&=()

template<class AT >
Matrix<General,Ref,Ref,AT>& fmatvec::Matrix< General, Ref, Ref, AT >::operator&= ( Matrix< General, Ref, Ref, AT > &  A)
inline

Reference operator.

References the matrix given by A.

Parameters
AThe matrix to be referenced.
Returns
A reference to the calling matrix.

◆ operator()() [1/5]

template<class AT >
AT& fmatvec::Matrix< General, Ref, Ref, AT >::operator() ( int  i,
int  j 
)
inline

Element operator.

Returns a reference to the element in the i-th row and the j-th column.

Parameters
iThe i-th row of the matrix
jThe j-th column of the matrix
Returns
A reference to the element A(i,j).
Remarks
The bounds are checked in debug mode.
See also
operator()(int,int) const

◆ operator()() [2/5]

template<class AT >
const AT& fmatvec::Matrix< General, Ref, Ref, AT >::operator() ( int  i,
int  j 
) const
inline

Element operator.

See operator()(int,int)

◆ operator()() [3/5]

template<class AT >
AT* fmatvec::Matrix< General, Ref, Ref, AT >::operator() ( )
inline

Pointer operator.

Returns the pointer to the first element.

Returns
The pointer to the first element.

◆ operator()() [4/5]

template<class AT >
const AT* fmatvec::Matrix< General, Ref, Ref, AT >::operator() ( ) const
inline

Pointer operator.

See operator()()

◆ operator()() [5/5]

template<class AT >
const Matrix< General, Ref, Ref, AT > fmatvec::Matrix< General, Ref, Ref, AT >::operator() ( const Range< Var, Var > &  I,
const Range< Var, Var > &  J 
) const
inline

Submatrix operator.

Returns a submatrix of the calling matrix. For example

B = A(Range<Var,Var>(1,2),Range<Var,Var>(2,4));

yields

\[ A=\begin{pmatrix} a_{00} & a_{01} & a_{02} & a_{03} & a_{04}\\ a_{10} & a_{11} & a_{12} & a_{13} & a_{14}\\ a_{20} & a_{21} & a_{22} & a_{23} & a_{24}\\ a_{30} & a_{31} & a_{32} & a_{33} & a_{34} \end{pmatrix}\quad \Rightarrow \quad B=\begin{pmatrix} a_{12} & a_{13} & a_{14}\\ a_{22} & a_{23} & a_{24} \end{pmatrix} \]

Attention
The submatrix and the calling matrix will share the same physical memory.
Parameters
IRange containing the starting and the ending row.
JRange containing the starting and the ending column.
Returns
A submatrix of the calling matrix.

Submatrix operator.

See operator()(const Range<Var,Var>&, const Range<Var,Var>&)

◆ operator<<=()

template<class AT >
template<class Type , class Row , class Col >
Matrix<General,Ref,Ref,AT>& fmatvec::Matrix< General, Ref, Ref, AT >::operator<<= ( const Matrix< Type, Row, Col, AT > &  A)
inline

Matrix assignment.

Copies the matrix given by A.

Parameters
AThe matrix to be copied.
Returns
A reference to the calling matrix.

◆ operator=() [1/2]

template<class AT >
Matrix<General,Ref,Ref,AT>& fmatvec::Matrix< General, Ref, Ref, AT >::operator= ( const Matrix< General, Ref, Ref, AT > &  A)
inline

Assignment operator.

Copies the matrix given by A.

Parameters
AThe matrix to be assigned.
Returns
A reference to the calling matrix.

◆ operator=() [2/2]

template<class AT >
template<class Type , class Row , class Col >
Matrix<General,Ref,Ref,AT>& fmatvec::Matrix< General, Ref, Ref, AT >::operator= ( const Matrix< Type, Row, Col, AT > &  A)
inline

Assignment operator.

Copies the matrix given by A.

Parameters
AThe matrix to be assigned.
Returns
A reference to the calling matrix.

◆ rows()

template<class AT >
int fmatvec::Matrix< General, Ref, Ref, AT >::rows ( ) const
inline

Number of rows.

Returns
The number of rows of the matrix.

◆ T()

template<class AT >
const Matrix<General,Ref,Ref,AT> fmatvec::Matrix< General, Ref, Ref, AT >::T ( ) const

Cast to AT.

Returns
The AT representation of the matrix

AT Constructor. Constructs and initializes a matrix with a AT object.

Parameters
xThe AT the matrix will be initialized with.

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