]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Follow the documented advice of not looping over all elements of a matrix but do...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 12 Feb 2013 17:03:38 +0000 (17:03 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 12 Feb 2013 17:03:38 +0000 (17:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@28333 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/lapack_full_matrix.h

index fa6636a912c65163751dc9d40a14308ae586cea3..74ae45cef1ca79a3c3ba2a7ced10bcbaa7a853cd 100644 (file)
@@ -705,10 +705,17 @@ inline void
 LAPACKFullMatrix<number>::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<number>::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_i<this->n_rows() && dst_j<this->n_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_i<this->n_rows() && dst_j<this->n_cols())
+            (*this)(dst_i, dst_j) = factor * entry->value();
+        }
     }
 
   state = LAPACKSupport::matrix;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.