[PPL-devel] [GIT] ppl/ppl(sparse_matrices): Unlimited_Sparse_Row_Over_CO_Tree: un-inline normalize() method.

Marco Poletti poletti.marco at gmail.com
Thu Apr 15 07:38:30 CEST 2010


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

Author: Marco Poletti <poletti.marco at gmail.com>
Date:   Thu Apr 15 07:26:41 2010 +0200

Unlimited_Sparse_Row_Over_CO_Tree: un-inline normalize() method.

---

 src/Unlimited_Sparse_Row_Over_CO_Tree.cc         |   50 ++++++++++++++++++++++
 src/Unlimited_Sparse_Row_Over_CO_Tree.inlines.hh |   49 ---------------------
 2 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/src/Unlimited_Sparse_Row_Over_CO_Tree.cc b/src/Unlimited_Sparse_Row_Over_CO_Tree.cc
index 40d2ec8..5d2d708 100644
--- a/src/Unlimited_Sparse_Row_Over_CO_Tree.cc
+++ b/src/Unlimited_Sparse_Row_Over_CO_Tree.cc
@@ -70,3 +70,53 @@ PPL::Unlimited_Sparse_Row_Over_CO_Tree
   PPL_ASSERT(OK());
   return true;
 }
+
+inline void
+PPL::Unlimited_Sparse_Row_Over_CO_Tree::normalize() {
+  // Compute the GCD of all the coefficients.
+  const_iterator i = begin();
+  const const_iterator i_end = end();
+  PPL_DIRTY_TEMP_COEFFICIENT(gcd);
+  for ( ; i != i_end; ++i) {
+    const Coefficient& x_i = i->second;
+    if (const int x_i_sign = sgn(x_i)) {
+      // FIXME: can this be optimized further?
+      gcd = x_i;
+      if (x_i_sign < 0)
+        neg_assign(gcd);
+      goto compute_gcd;
+    }
+  }
+  // We reach this point only if all the coefficients were zero.
+  return;
+
+ compute_gcd:
+  if (gcd == 1)
+    return;
+  for (++i; i != i_end; ++i) {
+    const Coefficient& x_i = i->second;
+    if (x_i != 0) {
+      // Note: we use the ternary version instead of a more concise
+      // gcd_assign(gcd, x_i) to take advantage of the fact that
+      // `gcd' will decrease very rapidly (see D. Knuth, The Art of
+      // Computer Programming, second edition, Section 4.5.2,
+      // Algorithm C, and the discussion following it).  Our
+      // implementation of gcd_assign(x, y, z) for checked numbers is
+      // optimized for the case where `z' is smaller than `y', so that
+      // on checked numbers we gain.  On the other hand, for the
+      // implementation of gcd_assign(x, y, z) on GMP's unbounded
+      // integers we cannot make any assumption, so here we draw.
+      // Overall, we win.
+      gcd_assign(gcd, x_i, gcd);
+      if (gcd == 1)
+        return;
+    }
+  }
+  // Divide the coefficients by the GCD.
+  for (iterator j = begin(), j_end = end(); j != j_end; ++j) {
+    Coefficient& x_j = j->second;
+    exact_div_assign(x_j, x_j, gcd);
+  }
+  PPL_ASSERT(OK());
+}
+
diff --git a/src/Unlimited_Sparse_Row_Over_CO_Tree.inlines.hh b/src/Unlimited_Sparse_Row_Over_CO_Tree.inlines.hh
index 2bb60b3..65a6020 100644
--- a/src/Unlimited_Sparse_Row_Over_CO_Tree.inlines.hh
+++ b/src/Unlimited_Sparse_Row_Over_CO_Tree.inlines.hh
@@ -408,55 +408,6 @@ Unlimited_Sparse_Row_Over_CO_Tree::add_zeroes_and_shift(dimension_type n,
 }
 
 inline void
-Unlimited_Sparse_Row_Over_CO_Tree::normalize() {
-  // Compute the GCD of all the coefficients.
-  const_iterator i = begin();
-  const const_iterator i_end = end();
-  PPL_DIRTY_TEMP_COEFFICIENT(gcd);
-  for ( ; i != i_end; ++i) {
-    const Coefficient& x_i = i->second;
-    if (const int x_i_sign = sgn(x_i)) {
-      // FIXME: can this be optimized further?
-      gcd = x_i;
-      if (x_i_sign < 0)
-        neg_assign(gcd);
-      goto compute_gcd;
-    }
-  }
-  // We reach this point only if all the coefficients were zero.
-  return;
-
- compute_gcd:
-  if (gcd == 1)
-    return;
-  for (++i; i != i_end; ++i) {
-    const Coefficient& x_i = i->second;
-    if (x_i != 0) {
-      // Note: we use the ternary version instead of a more concise
-      // gcd_assign(gcd, x_i) to take advantage of the fact that
-      // `gcd' will decrease very rapidly (see D. Knuth, The Art of
-      // Computer Programming, second edition, Section 4.5.2,
-      // Algorithm C, and the discussion following it).  Our
-      // implementation of gcd_assign(x, y, z) for checked numbers is
-      // optimized for the case where `z' is smaller than `y', so that
-      // on checked numbers we gain.  On the other hand, for the
-      // implementation of gcd_assign(x, y, z) on GMP's unbounded
-      // integers we cannot make any assumption, so here we draw.
-      // Overall, we win.
-      gcd_assign(gcd, x_i, gcd);
-      if (gcd == 1)
-        return;
-    }
-  }
-  // Divide the coefficients by the GCD.
-  for (iterator j = begin(), j_end = end(); j != j_end; ++j) {
-    Coefficient& x_j = j->second;
-    exact_div_assign(x_j, x_j, gcd);
-  }
-  PPL_ASSERT(OK());
-}
-
-inline void
 Unlimited_Sparse_Row_Over_CO_Tree::assign(dimension_type i,
                                           const Coefficient& x) {
   if (tree.empty())




More information about the PPL-devel mailing list