From 183b44215c262586a97a649eb640da8f0c6a700e Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 12 Feb 2013 17:03:38 +0000 Subject: [PATCH] Follow the documented advice of not looping over all elements of a matrix but do so row by row. git-svn-id: https://svn.dealii.org/trunk@28333 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/lac/lapack_full_matrix.h | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/deal.II/include/deal.II/lac/lapack_full_matrix.h b/deal.II/include/deal.II/lac/lapack_full_matrix.h index fa6636a912..74ae45cef1 100644 --- a/deal.II/include/deal.II/lac/lapack_full_matrix.h +++ b/deal.II/include/deal.II/lac/lapack_full_matrix.h @@ -705,10 +705,17 @@ inline void LAPACKFullMatrix::copy_from (const MATRIX &M) { this->reinit (M.m(), M.n()); - const typename MATRIX::const_iterator end = M.end(); - for (typename MATRIX::const_iterator entry = M.begin(); - entry != end; ++entry) - this->el(entry->row(), entry->column()) = entry->value(); + + // loop over the elements of the argument matrix row by row, as suggested + // in the documentation of the sparse matrix iterator class, and + // copy them into the current object + for (unsigned int row = 0; row < M.n(); ++row) + { + const typename MATRIX::const_iterator end_row = M.end(row); + for (typename MATRIX::const_iterator entry = M.begin(row); + entry != end_row; ++entry) + this->el(row, entry->column()) = entry->value(); + } state = LAPACKSupport::matrix; } @@ -727,17 +734,22 @@ LAPACKFullMatrix::fill ( const number factor, const bool transpose) { - const typename MATRIX::const_iterator end = M.end(); - for (typename MATRIX::const_iterator entry = M.begin(src_offset_i); - entry != end; ++entry) + // loop over the elements of the argument matrix row by row, as suggested + // in the documentation of the sparse matrix iterator class + for (unsigned int row = src_offset_i; row < M.n(); ++row) { - const unsigned int i = transpose ? entry->column() : entry->row(); - const unsigned int j = transpose ? entry->row() : entry->column(); - - const unsigned int dst_i=dst_offset_i+i-src_offset_i; - const unsigned int dst_j=dst_offset_j+j-src_offset_j; - if (dst_in_rows() && dst_jn_cols()) - (*this)(dst_i, dst_j) = factor * entry->value(); + const typename MATRIX::const_iterator end_row = M.end(row); + for (typename MATRIX::const_iterator entry = M.begin(row); + entry != end_row; ++entry) + { + const unsigned int i = transpose ? entry->column() : row; + const unsigned int j = transpose ? row : entry->column(); + + const unsigned int dst_i=dst_offset_i+i-src_offset_i; + const unsigned int dst_j=dst_offset_j+j-src_offset_j; + if (dst_in_rows() && dst_jn_cols()) + (*this)(dst_i, dst_j) = factor * entry->value(); + } } state = LAPACKSupport::matrix; -- 2.39.5