From 548217283fd84f7b9eef0598c3acd9285ec97547 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 12 Feb 2013 16:09:54 +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@28330 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/lac/full_matrix.h | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) 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(); + } } -- 2.39.5