From f555da41654e6c39e4ba3d86bc4ed0fee7c93344 Mon Sep 17 00:00:00 2001 From: Sebastian Buchwald Date: Mon, 26 Jul 2010 06:14:17 +0000 Subject: [PATCH] Avoid unnecessary initialization of new matrix (especially in cases where mapping is not set properly). [r27811] --- optimal.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/optimal.c b/optimal.c index cb4ef75fe..7969b373c 100644 --- 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]; } } -- 2.20.1