Avoid unnecessary initialization of new matrix (especially in cases where mapping...
authorSebastian Buchwald <Sebastian.Buchwald@kit.edu>
Mon, 26 Jul 2010 06:14:17 +0000 (06:14 +0000)
committerSebastian Buchwald <Sebastian.Buchwald@kit.edu>
Mon, 26 Jul 2010 06:14:17 +0000 (06:14 +0000)
[r27811]

optimal.c

index cb4ef75..7969b37 100644 (file)
--- a/optimal.c
+++ b/optimal.c
@@ -339,6 +339,7 @@ static void merge_source_into_target(pbqp *pbqp, pbqp_edge *edge)
                pbqp_matrix *old_matrix;
                pbqp_matrix *new_matrix;
                pbqp_node   *other_node;
+               vector      *other_vec;
                unsigned     other_len;
                unsigned     other_index;
                unsigned     tgt_index;
@@ -360,6 +361,7 @@ static void merge_source_into_target(pbqp *pbqp, pbqp_edge *edge)
                        other_len = old_matrix->cols;
                }
                assert(other_node);
+               other_vec = other_node->costs;
 
                new_matrix = pbqp_matrix_alloc(pbqp, tgt_len, other_len);
 
@@ -368,7 +370,13 @@ static void merge_source_into_target(pbqp *pbqp, pbqp_edge *edge)
                        for (tgt_index = 0; tgt_index < tgt_len; ++tgt_index) {
                                unsigned src_index = mapping[tgt_index];
 
+                               if (tgt_vec->entries[tgt_index].data == INF_COSTS)
+                                       continue;
+
                                for (other_index = 0; other_index < other_len; ++other_index) {
+                                       if (other_vec->entries[other_index].data == INF_COSTS)
+                                               continue;
+
                                        new_matrix->entries[tgt_index*other_len+other_index] = old_matrix->entries[other_index*src_len+src_index];
                                }
                        }
@@ -378,7 +386,13 @@ static void merge_source_into_target(pbqp *pbqp, pbqp_edge *edge)
                        for (tgt_index = 0; tgt_index < tgt_len; ++tgt_index) {
                                unsigned src_index = mapping[tgt_index];
 
+                               if (tgt_vec->entries[tgt_index].data == INF_COSTS)
+                                       continue;
+
                                for (other_index = 0; other_index < other_len; ++other_index) {
+                                       if (other_vec->entries[other_index].data == INF_COSTS)
+                                               continue;
+
                                        new_matrix->entries[tgt_index*other_len+other_index] = old_matrix->entries[src_index*other_len+other_index];
                                }
                        }
@@ -482,6 +496,7 @@ static void merge_target_into_source(pbqp *pbqp, pbqp_edge *edge)
                pbqp_matrix *old_matrix;
                pbqp_matrix *new_matrix;
                pbqp_node   *other_node;
+               vector      *other_vec;
                unsigned     other_len;
                unsigned     other_index;
                unsigned     src_index;
@@ -503,6 +518,7 @@ static void merge_target_into_source(pbqp *pbqp, pbqp_edge *edge)
                        other_len = old_matrix->cols;
                }
                assert(other_node);
+               other_vec = other_node->costs;
 
                new_matrix = pbqp_matrix_alloc(pbqp, src_len, other_len);
 
@@ -511,7 +527,13 @@ static void merge_target_into_source(pbqp *pbqp, pbqp_edge *edge)
                        for (src_index = 0; src_index < src_len; ++src_index) {
                                unsigned tgt_index = mapping[src_index];
 
+                               if (src_vec->entries[src_index].data == INF_COSTS)
+                                       continue;
+
                                for (other_index = 0; other_index < other_len; ++other_index) {
+                                       if (other_vec->entries[other_index].data == INF_COSTS)
+                                               continue;
+
                                        new_matrix->entries[src_index*other_len+other_index] = old_matrix->entries[other_index*tgt_len+tgt_index];
                                }
                        }
@@ -521,7 +543,13 @@ static void merge_target_into_source(pbqp *pbqp, pbqp_edge *edge)
                        for (src_index = 0; src_index < src_len; ++src_index) {
                                unsigned tgt_index = mapping[src_index];
 
+                               if (src_vec->entries[src_index].data == INF_COSTS)
+                                       continue;
+
                                for (other_index = 0; other_index < other_len; ++other_index) {
+                                       if (other_vec->entries[other_index].data == INF_COSTS)
+                                               continue;
+
                                        new_matrix->entries[src_index*other_len+other_index] = old_matrix->entries[tgt_index*other_len+other_index];
                                }
                        }