CppNoddy  0.92
Loading...
Searching...
No Matches
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::Sequential_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 ... the void method is preferred. 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...
 
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding) const
 
void matrix_to_vector (DenseVector< double > &p, const std::size_t &padding) const
 
DenseVector< double > matrix_to_vector (const std::size_t &padding) const
 
DenseVector< double > matrix_to_vector (const std::size_t &padding) const
 
- Public Member Functions inherited from CppNoddy::Sequential_Matrix_base< _Type >
 Sequential_Matrix_base ()
 An empty constructor. More...
 
virtual ~Sequential_Matrix_base ()
 
virtual const _Type & operator() (const std::size_t &row, const std::size_t &col) const =0
 
virtual _Type & operator() (const std::size_t &row, const std::size_t &col)=0
 
virtual const _Type & get (const std::size_t &row, const std::size_t &col) const =0
 
virtual _Type & set (const std::size_t &row, const std::size_t &col)=0
 
virtual std::size_t nrows () const =0
 
virtual std::size_t ncols () const =0
 
virtual std::size_t nelts () const =0
 
virtual void scale (const _Type &mult)=0
 
virtual void dump () const =0
 

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 25 of file DenseMatrix.h.

Member Typedef Documentation

◆ elt_citer

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

Definition at line 34 of file DenseMatrix.h.

◆ elt_criter

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

Definition at line 36 of file DenseMatrix.h.

◆ elt_iter

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

Definition at line 33 of file DenseMatrix.h.

◆ elt_riter

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

Definition at line 35 of file DenseMatrix.h.

◆ row_citer

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

Definition at line 30 of file DenseMatrix.h.

◆ row_criter

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

Definition at line 32 of file DenseMatrix.h.

◆ row_iter

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

Typedef iterator types.

Definition at line 29 of file DenseMatrix.h.

◆ row_riter

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

Definition at line 31 of file DenseMatrix.h.

Constructor & Destructor Documentation

◆ DenseMatrix() [1/5]

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

Allow empty construction.

Definition at line 17 of file DenseMatrix.cpp.

17 : m_nr(0), m_nc(0)
18 {}

◆ DenseMatrix() [2/5]

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

23 :
24 Sequential_Matrix_base<_Type>(),
25 m_nr(rows),
26 m_nc(cols) {
27 // make a row
28 const DenseVector<_Type> row(cols, fill);
29 // reserve the space
30 m_matrix.reserve(rows);
31 for(std::size_t i = 0; i < rows; ++i) {
32 // push require number of rows into the 'matrix'
33 m_matrix.push_back(row);
34 }
35 }

◆ DenseMatrix() [3/5]

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

40 :
41 Sequential_Matrix_base<_Type>(),
42 m_nr(rows),
43 m_nc(cols) {
44 m_matrix.reserve(rows);
45 for(std::size_t i = 0; i < rows; ++i) {
46 m_matrix.push_back(DenseVector<_Type>(cols, &p[ i * cols ]));
47 }
48 }

◆ DenseMatrix() [4/5]

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 62 of file DenseMatrix.h.

62 {
63 // get the number of off diagonal elts
64 int l = source.noffdiag();
65 // banded matrix class is always square
66 int n = source.nrows();
67 for(int row = 0; row < n; ++row) {
68 DenseVector<_Type> vecrow(n, 0.0);
69 for(int col = std::max(row - l, 0);
70 col < std::min(n, row + l + 1);
71 ++col) {
72 vecrow[ col ] = source(row, col);
73 }
74 m_matrix.push_back(vecrow);
75 }
76 m_nr = m_nc = n;
77 }
double source(const double &x, const double &y, const double &t)
Definition: IBVPLinear.cpp:26

◆ DenseMatrix() [5/5]

template<typename _Type >
CppNoddy::DenseMatrix< _Type >::DenseMatrix ( const DenseMatrix< _Type > &  source)

Copy constructor.

Parameters
sourceThe source object to be copied

Definition at line 51 of file DenseMatrix.cpp.

51 :
52 Sequential_Matrix_base<_Type>() {
53 *this = source;
54 }

◆ ~DenseMatrix()

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

Definition at line 57 of file DenseMatrix.cpp.

58 {}

Member Function Documentation

◆ add()

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

76 {
77#ifdef PARANOID
78 // check number of columns at least match
79 if((B.nrows() != m_nr) || (B.ncols() != m_nc)) {
80 std::string problem("The DenseMatrix.add has a geometry error.\n");
81 throw ExceptionGeom(problem, m_nr, m_nc, B.nrows(), B.ncols());
82 }
83#endif
84 std::transform(m_matrix.begin(), m_matrix.end(), B.m_matrix.begin(), m_matrix.begin(), std::plus< DenseVector<_Type> >());
85 }

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

Referenced by main().

◆ assign()

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 167 of file DenseMatrix.h.

167 {
168 m_matrix.assign(m_matrix.size(), DenseVector<_Type>(m_nc, elt));
169 }

◆ begin() [1/2]

template<typename _Type >
row_iter CppNoddy::DenseMatrix< _Type >::begin ( )
inline

Pass through of iterator calls.

Returns
Iterator to the begin row

Definition at line 173 of file DenseMatrix.h.

173 {
174 return m_matrix.begin();
175 }

◆ begin() [2/2]

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 197 of file DenseMatrix.h.

197 {
198 return m_matrix.begin();
199 }

◆ dump()

template<typename _Type >
void CppNoddy::DenseMatrix< _Type >::dump
virtual

Output the matrix to std::cout.

Implements CppNoddy::Sequential_Matrix_base< _Type >.

Definition at line 223 of file DenseMatrix.cpp.

223 {
224 std::cout << "DENSE mtx size = " << nrows() << " x " << ncols() << "; \n";
225 std::cout.precision(3);
226 std::cout << std::fixed;
227 std::cout.setf(std::ios::showpoint);
228 std::cout.setf(std::ios::showpos);
229 //std::cout.setf( std::ios::scientific );
230 std::cout << "- start matrix \n";
231 for(std::size_t i = 0; i < nrows(); ++i) {
232 std::cout << " row " << i << " = ";
233 for(std::size_t j = 0; j < ncols(); ++j) {
234 std::cout << m_matrix[ i ][ j ] << ", ";
235 }
236 std::cout << "\n";
237 }
238 std::cout << "- end matrix \n";
239 }
std::size_t nrows() const
Definition: DenseMatrix.h:375
std::size_t ncols() const
Definition: DenseMatrix.h:380

◆ end() [1/2]

template<typename _Type >
row_iter CppNoddy::DenseMatrix< _Type >::end ( )
inline

Pass through of iterator calls.

Returns
Iterator to the end row

Definition at line 179 of file DenseMatrix.h.

179 {
180 return m_matrix.end();
181 }

◆ end() [2/2]

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 203 of file DenseMatrix.h.

203 {
204 return m_matrix.end();
205 }

◆ frob_norm()

template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::frob_norm

Return the sum of the two_norm of all rows.

Definition at line 213 of file DenseMatrix.cpp.

213 {
214 double sum(0.0);
215 for(std::size_t row = 0; row < m_nr; ++row) {
216 sum += m_matrix[ row ].two_norm();
217 }
218 return sum;
219 }

◆ get()

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::Sequential_Matrix_base< _Type >.

Definition at line 319 of file DenseMatrix.h.

320 {
321#ifdef PARANOID
322 if((row > m_nr) || (row < 0)) {
323 std::string problem("The DenseMatrix.get has a range error.\n");
324 throw ExceptionRange(problem, m_nr, row, m_nc, col);
325 }
326
327 if((col > m_nc) || (col < 0)) {
328 std::string problem("The DenseMatrix.get has a range error.\n");
329 throw ExceptionRange(problem, m_nr, row, m_nc, col);
330 }
331#endif
332 return m_matrix[ row ][ col ];
333 }

◆ get_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 249 of file DenseMatrix.cpp.

249 {
250 DenseVector<_Type> X(m_nr, 0.0);
251 for(std::size_t row = 0; row < m_nr; ++row) {
252 X[ row ] = m_matrix[ row ][ col ];
253 }
254 return X;
255 }

◆ inf_norm()

template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::inf_norm

Return the maximum inf_norm of all rows.

Definition at line 204 of file DenseMatrix.cpp.

204 {
205 double max(0.0);
206 for(std::size_t row = 0; row < m_nr; ++row) {
207 max = std::max(max, m_matrix[ row ].inf_norm());
208 }
209 return max;
210 }
double inf_norm() const
Return the maximum inf_norm of all rows.

Referenced by main().

◆ matrix_to_vector() [1/6]

DenseVector< double > CppNoddy::DenseMatrix< double >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 287 of file DenseMatrix.cpp.

287 {
288 DenseVector<double> V;
289 V.reserve(m_nr * m_nc);
290 for(std::size_t row = 0; row < m_nr; ++row) {
291 for(std::size_t col = 0; col < m_nc; ++col) {
292 V.push_back(m_matrix[ row ][ col ]);
293 }
294 for(std::size_t col = 0; col < padding; ++col) {
295 V.push_back(0.0);
296 }
297 }
298 return V;
299 }
@ V
Definition: BVPKarman.cpp:20

References V.

◆ matrix_to_vector() [2/6]

DenseVector< double > CppNoddy::DenseMatrix< std::complex< double > >::matrix_to_vector ( const std::size_t &  padding) const

Definition at line 302 of file DenseMatrix.cpp.

302 {
303 DenseVector<double> V;
304 V.reserve(2 * m_nr * m_nc);
305 for(std::size_t row = 0; row < m_nr; ++row) {
306 for(std::size_t col = 0; col < m_nc; ++col) {
307 V.push_back(m_matrix[ row ][ col ].real());
308 V.push_back(m_matrix[ row ][ col ].imag());
309 }
310 for(std::size_t col = 0; col < padding; ++col) {
311 V.push_back(0.0);
312 V.push_back(0.0);
313 }
314 }
315 return V;
316 }
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:177
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:185

References V.

◆ matrix_to_vector() [3/6]

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().

◆ matrix_to_vector() [4/6]

void CppNoddy::DenseMatrix< std::complex< double > >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding 
) const

Definition at line 258 of file DenseMatrix.cpp.

258 {
259 p.reserve(2 * m_nr * m_nc);
260 for(std::size_t row = 0; row < m_nr; ++row) {
261 for(std::size_t col = 0; col < m_nc; ++col) {
262 p.push_back(m_matrix[ row ][ col ].real());
263 p.push_back(m_matrix[ row ][ col ].imag());
264 }
265 for(std::size_t col = 0; col < padding; ++col) {
266 p.push_back(0.0);
267 p.push_back(0.0);
268 }
269 }
270 }

References p.

◆ matrix_to_vector() [5/6]

void CppNoddy::DenseMatrix< double >::matrix_to_vector ( DenseVector< double > &  p,
const std::size_t &  padding 
) const

Definition at line 274 of file DenseMatrix.cpp.

274 {
275 p.reserve(m_nr * m_nc);
276 for(std::size_t row = 0; row < m_nr; ++row) {
277 for(std::size_t col = 0; col < m_nc; ++col) {
278 p.push_back(m_matrix[ row ][ col ]);
279 }
280 for(std::size_t col = 0; col < padding; ++col) {
281 p.push_back(0.0);
282 }
283 }
284 }

References p.

◆ matrix_to_vector() [6/6]

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

◆ max_in_col()

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

172 {
173 row_iter index(row_min);
174 double maxelt(std::abs(*(row_min -> begin())));
175 for(row_iter row = row_min + 1; row != row_max ; ++row) {
176 const double elt(std::abs(*(row -> begin() + col)));
177 if(elt >= maxelt) {
178 maxelt = elt;
179 index = row;
180 }
181 }
182 return index;
183 }
row_iter begin()
Pass through of iterator calls.
Definition: DenseMatrix.h:173
std::vector< DenseVector< _Type > >::iterator row_iter
Typedef iterator types.
Definition: DenseMatrix.h:29

◆ multiply() [1/2]

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

149 {
150#ifdef PARANOID
151 // check number of columns at least match
152 if(B.nrows() != m_nc) {
153 std::string problem("The DenseMatrix.multiply has a geometry error.\n");
154 throw ExceptionGeom(problem, m_nr, m_nc, B.nrows(), B.ncols());
155 }
156#endif
157 // temporary object for the result
158 DenseMatrix<_Type> C(nrows(), B.ncols(), 0.0);
159 // loops thru the columns in the B matrix
160 for(std::size_t col_in_B = 0; col_in_B < B.ncols(); ++col_in_B) {
161 // set the column in the result to be the matrix-vector
162 // product of (*this).multiply( column in B )
163 C.set_col(col_in_B, multiply(B.get_col(col_in_B)));
164 }
165 return C;
166 }
DenseVector< _Type > multiply(const DenseVector< _Type > &x) const
Right multiply the matrix by a DENSE vector.

◆ multiply() [2/2]

template<typename _Type >
DenseVector< _Type > CppNoddy::DenseMatrix< _Type >::multiply ( const DenseVector< _Type > &  x) const

Right multiply the matrix by a DENSE vector.

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

Definition at line 132 of file DenseMatrix.cpp.

132 {
133#ifdef PARANOID
134 // check number of columns at least match
135 if(X.size() != m_nc) {
136 std::string problem("The DenseMatrix.multiply has a geometry error.\n");
137 throw ExceptionGeom(problem, m_nr, m_nc, X.size(), 1);
138 }
139#endif
140 DenseVector<_Type> temp;
141 temp.reserve(m_nr);
142 for(std::size_t row = 0; row < m_nr; ++row) {
143 temp.push_back(Utility::dot(m_matrix[ row ], X));
144 }
145 return temp;
146 }
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:314

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().

◆ ncols()

template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::ncols
inlinevirtual

◆ nelts()

template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::nelts
virtual
Returns
The number of elements

Implements CppNoddy::Sequential_Matrix_base< _Type >.

Definition at line 71 of file DenseMatrix.cpp.

71 {
72 return m_nr * m_nc;
73 }

◆ nrows()

template<typename _Type >
std::size_t CppNoddy::DenseMatrix< _Type >::nrows
inlinevirtual

◆ one_norm()

template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::one_norm

Return the maximum one_norm of all rows.

Definition at line 186 of file DenseMatrix.cpp.

186 {
187 double max(0.0);
188 for(std::size_t row = 0; row < m_nr; ++row) {
189 max = std::max(max, m_matrix[ row ].one_norm());
190 }
191 return max;
192 }
double one_norm() const
Return the maximum one_norm of all rows.

◆ operator()() [1/2]

template<typename _Type >
_Type & CppNoddy::DenseMatrix< _Type >::operator() ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Sequential_Matrix_base< _Type >.

Definition at line 303 of file DenseMatrix.h.

304 {
305#ifdef PARANOID
306 if((row > m_nr) || (row < 0)) {
307 std::string problem("The DenseMatrix.() has a range error.\n");
308 throw ExceptionRange(problem, m_nr, row, m_nc, col);
309 }
310 if((col > m_nc) || (col < 0)) {
311 std::string problem("The DenseMatrix.() has a range error.\n");
312 throw ExceptionRange(problem, m_nr, row, m_nc, col);
313 }
314#endif
315 return m_matrix[ row ][ col ];
316 }

◆ operator()() [2/2]

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::Sequential_Matrix_base< _Type >.

Definition at line 287 of file DenseMatrix.h.

288 {
289#ifdef PARANOID
290 if((row > m_nr) || (row < 0)) {
291 std::string problem("The DenseMatrix.() has a range error.\n");
292 throw ExceptionRange(problem, m_nr, row, m_nc, col);
293 }
294 if((col > m_nc) || (col < 0)) {
295 std::string problem("The DenseMatrix.() has a range error.\n");
296 throw ExceptionRange(problem, m_nr, row, m_nc, col);
297 }
298#endif
299 return m_matrix[ row ][ col ];
300 }

◆ operator*()

template<typename _Type >
DenseMatrix< _Type > CppNoddy::DenseMatrix< _Type >::operator* ( const double &  m) const
inline

SIMD operator sugar.

Definition at line 101 of file DenseMatrix.h.

101 {
102 DenseMatrix<_Type> temp(*this);
103 temp.scale(m);
104 return temp;
105 }

References m, and CppNoddy::DenseMatrix< _Type >::scale().

◆ operator+()

template<typename _Type >
DenseMatrix< _Type > CppNoddy::DenseMatrix< _Type >::operator+ ( const DenseMatrix< _Type > &  A) const
inline

Definition at line 106 of file DenseMatrix.h.

106 {
107 DenseMatrix<_Type> temp(*this);
108 for(std::size_t row = 0; row < m_nr; ++row) {
109 for(std::size_t col = 0; col < m_nc; ++col) {
110 temp(row, col) += A(row, col);
111 }
112 }
113 return temp;
114 }
double A(1.0)
initial hump amplitude

◆ operator-()

template<typename _Type >
DenseMatrix< _Type > CppNoddy::DenseMatrix< _Type >::operator- ( const DenseMatrix< _Type > &  A) const
inline

Definition at line 115 of file DenseMatrix.h.

115 {
116 DenseMatrix<_Type> temp(*this);
117 for(std::size_t row = 0; row < m_nr; ++row) {
118 for(std::size_t col = 0; col < m_nc; ++col) {
119 temp(row, col) -= A(row, col);
120 }
121 }
122 return temp;
123 }

◆ operator=()

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

61 {
62 if(this == &source)
63 return * this;
64 m_matrix = source.m_matrix;
65 m_nr = source.m_nr;
66 m_nc = source.m_nc;
67 return *this;
68 }

◆ operator[]() [1/2]

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 353 of file DenseMatrix.h.

353 {
354#ifdef PARANOID
355 if((row > m_nr) || (row < 0)) {
356 std::string problem("The DenseMatrix.get_row has a range error.\n");
357 throw ExceptionRange(problem, m_nr, row);
358 }
359#endif
360 return m_matrix[ row ];
361 }

◆ operator[]() [2/2]

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 364 of file DenseMatrix.h.

364 {
365#ifdef PARANOID
366 if((row > m_nr) || (row < 0)) {
367 std::string problem("The DenseMatrix.get_row has a range error.\n");
368 throw ExceptionRange(problem, m_nr, row);
369 }
370#endif
371 return m_matrix[ row ];
372 }

◆ rbegin() [1/2]

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 185 of file DenseMatrix.h.

185 {
186 return m_matrix.rbegin();
187 }

◆ rbegin() [2/2]

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 209 of file DenseMatrix.h.

209 {
210 return m_matrix.rbegin();
211 }

◆ rend() [1/2]

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 191 of file DenseMatrix.h.

191 {
192 return m_matrix.rend();
193 }

◆ rend() [2/2]

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 215 of file DenseMatrix.h.

215 {
216 return m_matrix.rend();
217 }

◆ scale()

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::Sequential_Matrix_base< _Type >.

Definition at line 100 of file DenseMatrix.cpp.

100 {
101 std::transform(m_matrix.begin(), m_matrix.end(), m_matrix.begin(), scale_functor< DenseVector<_Type>, _Type >(mult));
102 }

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

◆ set()

template<typename _Type >
_Type & CppNoddy::DenseMatrix< _Type >::set ( const std::size_t &  row,
const std::size_t &  col 
)
inlinevirtual

Access operator.

Implements CppNoddy::Sequential_Matrix_base< _Type >.

Definition at line 336 of file DenseMatrix.h.

338 {
339#ifdef PARANOID
340 if((row > m_nr) || (row < 0)) {
341 std::string problem("The DenseMatrix.set has a range error.\n");
342 throw ExceptionRange(problem, m_nr, row, m_nc, col);
343 }
344 if((col > m_nc) || (col < 0)) {
345 std::string problem("The DenseMatrix.set has a range error.\n");
346 throw ExceptionRange(problem, m_nr, row, m_nc, col);
347 }
348#endif
349 return m_matrix[ row ][ col ];
350 }

◆ set_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 242 of file DenseMatrix.cpp.

242 {
243 for(std::size_t row = 0; row < m_nr; ++row) {
244 m_matrix[ row ][ col ] = X[ row ];
245 }
246 }

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(), and CppNoddy::Residual< _Type >::jacobian().

◆ sub()

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

88 {
89#ifdef PARANOID
90 // check number of columns at least match
91 if((B.nrows() != m_nr) || (B.ncols() != m_nc)) {
92 std::string problem("The DenseMatrix.sub has a geometry error.\n");
93 throw ExceptionGeom(problem, m_nr, m_nc, B.nrows(), B.ncols());
94 }
95#endif
96 std::transform(m_matrix.begin(), m_matrix.end(), B.m_matrix.begin(), m_matrix.begin(), std::minus< DenseVector<_Type> >());
97 }

Referenced by main().

◆ transpose()

template<typename _Type >
void CppNoddy::DenseMatrix< _Type >::transpose

Transpose the matrix.

Definition at line 105 of file DenseMatrix.cpp.

105 {
106 if(nrows() == ncols()) {
107 // square matrix needs no temp object
108 // loop through upper half diagonal of the matrix
109 for(std::size_t i = 0; i < nrows(); ++i) {
110 for(std::size_t j = i + 1; j < ncols(); ++j) {
111 // swap elements
112 std::swap(m_matrix[ i ][ j ], m_matrix[ j ][ i ]);
113 }
114 }
115 } else {
116 std::vector< DenseVector<_Type> > temp;
117 temp.resize(m_nc);
118 for(std::size_t row = 0; row < m_nc; ++row) {
119 temp[ row ].resize(m_nr);
120 }
121 for(std::size_t i = 0; i < nrows(); ++i) {
122 for(std::size_t j = 0; j < ncols(); ++j) {
123 temp[ j ][ i ] = m_matrix[ i ][ j ];
124 }
125 }
126 m_matrix = temp;
127 std::swap(m_nr, m_nc);
128 }
129 }

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

◆ two_norm()

template<typename _Type >
double CppNoddy::DenseMatrix< _Type >::two_norm

Rreturn the maximum two_norm of all rows.

Definition at line 195 of file DenseMatrix.cpp.

195 {
196 double max(0.0);
197 for(std::size_t row = 0; row < m_nr; ++row) {
198 max = std::max(max, m_matrix[ row ].two_norm());
199 }
200 return max;
201 }
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