From 96c6dc375e70855a31f8d104fa574c8d1cc17ff8 Mon Sep 17 00:00:00 2001 From: Joris Mooij Date: Sun, 16 Aug 2009 18:12:35 +0200 Subject: [PATCH] [Patrick Pletscher] Fixed performance issue in FactorGraph::clamp and FactorGraph::clampVar --- src/factorgraph.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/factorgraph.cpp b/src/factorgraph.cpp index d8b9fea..e49ee5e 100644 --- a/src/factorgraph.cpp +++ b/src/factorgraph.cpp @@ -319,11 +319,9 @@ void FactorGraph::clamp( const Var & n, size_t i, bool backup ) { delta_n_i[i] = 1.0; map newFacs; - // For all factors that contain n - for( size_t I = 0; I < nrFactors(); I++ ) - if( factor(I).vars().contains( n ) ) - // Multiply it with a delta function - newFacs[I] = factor(I) * delta_n_i; + size_t n_index = findVar(n); + foreach( const BipartiteGraph::Neighbor &I, nbV(n_index) ) + newFacs[I] = factor(I) * delta_n_i; setFactors( newFacs, backup ); return; @@ -340,10 +338,9 @@ void FactorGraph::clampVar( size_t i, const vector &is, bool backup ) { } map newFacs; - for( size_t I = 0; I < nrFactors(); I++ ) - if( factor(I).vars().contains( n ) ) { - newFacs[I] = factor(I) * mask_n; - } + size_t n_index = findVar(n); + foreach( const BipartiteGraph::Neighbor &I, nbV(n_index) ) + newFacs[I] = factor(I) * mask_n; setFactors( newFacs, backup ); } -- 2.20.1