From: Wolfgang Bangerth Date: Tue, 12 Feb 2013 16:09:54 +0000 (+0000) Subject: Follow the documented advice of not looping over all elements of a matrix but do... X-Git-Tag: v8.0.0~1355 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c617cbc747914c9bb223fc67834cd434f88f8e3;p=dealii.git 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@28330 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/full_matrix.h b/deal.II/include/deal.II/lac/full_matrix.h index 6a2854ef91..6fab9285d2 100644 --- a/deal.II/include/deal.II/lac/full_matrix.h +++ b/deal.II/include/deal.II/lac/full_matrix.h @@ -1520,10 +1520,17 @@ void FullMatrix::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(); + } } @@ -1534,10 +1541,17 @@ void FullMatrix::copy_transposed (const MATRIX &M) { this->reinit (M.n(), M.m()); - const typename MATRIX::const_iterator end = M.end(); - for (typename MATRIX::const_iterator entry = M.begin(); - entry != end; ++entry) - this->el(entry->column(), entry->row()) = 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(entry->column(), row) = entry->value(); + } }