[PPL-devel] [GIT] ppl/ppl(sparse_matrices): PIP_Tree_Node: fix regression in add_constraint() introduced by commit 1341d3.
Marco Poletti
poletti.marco at gmail.com
Tue Mar 16 13:48:07 CET 2010
Module: ppl/ppl
Branch: sparse_matrices
Commit: 1b2c6d7c1d7d7f9ec3f03a754ff9f64d29a7190a
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=1b2c6d7c1d7d7f9ec3f03a754ff9f64d29a7190a
Author: Marco Poletti <poletti.marco at gmail.com>
Date: Mon Mar 15 23:25:49 2010 +0100
PIP_Tree_Node: fix regression in add_constraint() introduced by commit 1341d3.
---
src/PIP_Tree.cc | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc
index 8e470b2..d977181 100644
--- a/src/PIP_Tree.cc
+++ b/src/PIP_Tree.cc
@@ -1158,20 +1158,22 @@ PIP_Tree_Node
// Compute the expression for the parameter constraint.
Linear_Expression expr = Linear_Expression(row.get(0));
- // Needed to avoid reallocations in expr when iterating upward.
- add_mul_assign(expr, 0, Variable(num_params));
Variables_Set::const_iterator j = parameters.begin();
- // The number of increments of j plus one.
- dimension_type j_index = 1;
- matrix_const_row_const_iterator i = row.lower_bound(1);
- matrix_const_row_const_iterator i_end = row.end();
- // NOTE: iterating in [1..num_params].
- for ( ; i!=i_end; ++i) {
- if ((*i).first > num_params)
- break;
- std::advance(j,(*i).first-j_index);
- j_index = (*i).first;
- add_mul_assign(expr, (*i).second, Variable(*j));
+ if (!parameters.empty()) {
+ // Needed to avoid reallocations in expr when iterating upward.
+ add_mul_assign(expr, 0, Variable(*(parameters.rbegin())));
+ // The number of increments of j plus one.
+ dimension_type j_index = 1;
+ matrix_const_row_const_iterator i = row.lower_bound(1);
+ matrix_const_row_const_iterator i_end = row.end();
+ // NOTE: iterating in [1..num_params].
+ for ( ; i!=i_end; ++i) {
+ if ((*i).first > num_params)
+ break;
+ std::advance(j,(*i).first-j_index);
+ j_index = (*i).first;
+ add_mul_assign(expr, (*i).second, Variable(*j));
+ }
}
// Add the parameter constraint.
constraints_.insert(expr >= 0);
More information about the PPL-devel
mailing list