From 6165a7852d01439d20ed5ee1814798863a3d5bf7 Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 31 Aug 2010 01:56:56 +0000 Subject: l2r bugfixes git-svn-id: https://ws10smt.googlecode.com/svn/trunk@635 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/apply_fsa_models.cc | 7 ++++--- decoder/hg.h | 3 +++ decoder/inside_outside.h | 2 +- decoder/viterbi.h | 2 ++ utils/agenda.h | 1 + utils/d_ary_heap.h | 12 +++++++----- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/decoder/apply_fsa_models.cc b/decoder/apply_fsa_models.cc index 4a928206..83083fc5 100755 --- a/decoder/apply_fsa_models.cc +++ b/decoder/apply_fsa_models.cc @@ -495,9 +495,8 @@ typedef Item *ItemP; /* we use a single type of item so it can live in a single best-first queue. we hold them by pointer so they can have mutable state, e.g. priority/location, but also lists of predictions and kbest completions (i.e. completions[L,r] = L -> * (r,s), by 1best for each possible s. we may discover more s later. we could use different subtypes since we hold by pointer, but for now everything will be packed as variants of Item */ struct Item : ItemPrio,ItemKey { - explicit Item(NodeP dot,int next=0) : ItemKey(dot),next(next),from(0) { } - explicit Item(NodeP dot,FFState const& state,int next=0) : ItemKey(dot,state),next(next),from(0) { } - unsigned location; + explicit Item(NodeP dot,int next=0) : ItemKey(dot),next(next),from(0),location(D_ARY_HEAP_NULL_INDEX) { } + explicit Item(NodeP dot,FFState const& state,int next=0) : ItemKey(dot,state),next(next),from(0),location(D_ARY_HEAP_NULL_INDEX) { } typedef std::queue Predicted; Predicted predicted; // this is empty, unless this is a predicted L -> .asdf item, or a to-complete L -> asdf . int next; // index of dot->adj to complete (if dest==0), or predict (if NT), or scan (if word). note: we could store pointer inside adj since it and trie are @ fixed addrs. less pointer arith, more space. @@ -517,6 +516,7 @@ struct Item : ItemPrio,ItemKey { o<< ']'; } PRINT_SELF(Item) + unsigned location; }; struct GetItemKey { @@ -645,6 +645,7 @@ void ApplyFsa::ApplyEarley() Chart chart(cfg,smeta,fsa); // don't need to uniq - option to do that already exists in cfg_options //TODO: + *oh=hgcfg.ih; } diff --git a/decoder/hg.h b/decoder/hg.h index 76b2b8f0..a78746b0 100644 --- a/decoder/hg.h +++ b/decoder/hg.h @@ -298,6 +298,9 @@ public: std::swap(is_linear_chain_, other.is_linear_chain_); other.edges_.swap(edges_); } + friend inline void swap(Hypergraph &a,Hypergraph &b) { + a.swap(b); + } void ResizeNodes(int size) { nodes_.resize(size); diff --git a/decoder/inside_outside.h b/decoder/inside_outside.h index 73d4ec6a..e6289176 100644 --- a/decoder/inside_outside.h +++ b/decoder/inside_outside.h @@ -55,7 +55,7 @@ WeightType Inside(const Hypergraph& hg, *cur_node_inside_score += score; } } - return inside_score.back(); + return inside_score.empty() ? WeightType(0) : inside_score.back(); } template diff --git a/decoder/viterbi.h b/decoder/viterbi.h index e78cd157..ac0b9a11 100644 --- a/decoder/viterbi.h +++ b/decoder/viterbi.h @@ -55,6 +55,8 @@ typename WeightFunction::Weight Viterbi(const Hypergraph& hg, antsb[k] = &vit_result[edgeb.tail_nodes_[k]]; traverse(edgeb, antsb, cur_node_best_result); } + if (vit_result.empty()) + return WeightType(0); std::swap(*result, vit_result.back()); return vit_weight.back(); } diff --git a/utils/agenda.h b/utils/agenda.h index 1937ad1a..a4940a00 100755 --- a/utils/agenda.h +++ b/utils/agenda.h @@ -64,6 +64,7 @@ struct Less { }; // LocMap and PrioMap are boost property maps put(locmap,key,size_t), Better(get(priomap,k1),get(priomap,k2)) means k1 should be above k2 (be popped first). Locmap and PrioMap may have state; the rest are assumed stateless functors +// make sure the (default) location is not -1 for anything you add, or else an assertion may trigger template ,class HashKey=boost::hash,class EqKey=std::equal_to, class Pool=boost::object_pool > struct Agenda : intern_pool { typedef intern_pool Intern; // inherited because I want to use construct() diff --git a/utils/d_ary_heap.h b/utils/d_ary_heap.h index eee8efe0..20cdab95 100644 --- a/utils/d_ary_heap.h +++ b/utils/d_ary_heap.h @@ -12,6 +12,9 @@ #define D_ARY_VERIFY_HEAP 1 // This is a very expensive test so it should be disabled even when NDEBUG is not defined +# undef D_ARY_HEAP_NULL_INDEX +# define D_ARY_HEAP_NULL_INDEX (-1) // if you want to test contains before adding, init location to this. + /* adapted from boost/graph/detail/d_ary_heap.hpp local modifications: @@ -112,8 +115,6 @@ typename Equal = std::equal_to > class d_ary_heap_indirect { BOOST_STATIC_ASSERT (Arity >= 2); -# undef D_ARY_HEAP_NULL_INDEX -# define D_ARY_HEAP_NULL_INDEX ((size_type)(-1)) public: typedef Container container_type; typedef Size size_type; @@ -285,9 +286,10 @@ #pragma GCC diagnostic ignored "-Wtype-limits" // because maybe size_type is signed or unsigned inline bool contains(const Value &v,size_type i) const { - return D_ARY_TRACK_OUT_OF_HEAP ? - (i != D_ARY_HEAP_NULL_INDEX) : - i>=0 && i=0 check to catch uninit. data + if (D_ARY_TRACK_OUT_OF_HEAP) + return i != D_ARY_HEAP_NULL_INDEX; + size_type sz=data.size(); + return i>=0 && i=0 check to catch uninit. data } #include "warning_pop.h" -- cgit v1.2.3