[PPL-devel] [GIT] ppl/ppl(sparse_matrices): PIP_Tree.cc: fix and optimize merge_assign( ).

Marco Poletti poletti.marco at gmail.com
Mon Mar 22 21:46:54 CET 2010


Module: ppl/ppl
Branch: sparse_matrices
Commit: f4b385706bf8e72fabe551b7a83c6ec5fecddfce
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=f4b385706bf8e72fabe551b7a83c6ec5fecddfce

Author: Marco Poletti <poletti.marco at gmail.com>
Date:   Mon Mar 22 21:47:02 2010 +0100

PIP_Tree.cc: fix and optimize merge_assign().

---

 src/PIP_Tree.cc |   36 ++++++++++++++++++------------------
 1 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc
index 0b2963b..a1d72e4 100644
--- a/src/PIP_Tree.cc
+++ b/src/PIP_Tree.cc
@@ -377,31 +377,31 @@ merge_assign(PIP_Tree_Node::matrix_type& x,
     PPL_ASSERT(y_i->is_nonstrict_inequality());
     PIP_Tree_Node::matrix_row_reference_type x_i = x[i];
     const Coefficient& inhomogeneous_term = y_i->inhomogeneous_term();
-    x_i.assign_if_nonzero(0, inhomogeneous_term);
-    Variables_Set::const_iterator pj;
+    PIP_Tree_Node::matrix_row_iterator itr = x_i.end();
+    Variables_Set::const_iterator pj = parameters.begin();
     dimension_type j = 1;
-    PIP_Tree_Node::matrix_row_iterator last = x_i.begin();
-    for (pj = param_begin; pj != param_end; ++pj, ++j) {
-      Variable vj(*pj);
-      if (vj.space_dimension() > cs_space_dim)
-        break;
-      const Coefficient& c = y_i->coefficient(vj);
-      if (c != 0) {
-        last = x_i.find_create(j, c);
-        ++pj;
-        ++j;
-        break;
+    if (inhomogeneous_term != 0)
+      itr = x_i.find_create(0, inhomogeneous_term);
+    else
+      if (pj != param_end) {
+        Variable vj(*pj);
+        if (vj.space_dimension() <= cs_space_dim) {
+          const Coefficient& c = y_i->coefficient(vj);
+          if (c != 0) {
+            itr = x_i.find_create(j, c);
+            ++pj;
+            ++j;
+          }
+        }
       }
-    }
+    PPL_ASSERT(pj == param_end || itr != x_i.end());
     for ( ; pj != param_end; ++pj, ++j) {
       Variable vj(*pj);
       if (vj.space_dimension() > cs_space_dim)
         break;
       const Coefficient& c = y_i->coefficient(vj);
-      if (c != 0) {
-        last = x_i.find_create(j, c, last);
-        break;
-      }
+      if (c != 0)
+        itr = x_i.find_create(j, c, itr);
     }
   }
 }




More information about the PPL-devel mailing list