CVM Class Library  8.1
This C++ class library encapsulates concepts of vector and different matrices including square, band, symmetric and hermitian ones in Euclidean space of real and complex numbers.
 All Classes Files Functions Variables Typedefs Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Matrix< TR, TC > Class Template Reference

Generalized matrix class (not end-user) More...

#include <cvm.h>

Inheritance diagram for Matrix< TR, TC >:
Inheritance graph
[legend]
Collaboration diagram for Matrix< TR, TC >:
Collaboration graph
[legend]

Public Member Functions

tint msize () const
 Number of rows.
tint nsize () const
 Number of columns.
tint ld () const
 Leading dimension.
tint rowofmax () const
 Row with maximum element.
tint rowofmin () const
 Row with minimum element.
tint colofmax () const
 Column with maximum element.
tint colofmin () const
 Column with minimum element.
TR norm1 () const override
 1-norm
TR norminf () const override
 Infinity norm.
- Public Member Functions inherited from basic_array< TR, TC >
 basic_array ()
 Default constructor.
 basic_array (tint nSize, bool bZeroMemory=true)
 Constructor.
 basic_array (TC *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TC *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TC *begin, const TC *end)
 Constructor.
 basic_array (const basic_array &a)
 Copy constructor.
 basic_array (basic_array &&a) noexcept
 Move constructor.
basic_arrayoperator= (const basic_array &a) throw (cvmexception)
 Assignment operator.
basic_arrayoperator= (basic_array &&a) throw (cvmexception)
 Move assignment operator.
virtual ~basic_array ()
 Destructor.
tint size () const
 Size (length) of array.
TC * get ()
 Pointer to data.
const TC * get () const
 Const pointer to data.
 operator TC * ()
 Type cast to pointer to data.
 operator const TC * () const
 Type cast to constant pointer to data.
TC & operator() (tint n) throw (cvmexception)
 Reference to element (l-value)
TC operator() (tint n) const throw (cvmexception)
 Value of element (not l-value)
TC & operator[] (tint n) throw (cvmexception)
 Reference to element (l-value)
TC operator[] (tint n) const throw (cvmexception)
 Value of element (not l-value)
basic_arrayassign (const TC *p)
 Assignment from external array.
basic_arrayset (TC x)
 Sets all elements to one value.
basic_arrayresize (tint nNewSize) throw (cvmexception)
 Changes size of array.
tint incr () const
 Increment between elements.
tint indofmax () const
 Index of element with maximum module.
tint indofmin () const
 Index of element with minimum module.
virtual TR norm () const
 Euclidean norm.
virtual TR norm2 () const
 2-norm
iterator begin ()
 (STL) iterator to begin
const_iterator begin () const
 (STL) const iterator to begin
iterator end ()
 (STL) iterator to end
const_iterator end () const
 (STL) const iterator to end
reverse_iterator rbegin ()
 (STL) iterator to begin reversed
const_reverse_iterator rbegin () const
 (STL) const iterator to begin reversed
reverse_iterator rend ()
 (STL) iterator to end reversed
const_reverse_iterator rend () const
 (STL) const iterator to end reversed
size_type max_size () const
 (STL) maximum possible size of array
size_type capacity () const
 (STL) current capacity of array, equal to size()
bool empty () const
 (STL) is array empty
reference front ()
 (STL) reference to first element
const_reference front () const
 (STL) const reference to first element
reference back ()
 (STL) reference to last element
const_reference back () const
 (STL) const reference to last element
void assign (size_type n, const TC &val) throw (cvmexception)
 (STL) assigns given value to n-th element (0-based)
void assign (const_iterator begin, const_iterator end) throw (cvmexception)
 (STL) assigns begin-end iteartor range to array
void clear ()
 (STL) clears array, dealocates memory and sets size() to zero
void swap (basic_array &v) throw (cvmexception)
 (STL) swaps array values, throws cvmexception if sizes are different
reference at (size_type n) throw (cvmexception)
 (STL) returns reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
const_reference at (size_type n) const throw (cvmexception)
 (STL) returns const reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
void push_back (const TC &x) throw (cvmexception)
 (STL) pushes new value to the end of array
void pop_back () throw (cvmexception)
 (STL) removes last element from array
iterator insert (iterator position, const TC &x) throw (cvmexception)
 (STL) inserts element to given position in array
iterator erase (iterator position) throw (cvmexception)
 (STL) removes element from given position in array

Protected Member Functions

 Matrix ()
 Default constructor.
 Matrix (tint nM, tint nN, tint nLD, bool bZeroMemory)
 Constructor.
 Matrix (TC *pd, tint nM, tint nN, tint nLD, tint nSize)
 Constructor.
 Matrix (const TC *pd, tint nM, tint nN, tint nLD, tint nSize)
 Constructor.
 Matrix (const BaseArray &v, bool bBeColumn)
 Constructor.
 Matrix (Matrix &&m) noexcept
 Move constructor.
Matrixoperator= (Matrix &&m) throw (cvmexception)
 Move assignment operator.

Protected Attributes

tint mm
 Number of rows.
tint mn
 Number of columns.
tint mld
 Leading dimension.
- Protected Attributes inherited from basic_array< TR, TC >
tint msz
 Number of elements of type TC allocated.
tint mincr
 Increment (distance) between elements (default is 1, i.e. elements follow each other)
std::shared_ptr< TC > mp
 native data pointer
TC * mpf
 Foreign data pointer.

Friends

std::ostream & operator<< (std::ostream &os, const Matrix< TR, TC > &mOut)
 Writes Matrix to output stream.
std::istream & operator>> (std::istream &is, Matrix< TR, TC > &mIn)
 Reads Matrix from input stream.

Additional Inherited Members

- Public Types inherited from basic_array< TR, TC >
typedef TC value_type
 STL-specific value type definition.
typedef value_typepointer
 STL-specific value pointer definition.
typedef value_typeiterator
 STL-specific iterator definition.
typedef const value_typeconst_iterator
 STL-specific const iterator definition.
typedef const value_typeconst_pointer
 STL-specific const pointer definition.
typedef value_typereference
 STL-specific reference definition.
typedef const value_typeconst_reference
 STL-specific const reference definition.
typedef size_t size_type
 STL-specific size type definition.
typedef ptrdiff_t difference_type
 STL-specific difference type definition.
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
 STL-specific const reverse iterator definition.
typedef std::reverse_iterator
< iterator
reverse_iterator
 STL-specific reverse iterator definition.

Detailed Description

template<typename TR, typename TC>
class Matrix< TR, TC >

Generalized matrix class (not end-user)

TR type stands for treal, TC type stands for tcomplex. Please use inherited matrix classes. This one provides some member functions which are common for all matrices.

See Also
basic_array

Definition at line 9927 of file cvm.h.

Constructor & Destructor Documentation

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( )
inlineprotected

Default constructor.

Creates empty matrix. No memory gets allocated.

Definition at line 9941 of file cvm.h.

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( tint  nM,
tint  nN,
tint  nLD,
bool  bZeroMemory 
)
inlineprotected

Constructor.

Creates Matrix of nM by nN size with nLD leading dimension. Assigns zero to all elements if bZeroMemory is true.

Parameters
[in]nMNumber of rows.
[in]nNNumber of columns.
[in]nLDLeading dimension.
[in]bZeroMemoryTrue if all elements should be set to zero.

Definition at line 9957 of file cvm.h.

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( TC *  pd,
tint  nM,
tint  nN,
tint  nLD,
tint  nSize 
)
inlineprotected

Constructor.

Creates Matrix of nM by nN size with nLD leading dimension and nSize array size. This is non-const version, it shares memory (shallow copy) with array pointed to by pd parameter.

See Also
http://cvmlib.com/faq.htm
Parameters
[in]pdNon-const pointer to external array.
[in]nMNumber of rows.
[in]nNNumber of columns.
[in]nLDLeading dimension.
[in]nSizeNumber of array elements.

Definition at line 9977 of file cvm.h.

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( const TC *  pd,
tint  nM,
tint  nN,
tint  nLD,
tint  nSize 
)
inlineprotected

Constructor.

Creates Matrix of nM by nN size with nLD leading dimension and nSize array size. This is const version, it allocates memory and copies every element (deep copy) from external array pointed to by pd parameter. It copies nSize elements total.

See Also
http://cvmlib.com/faq.htm
Parameters
[in]pdConst pointer to external array.
[in]nMNumber of rows.
[in]nNNumber of columns.
[in]nLDLeading dimension.
[in]nSizeNumber of array elements.

Definition at line 9998 of file cvm.h.

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( const BaseArray v,
bool  bBeColumn 
)
inlineprotected

Constructor.

Creates Matrix of 1 by N size if bBeColumn is false and N by 1 otherwise. Here N is size of array v passed as the first parameter. Copies all elements of v to the matrix created.

Parameters
[in]vbasic_array to copy elements from.
[in]bBeColumnTrue to create column matrix.

Definition at line 10014 of file cvm.h.

template<typename TR, typename TC>
Matrix< TR, TC >::Matrix ( Matrix< TR, TC > &&  m)
inlineprotected

Move constructor.

Implements move semantics introduced in new C++ standard. Moves data ownership from other matrix to newly created object. It's usually executed implicitly in cases like this:

rvector a(b + c);

or this

rvector a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to newly created object a.

Parameters
[in]mrvalue reference to other matrix.

Definition at line 10040 of file cvm.h.

Member Function Documentation

template<typename TR, typename TC>
Matrix& Matrix< TR, TC >::operator= ( Matrix< TR, TC > &&  m) throw (cvmexception)
inlineprotected

Move assignment operator.

Implements move semantics introduced in new C++ standard. Moves data ownership from other matrix to calling object. It's usually executed implicitly in cases like this:

a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to calling object a.

Parameters
[in]mrvalue reference to other matrix.

Definition at line 10066 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
tint Matrix< TR, TC >::msize ( ) const
inline

Number of rows.

Returns number of rows of calling matrix.

Example:
using namespace cvm;
rmatrix m (100, 200);
std::cout << m.msize() << std::endl;
prints
100
Returns
tint Number of rows.

Definition at line 10092 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
tint Matrix< TR, TC >::nsize ( ) const
inline

Number of columns.

Returns number of columns of calling matrix.

Example:
using namespace cvm;
rmatrix m (100, 200);
std::cout << m.nsize() << std::endl;
prints
200
Returns
tint Number of columns.

Definition at line 10113 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
tint Matrix< TR, TC >::ld ( ) const
inline

Leading dimension.

Returns leading dimension of calling matrix. Leading dimension is equal to number of rows for every matrix except submatrices. For submatrices it's equal to number of rows of parent matrix.

Example:
using namespace cvm;
rmatrix m (100, 200);
srmatrix ms (m, 30, 40, 5); // 5x5 submatrix
std::cout << ms.ld() << std::endl;
prints
100
Returns
tint Leading dimension.

Definition at line 10138 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
tint Matrix< TR, TC >::rowofmax ( ) const
inline

Row with maximum element.

Returns CVM0 based number of calling matrix row where the element with the maximum absolute value is located.

Example:
using namespace cvm;
double a[] = {1., 0., 2., -3., 1., -1.};
rmatrix m (a, 2, 3);
std::cout << m << std::endl << m.rowofmax() << std::endl;
prints
1 2 1
0 -3 -1
2
Returns
tint Row number (CVM0 based).

Definition at line 10165 of file cvm.h.

template<typename TR, typename TC>
tint Matrix< TR, TC >::rowofmin ( ) const
inline

Row with minimum element.

Returns CVM0 based number of calling matrix row where the element with the minimum absolute value is located.

Example:
using namespace cvm;
double a[] = {1., 0., 2., -3., 1., -1.};
rmatrix m (a, 2, 3);
std::cout << m << std::endl << m.rowofmin() << std::endl;
prints
1 2 1
0 -3 -1
2
Returns
tint Row number (CVM0 based).

Definition at line 10192 of file cvm.h.

template<typename TR, typename TC>
tint Matrix< TR, TC >::colofmax ( ) const
inline

Column with maximum element.

Returns CVM0 based number of calling matrix column where the element with the maximum absolute value is located.

Example:
using namespace cvm;
double a[] = {1., 0., 2., -3., 1., -1.};
rmatrix m (a, 2, 3);
std::cout << m << std::endl << m.colofmax() << std::endl;
prints
1 2 1
0 -3 -1
2
Returns
tint Column number (CVM0 based).

Definition at line 10219 of file cvm.h.

template<typename TR, typename TC>
tint Matrix< TR, TC >::colofmin ( ) const
inline

Column with minimum element.

Returns CVM0 based number of calling matrix column where the element with the minimum absolute value is located.

Example:
using namespace cvm;
double a[] = {1., 0., 2., -3., 1., -1.};
rmatrix m (a, 2, 3);
std::cout << m << std::endl << m.colofmin() << std::endl;
prints
1 2 1
0 -3 -1
1
Returns
tint Column number (CVM0 based).

Definition at line 10246 of file cvm.h.

template<typename TR, typename TC>
TR Matrix< TR, TC >::norm1 ( ) const
inlineoverridevirtual

1-norm

1-norm of calling array that for vectors is defined as

\[ {\|x\|}_1=\sum_{i=1}^{n} |x_i| \]

and for matrices as

\[ {\|A\|}_{1}=\max_{j=1,\dots,n} \sum_{i=1}^{m} |a_{ij}|, \]

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norm1 () << std::endl << std::endl;
std::cout << m << m.norm1 () << std::endl;
prints
+1.000000000000e+000 +2.000000000000e+000 +3.000000000000e+000
+6.000000000000e+000
+1.000000000000e+000 +3.000000000000e+000 +5.000000000000e+000
+2.000000000000e+000 -4.000000000000e+000 -6.000000000000e+000
+1.100000000000e+001
Returns
treal Norm value

Reimplemented from basic_array< TR, TC >.

Reimplemented in basic_scbmatrix< TR, TC >, and basic_srbmatrix< TR >.

Definition at line 10250 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
TR Matrix< TR, TC >::norminf ( ) const
inlineoverridevirtual

Infinity norm.

Infinity norm of calling array that for vectors is defined as

\[ {\|x\|}_\infty=\max_{i=1,\dots,n} |x_i| \]

and for matrices as

\[ {\|A\|}_\infty=\max_{i=1,\dots,m} \sum_{j=1}^{n} |a_{ij}|, \]

Example:
using namespace cvm;
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norminf () << std::endl;
std::cout << m << m.norminf () << std::endl;
prints
1 2 3
3
1 3 5
2 -4 -6
12
Returns
treal Norm value

Reimplemented from basic_array< TR, TC >.

Reimplemented in basic_schmatrix< TR, TC >, basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, and basic_srbmatrix< TR >.

Definition at line 10271 of file cvm.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename TR, typename TC>
std::ostream& operator<< ( std::ostream &  os,
const Matrix< TR, TC > &  mOut 
)
friend

Writes Matrix to output stream.

Operator writes matrix (row by row) referenced by parameter mOut into os stream.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
srmatrix m(3);
m(1,1) = 1.;
m(2,3) = 3.;
std::cout << m;
prints
1.00e+00 0.00e+00 0.00e+00
0.00e+00 0.00e+00 3.00e+00
0.00e+00 0.00e+00 0.00e+00
Parameters
[out]osStream to write to.
[in]mOutMatrix to write from.
Returns
Reference to stream for further writing.

Definition at line 1194 of file cvm.h.

template<typename TR, typename TC>
std::istream& operator>> ( std::istream &  is,
Matrix< TR, TC > &  mIn 
)
friend

Reads Matrix from input stream.

Operator fills calling Matrix (row by row) referenced by parameter mIn with numbers from is stream.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
std::ofstream os;
os.open ("in.txt");
os << 1.2 << " " << 2.3 << std::endl << 3.4;
os.close ();
std::ifstream is("in.txt");
rmatrix m(3,2);
is >> m;
std::cout << m;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.20e+000 2.30e+000
3.40e+000 0.00e+000
0.00e+000 0.00e+000
Parameters
[in]isStream to read from.
[out]mInMatrix to write to.
Returns
Reference to stream for further reading.

Definition at line 1151 of file cvm.h.

Member Data Documentation

template<typename TR, typename TC>
tint Matrix< TR, TC >::mm
protected

Number of rows.

Definition at line 9932 of file cvm.h.

template<typename TR, typename TC>
tint Matrix< TR, TC >::mn
protected

Number of columns.

Definition at line 9933 of file cvm.h.

template<typename TR, typename TC>
tint Matrix< TR, TC >::mld
protected

Leading dimension.

Definition at line 9934 of file cvm.h.


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