CppNoddy  0.90
Public Types | Public Member Functions | Public Attributes | List of all members
CppNoddy::BandedMatrix< _Type > Class Template Reference

A matrix class that constructs a BANDED matrix. More...

#include <BandedMatrix.h>

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

Public Types

typedef DenseVector< _Type >::elt_iter elt_iter
 

Public Member Functions

 BandedMatrix ()
 Empty constructor .. should we stop this? More...
 
 BandedMatrix (const std::size_t &rows, const std::size_t &offdiag, const _Type &fill)
 Noddy Banded Matrix constructor. More...
 
 BandedMatrix (const BandedMatrix &source)
 Copy constructor. More...
 
BandedMatrixoperator= (const BandedMatrix &source)
 Assignment operator. More...
 
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...
 
std::size_t nrows () const
 Get the number of rows. More...
 
std::size_t ncols () const
 Get the number of columns. More...
 
std::size_t nelts () const
 Get the number of elements. More...
 
void scale (const _Type &mult)
 Scale all entries in the matrix by a scalar. More...
 
void transpose ()
 Transpose the matrix. More...
 
double one_norm () const
 
double two_norm () const
 
double inf_norm () const
 
double frob_norm () const
 
DenseVector< _Type > multiply (const DenseVector< _Type > &X) const
 Right multiply the matrix by a DENSE vector. More...
 
void dump () const
 Output the matrix contents to std::cout. More...
 
void assign (_Type elt)
 Assign a value the matrix so that it has the same geometry, but zero entries in all locations including those reserved for pivotting. More...
 
std::size_t noffdiag () const
 Get the number of off-diagonal elements where the total INPUT band width is 2*noffdiag+1 since the band structure is symmetric. More...
 
void row_swap (const std::size_t &row1, const std::size_t &row2)
 Exchange rows in the matrix. More...
 
double * base ()
 Allow direct access to the vector STORAGE. More...
 
elt_iter get_elt_iter (std::size_t row, std::size_t col)
 
template<>
double * base ()
 
template<>
double * base ()
 
- Public Member Functions inherited from CppNoddy::Matrix_base< _Type >
 Matrix_base ()
 An empty constructor. More...
 
virtual ~Matrix_base ()
 

Public Attributes

DenseVector< _Type > STORAGE
 A contiguous vector. More...
 
std::size_t N
 The number of rows/cols in the matrix. More...
 
std::size_t L
 Max number of (INPUT) bands above OR below the main diagonal. More...
 

Detailed Description

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

A matrix class that constructs a BANDED matrix.

Definition at line 17 of file BandedMatrix.h.

Member Typedef Documentation

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

Definition at line 22 of file BandedMatrix.h.

Constructor & Destructor Documentation

template<typename _Type>
CppNoddy::BandedMatrix< _Type >::BandedMatrix ( )
inline

Empty constructor .. should we stop this?

Definition at line 25 of file BandedMatrix.h.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

26  {}
template<typename _Type>
CppNoddy::BandedMatrix< _Type >::BandedMatrix ( const std::size_t &  rows,
const std::size_t &  offdiag,
const _Type &  fill 
)

Noddy Banded Matrix constructor.

Parameters
rowsThe number of rows in the matrix.
offdiagThe maximum number of bands above OR below the diagonal. The total number stored will be 3 * offdiag + 1; i.e. assumes the number of offdiagonal elts is the same both above and below, and we must an extra 'offdiag' because of fill-in during pivotting.
fillThe initial value to be placed in each element of the banded matrix.

Definition at line 18 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, and CppNoddy::BandedMatrix< _Type >::STORAGE.

20  :
21  Matrix_base<_Type>(),
22  N( rows ),
23  L( upper_offdiag_bands )
24  {
25  // we'll assume that the upper & lower offdiags are of equal size.
26  // logical STORAGE is the main diagonal + upper offdiagonal + lower offdiagonal
27  // = 2 * L + 1.
28  // However, allowing for row interchanging during pivotting leads to additional
29  // padding of L, to make a total of 3*L+1.
30  STORAGE = DenseVector<_Type>( N * ( 3 * L + 1 ), 0.0 );
31  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type>
CppNoddy::BandedMatrix< _Type >::BandedMatrix ( const BandedMatrix< _Type > &  source)

Copy constructor.

Parameters
sourceThe source object to be copied

Definition at line 34 of file BandedMatrix.cpp.

References CppNoddy::Example::source().

34  :
35  Matrix_base<_Type>( source )
36  {
37  *this = source;
38  }
double source(const double &x, const double &y, const double &t)
Definition: IBVP_linear.cpp:25

Member Function Documentation

template<typename _Type>
void CppNoddy::BandedMatrix< _Type >::assign ( _Type  elt)
inline

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

Parameters
eltThe value to be assigned to all entries

Definition at line 104 of file BandedMatrix.h.

Referenced by CppNoddy::ODE_BVP< _Type, _Xtype >::arclength_solve(), CppNoddy::PDE_IBVP< _Type >::assemble_matrix_problem(), CppNoddy::reversed_BL< _Type >::bidirectional_step2(), and CppNoddy::PDE_double_IBVP< _Type >::step2().

105  {
106  STORAGE.assign( STORAGE.size(), elt );
107  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<typename _Type>
double* CppNoddy::BandedMatrix< _Type >::base ( )

Allow direct access to the vector STORAGE.

Dangerous, but used for passing to LAPACK.

Referenced by CppNoddy::BandedMatrix< double >::assign().

template<>
double * CppNoddy::BandedMatrix< double >::base ( )

Definition at line 187 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::STORAGE.

188  {
189  return &( STORAGE[0] );
190  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<>
double * CppNoddy::BandedMatrix< std::complex< double > >::base ( )

Definition at line 193 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::STORAGE.

194  {
195  //return &( STORAGE[0].real() );
196  return &reinterpret_cast<double(&)[2]>( STORAGE[0] )[0];
197  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<typename _Type >
void CppNoddy::BandedMatrix< _Type >::dump ( ) const
virtual

Output the matrix contents to std::cout.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 158 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::ncols(), CppNoddy::BandedMatrix< _Type >::nrows(), and CppNoddy::BandedMatrix< _Type >::operator()().

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

159  {
160  std::cout << "BANDED mtx size = " << nrows() << " x " << ncols()
161  << " with INPUT no. of bands = " << 2 * L + 1
162  << " and total bands STORED (for pivotting) = " << 3 * L + 1 << "\n";
163  std::cout.precision( 4 );
164  std::cout << "- start matrix \n";
165  for ( std::size_t i = 0; i < nrows(); ++i )
166  {
167  std::cout << " row " << i << " = ";
168  for ( std::size_t j = 0; j < nrows(); ++j )
169  {
170  if ( i == j )
171  std::cout << "*";
172  if ( ( ( int ) j < ( int ) i - ( int ) L ) || ( ( int ) j > ( int ) i + ( int ) ( 2*L ) ) )
173  {
174  std::cout << 0 << ", ";
175  }
176  else
177  {
178  std::cout << operator() ( i, j ) << ", ";
179  }
180  }
181  std::cout << "\n";
182  }
183  std::cout << "- end matrix \n";
184  }
std::size_t nrows() const
Get the number of rows.
Definition: BandedMatrix.h:225
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
std::size_t ncols() const
Get the number of columns.
Definition: BandedMatrix.h:231
const _Type & operator()(const std::size_t &row, const std::size_t &col) const
Access operator.
Definition: BandedMatrix.h:147
template<typename _Type >
double CppNoddy::BandedMatrix< _Type >::frob_norm ( ) const
virtual
Returns
The sum of the two_norm of all rows

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 145 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, CppNoddy::BandedMatrix< _Type >::STORAGE, and CppNoddy::DenseVector< _Type >::two_norm().

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

146  {
147  double sum( 0.0 );
148  for ( unsigned row = 0; row < N; ++row )
149  {
150  // copy the row into a temp vector
151  DenseVector<_Type> temp( 3 * L + 1, &STORAGE[ row * ( 3 * L + 1 ) ] );
152  sum += temp.two_norm();
153  }
154  return sum;
155  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
const _Type & CppNoddy::BandedMatrix< _Type >::get ( const std::size_t &  row,
const std::size_t &  col 
) const
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 212 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::operator()(), and CppNoddy::BandedMatrix< _Type >::set().

Referenced by CppNoddy::BandedMatrix< _Type >::operator()().

213  {
214  return operator() ( row, col );
215  }
const _Type & operator()(const std::size_t &row, const std::size_t &col) const
Access operator.
Definition: BandedMatrix.h:147
template<typename _Type>
elt_iter CppNoddy::BandedMatrix< _Type >::get_elt_iter ( std::size_t  row,
std::size_t  col 
)
inline

Definition at line 126 of file BandedMatrix.h.

Referenced by CppNoddy::PDE_IBVP< _Type >::assemble_matrix_problem(), CppNoddy::reversed_BL< _Type >::bidirectional_step2(), and CppNoddy::PDE_double_IBVP< _Type >::step2().

127  {
128  return STORAGE.begin() + L * ( 3 * col + 2 ) + row;
129  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
double CppNoddy::BandedMatrix< _Type >::inf_norm ( ) const
virtual
Returns
The maximum inf_norm of all rows

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 131 of file BandedMatrix.cpp.

References CppNoddy::DenseVector< _Type >::inf_norm(), CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, and CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

132  {
133  double max( 0.0 );
134  for ( unsigned row = 0; row < N; ++row )
135  {
136  // copy the row into a temp vector
137  DenseVector<_Type> temp( 3 * L + 1, &STORAGE[ row * ( 3 * L + 1 ) ] );
138  max = std::max( max, temp.inf_norm() );
139  }
140  return max;
141  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type>
DenseVector< _Type > CppNoddy::BandedMatrix< _Type >::multiply ( const DenseVector< _Type > &  X) const
virtual

Right multiply the matrix by a DENSE vector.

Parameters
XThe DENSE vector to multiply by
Returns
A DENSE vector of length ncols() produced from the multiplication

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 65 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

66  {
67  std::string problem;
68  problem = " The multiply method of the BandedMatrix class has \n";
69  problem += " not been implemented. \n";
70  throw ExceptionRuntime( problem );
71  return STORAGE; // dummy return
72  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<typename _Type >
std::size_t CppNoddy::BandedMatrix< _Type >::ncols ( ) const
inlinevirtual

Get the number of columns.

Returns
The number of columns in the matrix

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 231 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::N.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix(), CppNoddy::BandedMatrix< _Type >::dump(), CppNoddy::Utility::fill_random(), and CppNoddy::Utility::fill_row().

232  {
233  return N;
234  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
template<typename _Type >
std::size_t CppNoddy::BandedMatrix< _Type >::nelts ( ) const
virtual

Get the number of elements.

Returns
The number of elements

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 52 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

53  {
54  return STORAGE.size();
55  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<typename _Type >
std::size_t CppNoddy::BandedMatrix< _Type >::noffdiag ( ) const
inline

Get the number of off-diagonal elements where the total INPUT band width is 2*noffdiag+1 since the band structure is symmetric.

Returns
The number of upper or lower offdiagonal bands; NOTE: the number of offdiagonals STORED will typically be three times this to allow for pivotting

Definition at line 237 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::L.

Referenced by CppNoddy::PDE_IBVP< _Type >::assemble_matrix_problem(), CppNoddy::BandedMatrix< double >::assign(), CppNoddy::reversed_BL< _Type >::bidirectional_step2(), CppNoddy::DenseMatrix< D_complex >::DenseMatrix(), CppNoddy::Utility::fill_random(), CppNoddy::Utility::fill_row(), main(), and CppNoddy::PDE_double_IBVP< _Type >::step2().

238  {
239  return L;
240  }
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
std::size_t CppNoddy::BandedMatrix< _Type >::nrows ( ) const
inlinevirtual

Get the number of rows.

Returns
The number of rows in the matrix

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 225 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::N.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix(), CppNoddy::DenseMatrix< D_complex >::DenseMatrix(), CppNoddy::BandedMatrix< _Type >::dump(), CppNoddy::Utility::fill(), and CppNoddy::Utility::fill_random().

226  {
227  return N;
228  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
template<typename _Type >
double CppNoddy::BandedMatrix< _Type >::one_norm ( ) const
virtual
Returns
The maximum one_norm of all rows

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 103 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, CppNoddy::DenseVector< _Type >::one_norm(), and CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

104  {
105  double max( 0.0 );
106  for ( unsigned row = 0; row < N; ++row )
107  {
108  // copy the row into a temp vector
109  DenseVector<_Type> temp( 3 * L + 1, &STORAGE[ row * ( 3 * L + 1 ) ] );
110  max = std::max( max, temp.one_norm() );
111  }
112  return max;
113  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
const _Type & CppNoddy::BandedMatrix< _Type >::operator() ( const std::size_t &  row,
const std::size_t &  col 
) const
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 147 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, and CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix(), CppNoddy::BandedMatrix< _Type >::dump(), CppNoddy::BandedMatrix< _Type >::get(), and CppNoddy::BandedMatrix< _Type >::set().

148  {
149 #ifdef PARANOID
150  // if outside the NxN matrix
151  if ( ( row >= N ) || ( row < 0 ) || ( col >= N ) || ( col < 0 ) )
152  {
153  std::string problem;
154  problem = " The const operator() of BandedMatrix has been called \n";
155  problem += " with a (row, col) index that is outside \n";
156  problem += " the square NxN matrix.\n";
157  throw ExceptionGeom( problem, N, N, row, col );
158  }
159  // check if the subscripts are out of the band
160  if ( !( ( col + L >= row ) && ( col <= 2*L + row ) ) )
161  {
162  std::string problem;
163  problem = " The const operator() of BandedMatrix has been called \n";
164  problem += " with a (row, col) index that is outside \n";
165  problem += " the band structure. Bandwidth and offset from\n";
166  problem += " the diagonal information follows.\n";
167  throw ExceptionGeom( problem, L, col - row );
168  }
169 #endif
170  // MOSTLY WE PUSH BANDED MATRICES TO LAPACK - so we'll keep column major
171  // internal storage ... a la Fortran
172  // return STORAGE[ col * ( 3 * L + 1 ) + ( row - col ) + 2 * L ];
173  // or equiv.
174  return STORAGE[ L * ( 3 * col + 2 ) + row ];
175  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
_Type & CppNoddy::BandedMatrix< _Type >::operator() ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 178 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::get(), CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, and CppNoddy::BandedMatrix< _Type >::STORAGE.

179  {
180 #ifdef PARANOID
181  // if outside the NxN matrix
182  if ( ( row >= N ) || ( row < 0 ) || ( col >= N ) || ( col < 0 ) )
183  {
184  std::string problem;
185  problem = " The operator() of BandedMatrix has been called \n";
186  problem += " with a (row, col) index that is outside \n";
187  problem += " the square NxN matrix.\n";
188  throw ExceptionRange( problem, N, N, row, col );
189  }
190  // check if the subscripts are out of the band
191  if ( !( ( col + L >= row ) && ( col <= 2*L + row ) ) )
192  {
193  std::string problem;
194  problem = " The operator() of BandedMatrix has been called \n";
195  problem += " with a (row, col) index that is outside \n";
196  problem += " the band structure.\n";
197  std::cout << " L = " << L << "\n";
198  std::cout << " row = " << row << "\n";
199  std::cout << " col = " << col << "\n";
200  throw ExceptionRange( problem, N, L, row, col );
201  }
202 #endif
203  // MOSTLY WE PUSH BANDED MATRICES TO LAPACK - so we'll keep column major
204  // internal storage ... a la Fortran
205  // return STORAGE[ col * ( 3 * L + 1 ) + ( row - col ) + 2 * L ];
206  // or equiv.
207  return STORAGE[ L * ( 3 * col + 2 ) + row ];
208  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
BandedMatrix< _Type > & CppNoddy::BandedMatrix< _Type >::operator= ( const BandedMatrix< _Type > &  source)
inline

Assignment operator.

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

Definition at line 41 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, and CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

42  {
43  if ( this == &source )
44  return * this;
45  STORAGE = source.STORAGE;
46  N = source.N;
47  L = source.L;
48  return *this;
49  }
double source(const double &x, const double &y, const double &t)
Definition: IBVP_linear.cpp:25
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
void CppNoddy::BandedMatrix< _Type >::row_swap ( const std::size_t &  row1,
const std::size_t &  row2 
)

Exchange rows in the matrix.

Parameters
row1First row to be swapped
row2Second row to be swapped
Todo:
MAKE ME PRIVATE OR ELSE!

Definition at line 90 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, and CppNoddy::BandedMatrix< _Type >::N.

Referenced by CppNoddy::BandedMatrix< double >::assign().

91  {
92  // WE MUST HAVE row2 > row1 & row1 must have no elements left of the diagonal!
93  // only of any use to native Gaussian elimination solver
94  /// \todo MAKE ME PRIVATE OR ELSE!
95  for ( std::size_t col = row1; col <= std::min( row1 + 2 * L, N - 1 ); ++col )
96  {
97  std::swap( operator()( row1, col ), operator()( row2, col ) );
98  }
99  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type>
void CppNoddy::BandedMatrix< _Type >::scale ( const _Type &  mult)
virtual

Scale all entries in the matrix by a scalar.

Parameters
multThe scalar multiplier

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 58 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::STORAGE.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

59  {
60  STORAGE *= mult;
61  }
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
template<typename _Type >
_Type & CppNoddy::BandedMatrix< _Type >::set ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 219 of file BandedMatrix.h.

References CppNoddy::BandedMatrix< _Type >::operator()().

Referenced by CppNoddy::BandedMatrix< _Type >::get().

220  {
221  return operator() ( row, col );
222  }
const _Type & operator()(const std::size_t &row, const std::size_t &col) const
Access operator.
Definition: BandedMatrix.h:147
template<typename _Type >
void CppNoddy::BandedMatrix< _Type >::transpose ( )
virtual

Transpose the matrix.

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 76 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, and CppNoddy::BandedMatrix< _Type >::N.

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

77  {
78  for ( std::size_t row = 0; row < N; ++row )
79  {
80  for ( std::size_t col = std::max( 0, int( row ) - int( L ) ); col < row; ++col )
81  {
82  // swap elements
83  std::swap( operator()( row, col ), operator()( col, row ) );
84  }
85  }
86  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138
template<typename _Type >
double CppNoddy::BandedMatrix< _Type >::two_norm ( ) const
virtual
Returns
The maximum two_norm of all rows

Implements CppNoddy::Matrix_base< _Type >.

Definition at line 117 of file BandedMatrix.cpp.

References CppNoddy::BandedMatrix< _Type >::L, CppNoddy::BandedMatrix< _Type >::N, CppNoddy::BandedMatrix< _Type >::STORAGE, and CppNoddy::DenseVector< _Type >::two_norm().

Referenced by CppNoddy::BandedMatrix< double >::BandedMatrix().

118  {
119  double max( 0.0 );
120  for ( unsigned row = 0; row < N; ++row )
121  {
122  // copy the row into a temp vector
123  DenseVector<_Type> temp( 3 * L + 1, &STORAGE[ row * ( 3 * L + 1 ) ] );
124  max = std::max( max, temp.two_norm() );
125  }
126  return max;
127  }
std::size_t N
The number of rows/cols in the matrix.
Definition: BandedMatrix.h:136
DenseVector< _Type > STORAGE
A contiguous vector.
Definition: BandedMatrix.h:134
std::size_t L
Max number of (INPUT) bands above OR below the main diagonal.
Definition: BandedMatrix.h:138

Member Data Documentation

template<typename _Type>
std::size_t CppNoddy::BandedMatrix< _Type >::L
template<typename _Type>
std::size_t CppNoddy::BandedMatrix< _Type >::N
template<typename _Type>
DenseVector<_Type> CppNoddy::BandedMatrix< _Type >::STORAGE

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

© 2012

R.E. Hewitt