16 template <
typename _Type>
20 template <
typename _Type>
22 const std::size_t& cols,
30 m_matrix.reserve(rows);
31 for(std::size_t i = 0; i < rows; ++i) {
33 m_matrix.push_back(row);
37 template <
typename _Type>
39 const std::size_t& cols,
44 m_matrix.reserve(rows);
45 for(std::size_t i = 0; i < rows; ++i) {
50 template <
typename _Type>
56 template <
typename _Type>
60 template <
typename _Type>
64 m_matrix = source.m_matrix;
70 template <
typename _Type>
75 template <
typename _Type>
79 if((B.
nrows() != m_nr) || (B.
ncols() != m_nc)) {
80 std::string problem(
"The DenseMatrix.add has a geometry error.\n");
84 std::transform(m_matrix.begin(), m_matrix.end(), B.m_matrix.begin(), m_matrix.begin(), std::plus<
DenseVector<_Type> >());
87 template <
typename _Type>
91 if((B.
nrows() != m_nr) || (B.
ncols() != m_nc)) {
92 std::string problem(
"The DenseMatrix.sub has a geometry error.\n");
96 std::transform(m_matrix.begin(), m_matrix.end(), B.m_matrix.begin(), m_matrix.begin(), std::minus<
DenseVector<_Type> >());
99 template <
typename _Type>
104 template <
typename _Type>
106 if(nrows() == ncols()) {
109 for(std::size_t i = 0; i < nrows(); ++i) {
110 for(std::size_t j = i + 1; j < ncols(); ++j) {
112 std::swap(m_matrix[ i ][ j ], m_matrix[ j ][ i ]);
116 std::vector< DenseVector<_Type> > temp;
118 for(std::size_t row = 0; row < m_nc; ++row) {
119 temp[ row ].resize(m_nr);
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 ];
127 std::swap(m_nr, m_nc);
131 template <
typename _Type>
135 if(X.
size() != m_nc) {
136 std::string problem(
"The DenseMatrix.multiply has a geometry error.\n");
142 for(std::size_t row = 0; row < m_nr; ++row) {
148 template <
typename _Type>
152 if(B.
nrows() != m_nc) {
153 std::string problem(
"The DenseMatrix.multiply has a geometry error.\n");
160 for(std::size_t col_in_B = 0; col_in_B < B.
ncols(); ++col_in_B) {
163 C.set_col(col_in_B, multiply(B.
get_col(col_in_B)));
169 template <
typename _Type>
170 typename std::vector<DenseVector<_Type> >::iterator
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)));
185 template <
typename _Type>
188 for(std::size_t row = 0; row < m_nr; ++row) {
189 max = std::max(max, m_matrix[ row ].one_norm());
194 template <
typename _Type>
197 for(std::size_t row = 0; row < m_nr; ++row) {
198 max = std::max(max, m_matrix[ row ].two_norm());
203 template <
typename _Type>
206 for(std::size_t row = 0; row < m_nr; ++row) {
207 max = std::max(max, m_matrix[ row ].inf_norm());
212 template <
typename _Type>
215 for(std::size_t row = 0; row < m_nr; ++row) {
216 sum += m_matrix[ row ].two_norm();
222 template <
typename _Type>
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);
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 ] <<
", ";
238 std::cout <<
"- end matrix \n";
241 template <
typename _Type>
243 for(std::size_t row = 0; row < m_nr; ++row) {
244 m_matrix[ row ][ col ] = X[ row ];
248 template <
typename _Type>
251 for(std::size_t row = 0; row < m_nr; ++row) {
252 X[ row ] = m_matrix[ row ][ col ];
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());
265 for(std::size_t col = 0; col < padding; ++col) {
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 ]);
280 for(std::size_t col = 0; col < padding; ++col) {
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 ]);
294 for(std::size_t col = 0; col < padding; ++col) {
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());
310 for(std::size_t col = 0; col < padding; ++col) {
A matrix class that constructs a DENSE matrix as an STL Vector of DenseVectors.
Specification for a templated DenseVector class – a dense, dynamic, vector object.
The collection of CppNoddy exceptions.
Some Function Objects that CppNoddy makes use of in algorithms applied to STL containers.
A spec for a collection of utility functions.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
std::size_t nelts() const
void dump() const
Output the matrix to std::cout.
double one_norm() const
Return the maximum one_norm of all rows.
DenseMatrix & operator=(const DenseMatrix &source)
Assignment operator.
std::size_t nrows() const
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.
void set_col(const std::size_t &col, const DenseVector< _Type > &x)
Set a column of the matrix.
DenseVector< double > matrix_to_vector(const std::size_t &padding=0) const
Conversion to contiguous data in row major format Inefficient ... the void method is preferred.
std::vector< DenseVector< _Type > >::iterator row_iter
Typedef iterator types.
DenseVector< _Type > multiply(const DenseVector< _Type > &x) const
Right multiply the matrix by a DENSE vector.
void transpose()
Transpose the matrix.
double frob_norm() const
Return the sum of the two_norm of all rows.
DenseVector< _Type > get_col(const std::size_t &col) const
Get a column of the matrix.
void add(const DenseMatrix< _Type > &b)
Add a DENSE matrix to this object.
double inf_norm() const
Return the maximum inf_norm of all rows.
void scale(const _Type &mult)
Scale all matrix elements by a scalar.
void sub(const DenseMatrix< _Type > &b)
Subtract a DENSE matrix from this object.
DenseMatrix()
Allow empty construction.
double two_norm() const
Rreturn the maximum two_norm of all rows.
std::size_t ncols() const
An DenseVector class – a dense vector object.
void push_back(const _Type &fill)
A pass-thru definition of push_back.
void reserve(const std::size_t &n)
Reserve space for the vector.
std::size_t size() const
A pass-thru definition to get the size of the vector.
An exception class to be thrown when a container of incorrect geometry used in any class/method.
A base matrix class for sequential matrices.
A unary pure function object that scales through multiplication.
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...