CppNoddy  0.85
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
CppNoddy::DenseMatrix< _Type > Class Template Reference

A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors. More...

#include <DenseMatrix.h>

Inheritance diagram for CppNoddy::DenseMatrix< _Type >:
CppNoddy::Matrix_base< _Type >

Public Types

typedef std::vector
< DenseVector< _Type >
>::iterator 
row_iter
 Typedef iterator types.
typedef std::vector
< DenseVector< _Type >
>::const_iterator 
row_citer
typedef std::vector
< DenseVector< _Type >
>::reverse_iterator 
row_riter
typedef std::vector
< DenseVector< _Type >
>::const_reverse_iterator 
row_criter
typedef DenseVector< _Type >
::elt_iter 
elt_iter
typedef DenseVector< _Type >
::elt_citer 
elt_citer
typedef DenseVector< _Type >
::elt_riter 
elt_riter
typedef DenseVector< _Type >
::elt_criter 
elt_criter

Public Member Functions

 DenseMatrix ()
 Allow empty construction.
 DenseMatrix (const std::size_t &rows, const std::size_t &cols, const _Type &fill)
 Noddy Matrix constructor with a specified fill data.
 DenseMatrix (const std::size_t &rows, const std::size_t &cols, const _Type *p)
 Construct a Noddy Matrix from a contiguous set of data.
 DenseMatrix (const BandedMatrix< _Type > &source)
 Construct a dense matrix from its banded counterpart.
 DenseMatrix (const DenseMatrix &source)
 Copy constructor.
DenseMatrixoperator= (const DenseMatrix &source)
 Assignment operator.
 ~DenseMatrix ()
const _Type & operator() (const std::size_t &row, const std::size_t &col) const
 Access operator.
_Type & operator() (const std::size_t &row, const std::size_t &col)
 Access operator.
const _Type & get (const std::size_t &row, const std::size_t &col) const
 Access operator.
_Type & set (const std::size_t &row, const std::size_t &col)
 Access operator.
DenseMatrix< _Type > operator* (const double &m) const
 SIMD operator sugar.
DenseMatrix< _Type > operator+ (const DenseMatrix< _Type > &A) const
DenseMatrix< _Type > operator- (const DenseMatrix< _Type > &A) const
std::size_t nrows () const
std::size_t ncols () const
std::size_t nelts () const
void scale (const _Type &mult)
 Scale all matrix elements by a scalar.
void transpose ()
 Transpose the matrix.
double one_norm () const
 Return the maximum one_norm of all rows.
double two_norm () const
 Rreturn the maximum two_norm of all rows.
double inf_norm () const
 Return the maximum inf_norm of all rows.
double frob_norm () const
 Return the sum of the two_norm of all rows.
DenseVector< _Type > multiply (const DenseVector< _Type > &x) const
 Right multiply the matrix by a DENSE vector.
void dump () const
 Output the matrix to std::cout.
void assign (_Type elt)
 Assign a value the matrix so that it has the same geometry, but zero entries in all locations including.
row_iter begin ()
 Pass through of iterator calls.
row_iter end ()
 Pass through of iterator calls.
row_riter rbegin ()
 Pass through of iterator calls.
row_riter rend ()
 Pass through of iterator calls.
row_citer begin () const
 Pass through of iterator calls.
row_citer end () const
 Pass through of iterator calls.
row_criter rbegin () const
 Pass through of iterator calls.
row_criter rend () const
 Pass through of iterator calls.
DenseVector< _Type > & operator[] (const std::size_t &row)
 Operator overloading for ROW access.
const DenseVector< _Type > & operator[] (const std::size_t &row) const
 Operator overloading for ROW access.
void add (const DenseMatrix< _Type > &b)
 Add a DENSE matrix to this object.
void sub (const DenseMatrix< _Type > &b)
 Subtract a DENSE matrix from this object.
DenseMatrix< _Type > multiply (const DenseMatrix< _Type > &b) const
 Right-multiply by a DENSE matrix and return the result.
void set_col (const std::size_t &col, const DenseVector< _Type > &x)
 Set a column of the matrix.
DenseVector< _Type > get_col (const std::size_t &col) const
 Get a column of the matrix.
DenseVector< double > matrix_to_vector (const std::size_t &padding=0) const
 Conversion to contiguous data in row major format Inefficient ...
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding=0) const
 Conversion to contiguous data in row major format.
row_iter max_in_col (const std::size_t &col, row_iter row_min, row_iter row_max) const
 Find the maximum abs value in a column.
template<>
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding) const
template<>
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding) const
template<>
DenseVector< double > matrix_to_vector (const std::size_t &padding) const
template<>
DenseVector< double > matrix_to_vector (const std::size_t &padding) const
- Public Member Functions inherited from CppNoddy::Matrix_base< _Type >
 Matrix_base ()
 An empty constructor.
virtual ~Matrix_base ()

Detailed Description

template<typename _Type>
class CppNoddy::DenseMatrix< _Type >

A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.

This is generally a nice way to implement the matrix, but the data elements [i][j] are not necessarily in contiguous row_major format in memory because there is a system dependent padding at the end of each row vector. Thus, in general, &[i][j+1] - &[i][j] != &[i][0] - &[i-1][Nc] .. ie. the step may be larger from the end of row i-1 to the start of row i. Typically, the data must be copied into contiguous memory for use in external libraries that take base pointers & assume uniform steps between elements.

Definition at line 27 of file DenseMatrix.h.

Member Typedef Documentation

template<typename _Type>
typedef DenseVector<_Type>::elt_citer CppNoddy::DenseMatrix< _Type >::elt_citer

Definition at line 37 of file DenseMatrix.h.

template<typename _Type>
typedef DenseVector<_Type>::elt_criter CppNoddy::DenseMatrix< _Type >::elt_criter

Definition at line 39 of file DenseMatrix.h.

template<typename _Type>
typedef DenseVector<_Type>::elt_iter CppNoddy::DenseMatrix< _Type >::elt_iter

Definition at line 36 of file DenseMatrix.h.

template<typename _Type>
typedef DenseVector<_Type>::elt_riter CppNoddy::DenseMatrix< _Type >::elt_riter

Definition at line 38 of file DenseMatrix.h.

template<typename _Type>
typedef std::vector<DenseVector<_Type> >::const_iterator CppNoddy::DenseMatrix< _Type >::row_citer

Definition at line 33 of file DenseMatrix.h.

template<typename _Type>
typedef std::vector<DenseVector<_Type> >::const_reverse_iterator CppNoddy::DenseMatrix< _Type >::row_criter

Definition at line 35 of file DenseMatrix.h.

template<typename _Type>
typedef std::vector<DenseVector<_Type> >::iterator CppNoddy::DenseMatrix< _Type >::row_iter

Typedef iterator types.

Definition at line 32 of file DenseMatrix.h.

template<typename _Type>
typedef std::vector<DenseVector<_Type> >::reverse_iterator CppNoddy::DenseMatrix< _Type >::row_riter

Definition at line 34 of file DenseMatrix.h.

Constructor & Destructor Documentation

template<typename _Type >
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( )

Allow empty construction.

Definition at line 19 of file DenseMatrix.cpp.

: Matrix_base<_Type>(), NR( 0 ), NC( 0 )
{}
template<typename _Type>
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( const std::size_t &  rows,
const std::size_t &  cols,
const _Type &  fill 
)

Noddy Matrix constructor with a specified fill data.

Parameters
rowsThe number of rows in the matrix.
colsThe number of columns in the matrix.
fillThe entry to be placed in all elements.

Definition at line 23 of file DenseMatrix.cpp.

:
Matrix_base<_Type>(),
NR( rows ),
NC( cols )
{
// make a row
const DenseVector<_Type> row( cols, fill );
// reserve the space
MATRIX.reserve( rows );
for ( std::size_t i = 0; i < rows; ++i )
{
// push require number of rows into the 'matrix'
MATRIX.push_back( row );
}
}
template<typename _Type>
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( const std::size_t &  rows,
const std::size_t &  cols,
const _Type *  p 
)

Construct a Noddy Matrix from a contiguous set of data.

This will be nasty if you pass the wrong pointer, but is useful in interfacing with external libraries. This assumes the contiguous data is in row_major format.

Parameters
rowsThe number of rows in the matrix.
colsThe number of columns in the matrix.
pA pointer to the start of the data.

Definition at line 42 of file DenseMatrix.cpp.

:
Matrix_base<_Type>(),
NR( rows ),
NC( cols )
{
MATRIX.reserve( rows );
for ( std::size_t i = 0; i < rows; ++i )
{
MATRIX.push_back( DenseVector<_Type>( cols, &p[ i * cols ] ) );
}
}
template<typename _Type>
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( const BandedMatrix< _Type > &  source)
inline

Construct a dense matrix from its banded counterpart.

Parameters
sourceThe banded matrix to be used in the construction.

Definition at line 65 of file DenseMatrix.h.

{
// get the number of off diagonal elts
int l = source.noffdiag();
// banded matrix class is always square
int n = source.nrows();
for ( int row = 0; row < n; ++row )
{
DenseVector<_Type> vecrow( n, 0.0 );
for ( int col = std::max( row - l, 0 );
col < std::min( n, row + l + 1 );
++col )
{
vecrow[ col ] = source( row, col );
}
MATRIX.push_back( vecrow );
}
NR = NC = n;
}
template<typename _Type>
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( const DenseMatrix< _Type > &  source)

Copy constructor.

Parameters
sourceThe source object to be copied

Definition at line 57 of file DenseMatrix.cpp.

References CppNoddy::Example::source().

:
Matrix_base<_Type>( source )
{
*this = source;
}
template<typename _Type >
CppNoddy::DenseMatrix< _Type >::~DenseMatrix ( )

Definition at line 64 of file DenseMatrix.cpp.

{}

Member Function Documentation

template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::add ( const DenseMatrix< _Type > &  b)

Add a DENSE matrix to this object.

Parameters
bThe DENSE matrix to add to 'this'

Definition at line 85 of file DenseMatrix.cpp.

References CppNoddy::DenseMatrix< _Type >::ncols(), and CppNoddy::DenseMatrix< _Type >::nrows().

Referenced by main().

{
#ifdef PARANOID
// check number of columns at least match
if ( ( B.nrows() != NR ) || ( B.ncols() != NC ) )
{
std::string problem( "The DenseMatrix.add has a geometry error.\n" );
throw ExceptionGeom( problem, NR, NC, B.nrows(), B.ncols() );
}
#endif
std::transform( MATRIX.begin(), MATRIX.end(), B.MATRIX.begin(), MATRIX.begin(), std::plus< DenseVector<_Type> >() );
}
template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::assign ( _Type  elt)
inline

Assign a value the matrix so that it has the same geometry, but zero entries in all locations including.

Parameters
eltThe value to be assigned to all entries

Definition at line 180 of file DenseMatrix.h.

{
MATRIX.assign( MATRIX.size(), DenseVector<_Type>( NC, elt ) );
}
template<typename _Type>
row_iter CppNoddy::DenseMatrix< _Type >::begin ( )
inline

Pass through of iterator calls.

Returns
Iterator to the begin row

Definition at line 187 of file DenseMatrix.h.

{
return MATRIX.begin();
}
template<typename _Type>
row_citer CppNoddy::DenseMatrix< _Type >::begin ( ) const
inline

Pass through of iterator calls.

Returns
Const iterator to the begin row

Definition at line 215 of file DenseMatrix.h.

{
return MATRIX.begin();
}
template<typename _Type >
void CppNoddy::DenseMatrix< _Type >::dump ( ) const
virtual

Output the matrix to std::cout.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 263 of file DenseMatrix.cpp.

{
std::cout << "DENSE mtx size = " << nrows() << " x " << ncols() << "; \n";
std::cout.precision( 4 );
std::cout << "- start matrix \n";
for ( std::size_t i = 0; i < nrows(); ++i )
{
std::cout << " row " << i << " = ";
for ( std::size_t j = 0; j < ncols(); ++j )
{
std::cout << MATRIX[ i ][ j ] << ", ";
}
std::cout << "\n";
}
std::cout << "- end matrix \n";
}
template<typename _Type>
row_iter CppNoddy::DenseMatrix< _Type >::end ( )
inline

Pass through of iterator calls.

Returns
Iterator to the end row

Definition at line 194 of file DenseMatrix.h.

{
return MATRIX.end();
}
template<typename _Type>
row_citer CppNoddy::DenseMatrix< _Type >::end ( ) const
inline

Pass through of iterator calls.

Returns
Const iterator to the end row

Definition at line 222 of file DenseMatrix.h.

{
return MATRIX.end();
}
template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::frob_norm ( ) const
virtual

Return the sum of the two_norm of all rows.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 251 of file DenseMatrix.cpp.

Referenced by main().

{
double sum ( 0.0 );
for ( std::size_t row = 0; row < NR; ++row )
{
sum += MATRIX[ row ].two_norm();
}
return sum;
}
template<typename _Type >
const _Type & CppNoddy::DenseMatrix< _Type >::get ( const std::size_t &  row,
const std::size_t &  col 
) const
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 348 of file DenseMatrix.h.

Referenced by main().

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.get has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
if ( ( col > NC ) || ( col < 0 ) )
{
std::string problem( "The DenseMatrix.get has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
#endif
return MATRIX[ row ][ col ];
}
template<typename _Type >
DenseVector< _Type > CppNoddy::DenseMatrix< _Type >::get_col ( const std::size_t &  col) const

Get a column of the matrix.

Parameters
colThe column to get
Returns
A DENSE vector of the column of data

Definition at line 290 of file DenseMatrix.cpp.

Referenced by CppNoddy::DenseMatrix< _Type >::multiply().

{
DenseVector<_Type> X( NR, 0.0 );
for ( std::size_t row = 0; row < NR; ++row )
{
X[ row ] = MATRIX[ row ][ col ];
}
return X;
}
template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::inf_norm ( ) const
virtual

Return the maximum inf_norm of all rows.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 240 of file DenseMatrix.cpp.

Referenced by main().

{
double max( 0.0 );
for ( std::size_t row = 0; row < NR; ++row )
{
max = std::max( max, MATRIX[ row ].inf_norm() );
}
return max;
}
template<typename _Type>
DenseVector<double> CppNoddy::DenseMatrix< _Type >::matrix_to_vector ( const std::size_t &  padding = 0) const

Conversion to contiguous data in row major format Inefficient ...

the void method is preferred

Parameters
paddingAn integer padding hack
Returns
A DENSE vector containing the matrix

Referenced by CppNoddy::FortranData::FortranData().

template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding = 0 
) const

Conversion to contiguous data in row major format.

Parameters
paddingAn integer padding hack
pA DENSE vector containing the matrix
template<>
void CppNoddy::DenseMatrix< std::complex< double > >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding 
) const

Definition at line 301 of file DenseMatrix.cpp.

References CppNoddy::Utility::imag(), CppNoddy::DenseVector< _Type >::push_back(), CppNoddy::Utility::real(), and CppNoddy::DenseVector< _Type >::reserve().

{
p.reserve( 2 * NR * NC );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
p.push_back( MATRIX[ row ][ col ].real() );
p.push_back( MATRIX[ row ][ col ].imag() );
}
for ( std::size_t col = 0; col < padding; ++col )
{
p.push_back( 0.0 );
p.push_back( 0.0 );
}
}
}
template<>
void CppNoddy::DenseMatrix< double >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding 
) const

Definition at line 321 of file DenseMatrix.cpp.

References CppNoddy::DenseVector< _Type >::push_back(), and CppNoddy::DenseVector< _Type >::reserve().

{
p.reserve( NR * NC );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
p.push_back( MATRIX[ row ][ col ] );
}
for ( std::size_t col = 0; col < padding; ++col )
{
p.push_back( 0.0 );
}
}
}
template<>
DenseVector< double > CppNoddy::DenseMatrix< double >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 338 of file DenseMatrix.cpp.

References CppNoddy::DenseVector< _Type >::push_back(), CppNoddy::DenseVector< _Type >::reserve(), and V.

{
DenseVector<double> V;
V.reserve( NR * NC );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
V.push_back( MATRIX[ row ][ col ] );
}
for ( std::size_t col = 0; col < padding; ++col )
{
V.push_back( 0.0 );
}
}
return V;
}
template<>
DenseVector< double > CppNoddy::DenseMatrix< std::complex< double > >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 357 of file DenseMatrix.cpp.

References CppNoddy::Utility::imag(), CppNoddy::DenseVector< _Type >::push_back(), CppNoddy::Utility::real(), CppNoddy::DenseVector< _Type >::reserve(), and V.

{
DenseVector<double> V;
V.reserve( 2 * NR * NC );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
V.push_back( MATRIX[ row ][ col ].real() );
V.push_back( MATRIX[ row ][ col ].imag() );
}
for ( std::size_t col = 0; col < padding; ++col )
{
V.push_back( 0.0 );
V.push_back( 0.0 );
}
}
return V;
}
template<typename _Type >
std::vector< DenseVector< _Type > >::iterator CppNoddy::DenseMatrix< _Type >::max_in_col ( const std::size_t &  col,
row_iter  row_min,
row_iter  row_max 
) const

Find the maximum abs value in a column.

Parameters
colThe column offset to search through
row_minIterator to the begin row
row_maxIterator to final row (NOT INCLUSIVE)
Returns
An iterator to the row that contains the maximum value

Definition at line 200 of file DenseMatrix.cpp.

{
row_iter index( row_min );
double maxelt( std::abs( *( row_min -> begin() ) ) );
for ( row_iter row = row_min + 1; row != row_max ; ++row )
{
const double elt( std::abs( *( row -> begin() + col ) ) );
if ( elt >= maxelt )
{
maxelt = elt;
index = row;
}
}
return index;
}
template<typename _Type>
DenseVector< _Type > CppNoddy::DenseMatrix< _Type >::multiply ( const DenseVector< _Type > &  x) const
virtual

Right multiply the matrix by a DENSE vector.

Parameters
xThe DENSE vector to be multiplied
Returns
The DENSE vector of the multiplication

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 155 of file DenseMatrix.cpp.

References CppNoddy::Utility::dot(), CppNoddy::DenseVector< _Type >::push_back(), CppNoddy::DenseVector< _Type >::reserve(), and CppNoddy::DenseVector< _Type >::size().

Referenced by CppNoddy::OneD_TVDLF_Elt::contributed_flux_in_left(), CppNoddy::OneD_TVDLF_Elt::contributed_flux_out_right(), CppNoddy::TwoD_TVDLF_Elt::get_Q_Taylor_series(), and main().

{
#ifdef PARANOID
// check number of columns at least match
if ( X.size() != NC )
{
std::string problem( "The DenseMatrix.multiply has a geometry error.\n" );
throw ExceptionGeom( problem, NR, NC, X.size(), 1 );
}
#endif
DenseVector<_Type> temp;
temp.reserve( NR );
for ( std::size_t row = 0; row < NR; ++row )
{
temp.push_back( Utility::dot( MATRIX[ row ], X ) );
}
return temp;
}
template<typename _Type>
DenseMatrix< _Type > CppNoddy::DenseMatrix< _Type >::multiply ( const DenseMatrix< _Type > &  b) const

Right-multiply by a DENSE matrix and return the result.

Parameters
bThe matrix to right-multiply by
Returns
The matrix result of the multiplication

Definition at line 175 of file DenseMatrix.cpp.

References CppNoddy::DenseMatrix< _Type >::get_col(), CppNoddy::Utility::multiply(), CppNoddy::DenseMatrix< _Type >::ncols(), CppNoddy::DenseMatrix< _Type >::nrows(), and CppNoddy::DenseMatrix< _Type >::set_col().

{
#ifdef PARANOID
// check number of columns at least match
if ( B.nrows() != NC )
{
std::string problem( "The DenseMatrix.multiply has a geometry error.\n" );
throw ExceptionGeom( problem, NR, NC, B.nrows(), B.ncols() );
}
#endif
// temporary object for the result
DenseMatrix<_Type> C( nrows(), B.ncols(), 0.0 );
// loops thru the columns in the B matrix
for ( std::size_t col_in_B = 0; col_in_B < B.ncols(); ++col_in_B )
{
// set the column in the result to be the matrix-vector
// product of (*this).multiply( column in B )
C.set_col( col_in_B , multiply( B.get_col( col_in_B ) ) );
}
return C;
}
template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::ncols ( ) const
inlinevirtual
Returns
The number of columns

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 419 of file DenseMatrix.h.

Referenced by CppNoddy::DenseMatrix< _Type >::add(), CppNoddy::Utility::fill_random(), CppNoddy::Utility::fill_row(), CppNoddy::DenseMatrix< _Type >::multiply(), CppNoddy::Utility::multiply(), CppNoddy::DenseMatrix< _Type >::sub(), CppNoddy::Utility::vels_from_streamfn_Cartesian(), and CppNoddy::Utility::vels_from_streamfn_Stokes().

{
return NC;
}
template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::nelts ( ) const
virtual
Returns
The number of elements

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 79 of file DenseMatrix.cpp.

{
return NR * NC;
}
template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::nrows ( ) const
inlinevirtual
Returns
The number of rows

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 413 of file DenseMatrix.h.

Referenced by CppNoddy::DenseMatrix< _Type >::add(), CppNoddy::Utility::fill(), CppNoddy::Utility::fill_random(), CppNoddy::DenseMatrix< _Type >::multiply(), CppNoddy::Utility::multiply(), CppNoddy::DenseMatrix< _Type >::sub(), CppNoddy::Utility::vels_from_streamfn_Cartesian(), and CppNoddy::Utility::vels_from_streamfn_Stokes().

{
return NR;
}
template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::one_norm ( ) const
virtual

Return the maximum one_norm of all rows.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 218 of file DenseMatrix.cpp.

Referenced by main().

{
double max( 0.0 );
for ( std::size_t row = 0; row < NR; ++row )
{
max = std::max( max, MATRIX[ row ].one_norm() );
}
return max;
}
template<typename _Type >
const _Type & CppNoddy::DenseMatrix< _Type >::operator() ( const std::size_t &  row,
const std::size_t &  col 
) const
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 309 of file DenseMatrix.h.

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.() has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
if ( ( col > NC ) || ( col < 0 ) )
{
std::string problem( "The DenseMatrix.() has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
#endif
return MATRIX[ row ][ col ];
}
template<typename _Type >
_Type & CppNoddy::DenseMatrix< _Type >::operator() ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 328 of file DenseMatrix.h.

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.() has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
if ( ( col > NC ) || ( col < 0 ) )
{
std::string problem( "The DenseMatrix.() has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
#endif
return MATRIX[ row ][ col ];
}
template<typename _Type>
DenseMatrix<_Type> CppNoddy::DenseMatrix< _Type >::operator* ( const double &  m) const
inline

SIMD operator sugar.

Definition at line 107 of file DenseMatrix.h.

{
DenseMatrix<_Type> temp( *this );
temp.scale( m );
return temp;
}
template<typename _Type>
DenseMatrix<_Type> CppNoddy::DenseMatrix< _Type >::operator+ ( const DenseMatrix< _Type > &  A) const
inline

Definition at line 113 of file DenseMatrix.h.

{
DenseMatrix<_Type> temp( *this );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
temp( row, col ) += A( row, col );
}
}
return temp;
}
template<typename _Type>
DenseMatrix<_Type> CppNoddy::DenseMatrix< _Type >::operator- ( const DenseMatrix< _Type > &  A) const
inline

Definition at line 125 of file DenseMatrix.h.

{
DenseMatrix<_Type> temp( *this );
for ( std::size_t row = 0; row < NR; ++row )
{
for ( std::size_t col = 0; col < NC; ++col )
{
temp( row, col ) -= A( row, col );
}
}
return temp;
}
template<typename _Type >
DenseMatrix< _Type > & CppNoddy::DenseMatrix< _Type >::operator= ( const DenseMatrix< _Type > &  source)
inline

Assignment operator.

Parameters
sourceThe source object for the assignment
Returns
The newly assigned object

Definition at line 68 of file DenseMatrix.cpp.

{
if ( this == &source )
return * this;
MATRIX = source.MATRIX;
NR = source.NR;
NC = source.NC;
return *this;
}
template<typename _Type >
DenseVector< _Type > & CppNoddy::DenseMatrix< _Type >::operator[] ( const std::size_t &  row)
inline

Operator overloading for ROW access.

Parameters
rowThe row to access
Returns
The DENSE vector of the row data

Definition at line 387 of file DenseMatrix.h.

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.get_row has a range error.\n" );
throw ExceptionRange( problem, NR, row );
}
#endif
return MATRIX[ row ];
}
template<typename _Type >
const DenseVector< _Type > & CppNoddy::DenseMatrix< _Type >::operator[] ( const std::size_t &  row) const
inline

Operator overloading for ROW access.

Parameters
rowThe row to access
Returns
The DENSE vector of the row data

Definition at line 400 of file DenseMatrix.h.

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.get_row has a range error.\n" );
throw ExceptionRange( problem, NR, row );
}
#endif
return MATRIX[ row ];
}
template<typename _Type>
row_riter CppNoddy::DenseMatrix< _Type >::rbegin ( )
inline

Pass through of iterator calls.

Returns
Reverse iterator to the begin row

Definition at line 201 of file DenseMatrix.h.

{
return MATRIX.rbegin();
}
template<typename _Type>
row_criter CppNoddy::DenseMatrix< _Type >::rbegin ( ) const
inline

Pass through of iterator calls.

Returns
Const reverse iterator to the begin row

Definition at line 229 of file DenseMatrix.h.

{
return MATRIX.rbegin();
}
template<typename _Type>
row_riter CppNoddy::DenseMatrix< _Type >::rend ( )
inline

Pass through of iterator calls.

Returns
Reverse iterator to the end row

Definition at line 208 of file DenseMatrix.h.

{
return MATRIX.rend();
}
template<typename _Type>
row_criter CppNoddy::DenseMatrix< _Type >::rend ( ) const
inline

Pass through of iterator calls.

Returns
Const reverse iterator to the end row

Definition at line 236 of file DenseMatrix.h.

{
return MATRIX.rend();
}
template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::scale ( const _Type &  mult)
virtual

Scale all matrix elements by a scalar.

Parameters
multThe scalar multiplier

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 113 of file DenseMatrix.cpp.

Referenced by CppNoddy::Equation_1matrix< _Type, _Xtype >::get_jacobian_of_matrix0_mult_vector(), CppNoddy::Equation_2matrix< _Type, _Xtype >::get_jacobian_of_matrix1_mult_vector(), CppNoddy::Equation_3matrix< _Type, _Xtype >::get_jacobian_of_matrix2_mult_vector(), main(), and CppNoddy::DenseMatrix< D_complex >::operator*().

{
std::transform( MATRIX.begin(), MATRIX.end(), MATRIX.begin(), scale_functor< DenseVector<_Type>, _Type >( mult ) );
}
template<typename _Type >
_Type & CppNoddy::DenseMatrix< _Type >::set ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 368 of file DenseMatrix.h.

Referenced by main().

{
#ifdef PARANOID
if ( ( row > NR ) || ( row < 0 ) )
{
std::string problem( "The DenseMatrix.set has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
if ( ( col > NC ) || ( col < 0 ) )
{
std::string problem( "The DenseMatrix.set has a range error.\n" );
throw ExceptionRange( problem, NR, row, NC, col );
}
#endif
return MATRIX[ row ][ col ];
}
template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::set_col ( const std::size_t &  col,
const DenseVector< _Type > &  x 
)

Set a column of the matrix.

Parameters
colThe column to be set
xThe DENSE vector of column information

Definition at line 281 of file DenseMatrix.cpp.

Referenced by CppNoddy::OneD_Hyperbolic_System::Jac_flux_fn(), CppNoddy::TwoD_Hyperbolic_System::Jac_flux_fn_x(), CppNoddy::TwoD_Hyperbolic_System::Jac_flux_fn_y(), CppNoddy::Residual< _Type >::jacobian(), and CppNoddy::DenseMatrix< _Type >::multiply().

{
for ( std::size_t row = 0; row < NR; ++row )
{
MATRIX[ row ][ col ] = X[ row ];
}
}
template<typename _Type>
void CppNoddy::DenseMatrix< _Type >::sub ( const DenseMatrix< _Type > &  b)

Subtract a DENSE matrix from this object.

Parameters
bThe DENSE matrix to subtract from 'this'

Definition at line 99 of file DenseMatrix.cpp.

References CppNoddy::DenseMatrix< _Type >::ncols(), and CppNoddy::DenseMatrix< _Type >::nrows().

Referenced by CppNoddy::Equation_1matrix< _Type, _Xtype >::get_jacobian_of_matrix0_mult_vector(), CppNoddy::Equation_2matrix< _Type, _Xtype >::get_jacobian_of_matrix1_mult_vector(), CppNoddy::Equation_3matrix< _Type, _Xtype >::get_jacobian_of_matrix2_mult_vector(), and main().

{
#ifdef PARANOID
// check number of columns at least match
if ( ( B.nrows() != NR ) || ( B.ncols() != NC ) )
{
std::string problem( "The DenseMatrix.sub has a geometry error.\n" );
throw ExceptionGeom( problem, NR, NC, B.nrows(), B.ncols() );
}
#endif
std::transform( MATRIX.begin(), MATRIX.end(), B.MATRIX.begin(), MATRIX.begin(), std::minus< DenseVector<_Type> >() );
}
template<typename _Type >
void CppNoddy::DenseMatrix< _Type >::transpose ( )
virtual

Transpose the matrix.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 119 of file DenseMatrix.cpp.

Referenced by CppNoddy::FortranData::FortranData().

{
if ( nrows() == ncols() )
{
// square matrix needs no temp object
// loop through upper half diagonal of the matrix
for ( std::size_t i = 0; i < nrows(); ++i )
{
for ( std::size_t j = i + 1; j < ncols(); ++j )
{
// swap elements
std::swap( MATRIX[ i ][ j ], MATRIX[ j ][ i ] );
}
}
}
else
{
std::vector< DenseVector<_Type> > temp;
temp.resize( NC );
for ( std::size_t row = 0; row < NC; ++row )
{
temp[ row ].resize( NR );
}
for ( std::size_t i = 0; i < nrows(); ++i )
{
for ( std::size_t j = 0; j < ncols(); ++j )
{
temp[ j ][ i ] = MATRIX[ i ][ j ];
}
}
MATRIX = temp;
std::swap( NR, NC );
}
}
template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::two_norm ( ) const
virtual

Rreturn the maximum two_norm of all rows.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 229 of file DenseMatrix.cpp.

Referenced by main().

{
double max( 0.0 );
for ( std::size_t row = 0; row < NR; ++row )
{
max = std::max( max, MATRIX[ row ].two_norm() );
}
return max;
}

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

© 2012

R.E. Hewitt