[PPL-devel] [GIT] ppl/ppl(sparse_matrices): MIP_Problem: optimize find_create() calls in linear_combine().

Marco Poletti poletti.marco at gmail.com
Mon Mar 22 13:02:32 CET 2010


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

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

MIP_Problem: optimize find_create() calls in linear_combine().

---

 src/MIP_Problem.cc |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/MIP_Problem.cc b/src/MIP_Problem.cc
index db51352..95ef74a 100644
--- a/src/MIP_Problem.cc
+++ b/src/MIP_Problem.cc
@@ -1202,8 +1202,14 @@ PPL::MIP_Problem::linear_combine(matrix_row_reference_type x,
     if (j->first < i->first) {
       if (j->first != k) {
         // FIXME: check if adding "if (j->second != 0)" speeds this up.
-        last_i = x.find_create(j->first);
+
+        // The following statements are equivalent to
+        // sub_mul_assign(x[j->first], j->second, normalized_x_k);
+        last_i = x.find_create(*j);
         Coefficient& x_i = (*last_i).second;
+        x_i *= normalized_x_k;
+        neg_assign(x_i);
+
 #ifdef PPL_SPARSE_BACKEND_INVALIDATES_REFERENCES
         i = last_i;
         ++i;
@@ -1212,11 +1218,6 @@ PPL::MIP_Problem::linear_combine(matrix_row_reference_type x,
         // Here we had (j->first < i->first) therefore (&x != &y) .
         PPL_ASSERT(& static_cast<matrix_row_const_reference_type>(x) != &y);
 #endif
-        PPL_ASSERT(x_i == 0);
-        // sub_mul_assign(x_i, j->second, normalized_x_k);
-        x_i = j->second;
-        x_i *= normalized_x_k;
-        neg_assign(x_i);
 
         ++j;
         break;
@@ -1245,8 +1246,14 @@ PPL::MIP_Problem::linear_combine(matrix_row_reference_type x,
     if (j->first < i->first) {
       if (j->first != k) {
         // FIXME: check if adding "if (j->second != 0)" speeds this up.
-        last_i = x.find_create(j->first, Coefficient_zero(), last_i);
+
+        // The following statements are equivalent to
+        // sub_mul_assign(x[j->first], j->second, normalized_x_k);
+        last_i = x.find_create(*j, last_i);
         Coefficient& x_i = (*last_i).second;
+        x_i *= normalized_x_k;
+        neg_assign(x_i);
+
 #ifdef PPL_SPARSE_BACKEND_INVALIDATES_REFERENCES
         i = last_i;
         ++i;
@@ -1255,11 +1262,6 @@ PPL::MIP_Problem::linear_combine(matrix_row_reference_type x,
         // Here we had (j->first < i->first) therefore (&x != &y) .
         PPL_ASSERT(& static_cast<matrix_row_const_reference_type>(x) != &y);
 #endif
-        PPL_ASSERT(x_i == 0);
-        // sub_mul_assign(x_i, j->second, normalized_x_k);
-        x_i = j->second;
-        x_i *= normalized_x_k;
-        neg_assign(x_i);
       }
       ++j;
     } else {
@@ -1285,11 +1287,11 @@ PPL::MIP_Problem::linear_combine(matrix_row_reference_type x,
   while (j != j_end) {
     if (j->first != k) {
       // FIXME: check if adding "if (j->second != 0)" speeds this up.
-      last_i = x.find_create(j->first, Coefficient_zero(), last_i);
+
+      // The following statements are equivalent to
+      // sub_mul_assign(x[j->first], j->second, normalized_x_k);
+      last_i = x.find_create(*j, last_i);
       Coefficient& x_i = (*last_i).second;
-      PPL_ASSERT(x_i == 0);
-      // sub_mul_assign(x_i, j->second, normalized_x_k);
-      x_i = j->second;
       x_i *= normalized_x_k;
       neg_assign(x_i);
     }




More information about the PPL-devel mailing list