CppNoddy  0.90
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. More...
 
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. More...
 
 DenseMatrix (const std::size_t &rows, const std::size_t &cols, const _Type &fill)
 Noddy Matrix constructor with a specified fill data. More...
 
 DenseMatrix (const std::size_t &rows, const std::size_t &cols, const _Type *p)
 Construct a Noddy Matrix from a contiguous set of data. More...
 
 DenseMatrix (const BandedMatrix< _Type > &source)
 Construct a dense matrix from its banded counterpart. More...
 
 DenseMatrix (const DenseMatrix &source)
 Copy constructor. More...
 
DenseMatrixoperator= (const DenseMatrix &source)
 Assignment operator. More...
 
 ~DenseMatrix ()
 
const _Type & operator() (const std::size_t &row, const std::size_t &col) const
 Access operator. More...
 
_Type & operator() (const std::size_t &row, const std::size_t &col)
 Access operator. More...
 
const _Type & get (const std::size_t &row, const std::size_t &col) const
 Access operator. More...
 
_Type & set (const std::size_t &row, const std::size_t &col)
 Access operator. More...
 
DenseMatrix< _Type > operator* (const double &m) const
 SIMD operator sugar. More...
 
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. More...
 
void transpose ()
 Transpose the matrix. More...
 
double one_norm () const
 Return the maximum one_norm of all rows. More...
 
double two_norm () const
 Rreturn the maximum two_norm of all rows. More...
 
double inf_norm () const
 Return the maximum inf_norm of all rows. More...
 
double frob_norm () const
 Return the sum of the two_norm of all rows. More...
 
DenseVector< _Type > multiply (const DenseVector< _Type > &x) const
 Right multiply the matrix by a DENSE vector. More...
 
void dump () const
 Output the matrix to std::cout. More...
 
void assign (_Type elt)
 Assign a value to the matrix but keep the same geometry. More...
 
row_iter begin ()
 Pass through of iterator calls. More...
 
row_iter end ()
 Pass through of iterator calls. More...
 
row_riter rbegin ()
 Pass through of iterator calls. More...
 
row_riter rend ()
 Pass through of iterator calls. More...
 
row_citer begin () const
 Pass through of iterator calls. More...
 
row_citer end () const
 Pass through of iterator calls. More...
 
row_criter rbegin () const
 Pass through of iterator calls. More...
 
row_criter rend () const
 Pass through of iterator calls. More...
 
DenseVector< _Type > & operator[] (const std::size_t &row)
 Operator overloading for ROW access. More...
 
const DenseVector< _Type > & operator[] (const std::size_t &row) const
 Operator overloading for ROW access. More...
 
void add (const DenseMatrix< _Type > &b)
 Add a DENSE matrix to this object. More...
 
void sub (const DenseMatrix< _Type > &b)
 Subtract a DENSE matrix from this object. More...
 
DenseMatrix< _Type > multiply (const DenseMatrix< _Type > &b) const
 Right-multiply by a DENSE matrix and return the result. More...
 
void set_col (const std::size_t &col, const DenseVector< _Type > &x)
 Set a column of the matrix. More...
 
DenseVector< _Type > get_col (const std::size_t &col) const
 Get a column of the matrix. More...
 
DenseVector< double > matrix_to_vector (const std::size_t &padding=0) const
 Conversion to contiguous data in row major format Inefficient ... More...
 
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding=0) const
 Conversion to contiguous data in row major format. More...
 
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. More...
 
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. More...
 
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.

Referenced by CppNoddy::DenseMatrix< D_complex >::DenseMatrix().

19  : Matrix_base<_Type>(), NR( 0 ), NC( 0 )
20  {}
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.

25  :
26  Matrix_base<_Type>(),
27  NR( rows ),
28  NC( cols )
29  {
30  // make a row
31  const DenseVector<_Type> row( cols, fill );
32  // reserve the space
33  MATRIX.reserve( rows );
34  for ( std::size_t i = 0; i < rows; ++i )
35  {
36  // push require number of rows into the 'matrix'
37  MATRIX.push_back( row );
38  }
39  }
void fill(BandedMatrix< _Type > &A, const _Type &value)
Set all elements of a specified BANDED matrix.
Definition: Utility.h:89
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.

44  :
45  Matrix_base<_Type>(),
46  NR( rows ),
47  NC( cols )
48  {
49  MATRIX.reserve( rows );
50  for ( std::size_t i = 0; i < rows; ++i )
51  {
52  MATRIX.push_back( DenseVector<_Type>( cols, &p[ i * cols ] ) );
53  }
54  }
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.

66  {
67  // get the number of off diagonal elts
68  int l = source.noffdiag();
69  // banded matrix class is always square
70  int n = source.nrows();
71  for ( int row = 0; row < n; ++row )
72  {
73  DenseVector<_Type> vecrow( n, 0.0 );
74  for ( int col = std::max( row - l, 0 );
75  col < std::min( n, row + l + 1 );
76  ++col )
77  {
78  vecrow[ col ] = source( row, col );
79  }
80  MATRIX.push_back( vecrow );
81  }
82  NR = NC = n;
83  }
double source(const double &x, const double &y, const double &t)
Definition: IBVP_linear.cpp:25
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().

57  :
58  Matrix_base<_Type>( source )
59  {
60  *this = source;
61  }
double source(const double &x, const double &y, const double &t)
Definition: IBVP_linear.cpp:25
template<typename _Type >
CppNoddy::DenseMatrix< _Type >::~DenseMatrix ( )

Definition at line 64 of file DenseMatrix.cpp.

Referenced by CppNoddy::DenseMatrix< D_complex >::DenseMatrix().

65  {}

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(), and CppNoddy::DenseMatrix< D_complex >::rend().

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

Assign a value to the matrix but keep the same geometry.

Parameters
eltThe value to be assigned to all entries

Definition at line 179 of file DenseMatrix.h.

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

Pass through of iterator calls.

Returns
Iterator to the begin row

Definition at line 186 of file DenseMatrix.h.

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

187  {
188  return MATRIX.begin();
189  }
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 214 of file DenseMatrix.h.

215  {
216  return MATRIX.begin();
217  }
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.

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

Referenced by CppNoddy::DenseMatrix< D_complex >::operator-().

264  {
265  std::cout << "DENSE mtx size = " << nrows() << " x " << ncols() << "; \n";
266  std::cout.precision( 3 );
267  std::cout << std::fixed;
268  std::cout.setf( std::ios::showpoint );
269  std::cout.setf( std::ios::showpos );
270  //std::cout.setf( std::ios::scientific );
271  std::cout << "- start matrix \n";
272  for ( std::size_t i = 0; i < nrows(); ++i )
273  {
274  std::cout << " row " << i << " = ";
275  for ( std::size_t j = 0; j < ncols(); ++j )
276  {
277  std::cout << MATRIX[ i ][ j ] << ", ";
278  }
279  std::cout << "\n";
280  }
281  std::cout << "- end matrix \n";
282  }
std::size_t ncols() const
Definition: DenseMatrix.h:418
std::size_t nrows() const
Definition: DenseMatrix.h:412
template<typename _Type>
row_iter CppNoddy::DenseMatrix< _Type >::end ( )
inline

Pass through of iterator calls.

Returns
Iterator to the end row

Definition at line 193 of file DenseMatrix.h.

194  {
195  return MATRIX.end();
196  }
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 221 of file DenseMatrix.h.

222  {
223  return MATRIX.end();
224  }
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(), and CppNoddy::DenseMatrix< D_complex >::operator-().

252  {
253  double sum ( 0.0 );
254  for ( std::size_t row = 0; row < NR; ++row )
255  {
256  sum += MATRIX[ row ].two_norm();
257  }
258  return sum;
259  }
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 347 of file DenseMatrix.h.

References CppNoddy::DenseMatrix< _Type >::set().

Referenced by main(), and CppNoddy::DenseMatrix< _Type >::operator()().

348  {
349 #ifdef PARANOID
350  if ( ( row > NR ) || ( row < 0 ) )
351  {
352  std::string problem( "The DenseMatrix.get has a range error.\n" );
353  throw ExceptionRange( problem, NR, row, NC, col );
354  }
355 
356  if ( ( col > NC ) || ( col < 0 ) )
357  {
358  std::string problem( "The DenseMatrix.get has a range error.\n" );
359  throw ExceptionRange( problem, NR, row, NC, col );
360  }
361 #endif
362  return MATRIX[ row ][ col ];
363  }
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 294 of file DenseMatrix.cpp.

Referenced by CppNoddy::DenseMatrix< _Type >::multiply(), and CppNoddy::DenseMatrix< D_complex >::rend().

295  {
296  DenseVector<_Type> X( NR, 0.0 );
297  for ( std::size_t row = 0; row < NR; ++row )
298  {
299  X[ row ] = MATRIX[ row ][ col ];
300  }
301  return X;
302  }
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(), and CppNoddy::DenseMatrix< D_complex >::operator-().

241  {
242  double max( 0.0 );
243  for ( std::size_t row = 0; row < NR; ++row )
244  {
245  max = std::max( max, MATRIX[ row ].inf_norm() );
246  }
247  return max;
248  }
double inf_norm() const
Return the maximum inf_norm of all rows.
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(), and CppNoddy::DenseMatrix< D_complex >::rend().

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 305 of file DenseMatrix.cpp.

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

306  {
307  p.reserve( 2 * NR * NC );
308  for ( std::size_t row = 0; row < NR; ++row )
309  {
310  for ( std::size_t col = 0; col < NC; ++col )
311  {
312  p.push_back( MATRIX[ row ][ col ].real() );
313  p.push_back( MATRIX[ row ][ col ].imag() );
314  }
315  for ( std::size_t col = 0; col < padding; ++col )
316  {
317  p.push_back( 0.0 );
318  p.push_back( 0.0 );
319  }
320  }
321  }
DenseVector< double > imag(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the imaginary part of a complex DENSE vector.
Definition: Utility.cpp:355
DenseVector< double > real(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the real part of a complex DENSE vector.
Definition: Utility.cpp:345
void push_back(const _Type &fill)
A pass-thru definition of push_back.
Definition: DenseVector.h:341
void reserve(const std::size_t &n)
Reserve space for the vector.
Definition: DenseVector.h:377
template<>
void CppNoddy::DenseMatrix< double >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding 
) const

Definition at line 325 of file DenseMatrix.cpp.

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

326  {
327  p.reserve( NR * NC );
328  for ( std::size_t row = 0; row < NR; ++row )
329  {
330  for ( std::size_t col = 0; col < NC; ++col )
331  {
332  p.push_back( MATRIX[ row ][ col ] );
333  }
334  for ( std::size_t col = 0; col < padding; ++col )
335  {
336  p.push_back( 0.0 );
337  }
338  }
339  }
void push_back(const _Type &fill)
A pass-thru definition of push_back.
Definition: DenseVector.h:341
void reserve(const std::size_t &n)
Reserve space for the vector.
Definition: DenseVector.h:377
template<>
DenseVector< double > CppNoddy::DenseMatrix< double >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 342 of file DenseMatrix.cpp.

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

343  {
344  DenseVector<double> V;
345  V.reserve( NR * NC );
346  for ( std::size_t row = 0; row < NR; ++row )
347  {
348  for ( std::size_t col = 0; col < NC; ++col )
349  {
350  V.push_back( MATRIX[ row ][ col ] );
351  }
352  for ( std::size_t col = 0; col < padding; ++col )
353  {
354  V.push_back( 0.0 );
355  }
356  }
357  return V;
358  }
Definition: BVP_Karman.cpp:22
template<>
DenseVector< double > CppNoddy::DenseMatrix< std::complex< double > >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 361 of file DenseMatrix.cpp.

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

362  {
363  DenseVector<double> V;
364  V.reserve( 2 * NR * NC );
365  for ( std::size_t row = 0; row < NR; ++row )
366  {
367  for ( std::size_t col = 0; col < NC; ++col )
368  {
369  V.push_back( MATRIX[ row ][ col ].real() );
370  V.push_back( MATRIX[ row ][ col ].imag() );
371  }
372  for ( std::size_t col = 0; col < padding; ++col )
373  {
374  V.push_back( 0.0 );
375  V.push_back( 0.0 );
376  }
377  }
378  return V;
379  }
DenseVector< double > imag(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the imaginary part of a complex DENSE vector.
Definition: Utility.cpp:355
Definition: BVP_Karman.cpp:22
DenseVector< double > real(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the real part of a complex DENSE vector.
Definition: Utility.cpp:345
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.

References CppNoddy::DenseMatrix< _Type >::begin().

Referenced by CppNoddy::DenseMatrix< D_complex >::rend().

202  {
203  row_iter index( row_min );
204  double maxelt( std::abs( *( row_min -> begin() ) ) );
205  for ( row_iter row = row_min + 1; row != row_max ; ++row )
206  {
207  const double elt( std::abs( *( row -> begin() + col ) ) );
208  if ( elt >= maxelt )
209  {
210  maxelt = elt;
211  index = row;
212  }
213  }
214  return index;
215  }
std::vector< DenseVector< _Type > >::iterator row_iter
Typedef iterator types.
Definition: DenseMatrix.h:32
row_iter begin()
Pass through of iterator calls.
Definition: DenseMatrix.h:186
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 >::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(), main(), CppNoddy::DenseMatrix< _Type >::multiply(), CppNoddy::DenseMatrix< D_complex >::operator-(), and CppNoddy::DenseMatrix< D_complex >::rend().

156  {
157 #ifdef PARANOID
158  // check number of columns at least match
159  if ( X.size() != NC )
160  {
161  std::string problem( "The DenseMatrix.multiply has a geometry error.\n" );
162  throw ExceptionGeom( problem, NR, NC, X.size(), 1 );
163  }
164 #endif
165  DenseVector<_Type> temp;
166  temp.reserve( NR );
167  for ( std::size_t row = 0; row < NR; ++row )
168  {
169  temp.push_back( Utility::dot( MATRIX[ row ], X ) );
170  }
171  return temp;
172  }
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:381
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::DenseMatrix< _Type >::multiply(), CppNoddy::DenseMatrix< _Type >::ncols(), CppNoddy::DenseMatrix< _Type >::nrows(), and CppNoddy::DenseMatrix< _Type >::set_col().

176  {
177 #ifdef PARANOID
178  // check number of columns at least match
179  if ( B.nrows() != NC )
180  {
181  std::string problem( "The DenseMatrix.multiply has a geometry error.\n" );
182  throw ExceptionGeom( problem, NR, NC, B.nrows(), B.ncols() );
183  }
184 #endif
185  // temporary object for the result
186  DenseMatrix<_Type> C( nrows(), B.ncols(), 0.0 );
187  // loops thru the columns in the B matrix
188  for ( std::size_t col_in_B = 0; col_in_B < B.ncols(); ++col_in_B )
189  {
190  // set the column in the result to be the matrix-vector
191  // product of (*this).multiply( column in B )
192  C.set_col( col_in_B , multiply( B.get_col( col_in_B ) ) );
193  }
194  return C;
195  }
std::size_t nrows() const
Definition: DenseMatrix.h:412
DenseVector< _Type > multiply(const DenseVector< _Type > &x) const
Right multiply the matrix by a DENSE vector.
template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::ncols ( ) const
inlinevirtual
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.

Referenced by CppNoddy::DenseMatrix< D_complex >::operator-().

80  {
81  return NR * NC;
82  }
template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::nrows ( ) const
inlinevirtual
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(), and CppNoddy::DenseMatrix< D_complex >::operator-().

219  {
220  double max( 0.0 );
221  for ( std::size_t row = 0; row < NR; ++row )
222  {
223  max = std::max( max, MATRIX[ row ].one_norm() );
224  }
225  return max;
226  }
double one_norm() const
Return the maximum one_norm of all rows.
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 308 of file DenseMatrix.h.

Referenced by CppNoddy::DenseMatrix< D_complex >::DenseMatrix().

310  {
311 #ifdef PARANOID
312  if ( ( row > NR ) || ( row < 0 ) )
313  {
314  std::string problem( "The DenseMatrix.() has a range error.\n" );
315  throw ExceptionRange( problem, NR, row, NC, col );
316  }
317  if ( ( col > NC ) || ( col < 0 ) )
318  {
319  std::string problem( "The DenseMatrix.() has a range error.\n" );
320  throw ExceptionRange( problem, NR, row, NC, col );
321  }
322 #endif
323  return MATRIX[ row ][ col ];
324  }
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 327 of file DenseMatrix.h.

References CppNoddy::DenseMatrix< _Type >::get().

329  {
330 #ifdef PARANOID
331  if ( ( row > NR ) || ( row < 0 ) )
332  {
333  std::string problem( "The DenseMatrix.() has a range error.\n" );
334  throw ExceptionRange( problem, NR, row, NC, col );
335  }
336  if ( ( col > NC ) || ( col < 0 ) )
337  {
338  std::string problem( "The DenseMatrix.() has a range error.\n" );
339  throw ExceptionRange( problem, NR, row, NC, col );
340  }
341 #endif
342  return MATRIX[ row ][ col ];
343  }
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.

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

Definition at line 113 of file DenseMatrix.h.

114  {
115  DenseMatrix<_Type> temp( *this );
116  for ( std::size_t row = 0; row < NR; ++row )
117  {
118  for ( std::size_t col = 0; col < NC; ++col )
119  {
120  temp( row, col ) += A( row, col );
121  }
122  }
123  return temp;
124  }
double A(1.0)
initial hump amplitude
template<typename _Type>
DenseMatrix<_Type> CppNoddy::DenseMatrix< _Type >::operator- ( const DenseMatrix< _Type > &  A) const
inline

Definition at line 125 of file DenseMatrix.h.

126  {
127  DenseMatrix<_Type> temp( *this );
128  for ( std::size_t row = 0; row < NR; ++row )
129  {
130  for ( std::size_t col = 0; col < NC; ++col )
131  {
132  temp( row, col ) -= A( row, col );
133  }
134  }
135  return temp;
136  }
double A(1.0)
initial hump amplitude
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.

Referenced by CppNoddy::DenseMatrix< D_complex >::DenseMatrix().

69  {
70  if ( this == &source )
71  return * this;
72  MATRIX = source.MATRIX;
73  NR = source.NR;
74  NC = source.NC;
75  return *this;
76  }
double source(const double &x, const double &y, const double &t)
Definition: IBVP_linear.cpp:25
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 386 of file DenseMatrix.h.

Referenced by CppNoddy::DenseMatrix< D_complex >::rend().

387  {
388 #ifdef PARANOID
389  if ( ( row > NR ) || ( row < 0 ) )
390  {
391  std::string problem( "The DenseMatrix.get_row has a range error.\n" );
392  throw ExceptionRange( problem, NR, row );
393  }
394 #endif
395  return MATRIX[ row ];
396  }
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 399 of file DenseMatrix.h.

400  {
401 #ifdef PARANOID
402  if ( ( row > NR ) || ( row < 0 ) )
403  {
404  std::string problem( "The DenseMatrix.get_row has a range error.\n" );
405  throw ExceptionRange( problem, NR, row );
406  }
407 #endif
408  return MATRIX[ row ];
409  }
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 200 of file DenseMatrix.h.

201  {
202  return MATRIX.rbegin();
203  }
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 228 of file DenseMatrix.h.

229  {
230  return MATRIX.rbegin();
231  }
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 207 of file DenseMatrix.h.

208  {
209  return MATRIX.rend();
210  }
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 235 of file DenseMatrix.h.

236  {
237  return MATRIX.rend();
238  }
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(), CppNoddy::DenseMatrix< D_complex >::operator*(), and CppNoddy::DenseMatrix< D_complex >::operator-().

114  {
115  std::transform( MATRIX.begin(), MATRIX.end(), MATRIX.begin(), scale_functor< DenseVector<_Type>, _Type >( mult ) );
116  }
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 367 of file DenseMatrix.h.

Referenced by CppNoddy::DenseMatrix< _Type >::get(), and main().

369  {
370 #ifdef PARANOID
371  if ( ( row > NR ) || ( row < 0 ) )
372  {
373  std::string problem( "The DenseMatrix.set has a range error.\n" );
374  throw ExceptionRange( problem, NR, row, NC, col );
375  }
376  if ( ( col > NC ) || ( col < 0 ) )
377  {
378  std::string problem( "The DenseMatrix.set has a range error.\n" );
379  throw ExceptionRange( problem, NR, row, NC, col );
380  }
381 #endif
382  return MATRIX[ row ][ col ];
383  }
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 285 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(), CppNoddy::DenseMatrix< _Type >::multiply(), and CppNoddy::DenseMatrix< D_complex >::rend().

286  {
287  for ( std::size_t row = 0; row < NR; ++row )
288  {
289  MATRIX[ row ][ col ] = X[ row ];
290  }
291  }
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(), main(), and CppNoddy::DenseMatrix< D_complex >::rend().

100  {
101 #ifdef PARANOID
102  // check number of columns at least match
103  if ( ( B.nrows() != NR ) || ( B.ncols() != NC ) )
104  {
105  std::string problem( "The DenseMatrix.sub has a geometry error.\n" );
106  throw ExceptionGeom( problem, NR, NC, B.nrows(), B.ncols() );
107  }
108 #endif
109  std::transform( MATRIX.begin(), MATRIX.end(), B.MATRIX.begin(), MATRIX.begin(), std::minus< DenseVector<_Type> >() );
110  }
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.

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

Referenced by CppNoddy::FortranData::FortranData(), and CppNoddy::DenseMatrix< D_complex >::operator-().

120  {
121  if ( nrows() == ncols() )
122  {
123  // square matrix needs no temp object
124  // loop through upper half diagonal of the matrix
125  for ( std::size_t i = 0; i < nrows(); ++i )
126  {
127  for ( std::size_t j = i + 1; j < ncols(); ++j )
128  {
129  // swap elements
130  std::swap( MATRIX[ i ][ j ], MATRIX[ j ][ i ] );
131  }
132  }
133  }
134  else
135  {
136  std::vector< DenseVector<_Type> > temp;
137  temp.resize( NC );
138  for ( std::size_t row = 0; row < NC; ++row )
139  {
140  temp[ row ].resize( NR );
141  }
142  for ( std::size_t i = 0; i < nrows(); ++i )
143  {
144  for ( std::size_t j = 0; j < ncols(); ++j )
145  {
146  temp[ j ][ i ] = MATRIX[ i ][ j ];
147  }
148  }
149  MATRIX = temp;
150  std::swap( NR, NC );
151  }
152  }
std::size_t ncols() const
Definition: DenseMatrix.h:418
std::size_t nrows() const
Definition: DenseMatrix.h:412
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(), and CppNoddy::DenseMatrix< D_complex >::operator-().

230  {
231  double max( 0.0 );
232  for ( std::size_t row = 0; row < NR; ++row )
233  {
234  max = std::max( max, MATRIX[ row ].two_norm() );
235  }
236  return max;
237  }
double two_norm() const
Rreturn the maximum two_norm of all rows.

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

© 2012

R.E. Hewitt