My Project
Loading...
Searching...
No Matches
TNT::Matrix< T > Class Template Reference

#include <tnt_matrix.h>

Public Types

typedef Subscript size_type
 
typedef T value_type
 
typedef T element_type
 
typedef T * pointer
 
typedef T * iterator
 
typedef T & reference
 
typedef const T * const_iterator
 
typedef const T & const_reference
 

Public Member Functions

Subscript lbound () const
 
 operator T** ()
 
 operator const T ** () const
 
Subscript size () const
 
 Matrix (const Matrix< T > &A)
 
 Matrix (Subscript M, Subscript N, const T &value=T(0))
 
 Matrix (Subscript M, Subscript N, const T *v)
 
 Matrix (Subscript M, Subscript N, const char *s)
 
Matrix< T > & newsize (Subscript M, Subscript N)
 
Matrix< T > & operator= (const Matrix< T > &B)
 
Matrix< T > & operator= (const T &scalar)
 
Subscript dim (Subscript d) const
 
Subscript num_rows () const
 
Subscript num_cols () const
 
T * operator[] (Subscript i)
 
const T * operator[] (Subscript i) const
 
reference operator() (Subscript i)
 
const_reference operator() (Subscript i) const
 
reference operator() (Subscript i, Subscript j)
 
const_reference operator() (Subscript i, Subscript j) const
 
Vector< T > diag () const
 
Matrix< T > upper_triangular () const
 
Matrix< T > lower_triangular () const
 

Detailed Description

template<class T>
class TNT::Matrix< T >

Dense matrix class for basic linear algebra operations.

Ordering: row major.

Elements begin at (1,1) or [0][0].

Can be interfaced with C multidimentionsal arrays (e.g. double **)

copy-by-value semantics.

Optional range checking at compile time via TNT_BOUNDS_CHECK macro.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

template<class T >
TNT::Matrix< T >::Matrix ( Subscript M,
Subscript N,
const T & value = T(0) )
inline

Create a MxN matrix, with each element assigned to the value 0.

Parameters
Mthe number of rows
Nthe number of columns
value(optional default value: 0 if not specified.

◆ Matrix() [2/3]

template<class T >
TNT::Matrix< T >::Matrix ( Subscript M,
Subscript N,
const T * v )
inline

Create an MxN matrix, filling in values (row-major order) from the list (C array) provided.

Parameters
Mthe number of rows
Nthe number of columns
vlist (C array) of M*N values used to initialize matrix.

◆ Matrix() [3/3]

template<class T >
TNT::Matrix< T >::Matrix ( Subscript M,
Subscript N,
const char * s )
inline

Create an MxN matrix, filling in values (row-major order) from a character string.

Parameters
Mthe number of rows
Nthe number of columns
sstring of M*N values used to initialize matrix.

Member Function Documentation

◆ newsize()

template<class T >
Matrix< T > & TNT::Matrix< T >::newsize ( Subscript M,
Subscript N )
inline

Change size of matrix to MxN, reallocating memory if necessary.

NOTE: This operations occurs in place, i.e. when resizing to a new matrix, original matrix elements are NOT retained. Instead, one must explicit create a new matrix of this size and manually copy the elements, e.g.


Matrix double B(M, N);

int     min_M = M < A.num_rows() ? M : A.num_rows();
int     min_N = N < A.num_cols() ? N : A.num_cols();
for (int i=1; i<=min_M; i++)
    for (int j=1; j<=min_N; j++)
        B(i,j) = A(i,j);

A.destroy();
Parameters
Mthe number of rows of new size.
Nthe number of columns of new size.

◆ operator=()

template<class T >
Matrix< T > & TNT::Matrix< T >::operator= ( const Matrix< T > & B)
inline

Assign (copy) one matrix to another, e.g. A=B. The contents of A are lost, and a new copy of B is created.

Parameters
Bto matrix to be copied.

◆ size()

template<class T >
Subscript TNT::Matrix< T >::size ( ) const
inline
Returns
the total number of items in matrix (M*N).

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