From d9cc1a6986188a97e09e4c8cef46c34eee5f9cd2 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 10 Nov 2013 00:58:44 -0500 Subject: guard against direct includes of tr1 --- training/mira/kbest_cut_mira.cc | 65 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'training/mira/kbest_cut_mira.cc') diff --git a/training/mira/kbest_cut_mira.cc b/training/mira/kbest_cut_mira.cc index 59fa860a..3b1108e0 100644 --- a/training/mira/kbest_cut_mira.cc +++ b/training/mira/kbest_cut_mira.cc @@ -30,7 +30,6 @@ #include "sparse_vector.h" using namespace std; -using boost::shared_ptr; namespace po = boost::program_options; bool invert_score; @@ -149,7 +148,7 @@ struct HypothesisInfo { double alpha; double oracle_loss; SparseVector oracle_feat_diff; - shared_ptr oracleN; + boost::shared_ptr oracleN; }; bool ApproxEqual(double a, double b) { @@ -157,7 +156,7 @@ bool ApproxEqual(double a, double b) { return (fabs(a-b)/fabs(b)) < EPSILON; } -typedef shared_ptr HI; +typedef boost::shared_ptr HI; bool HypothesisCompareB(const HI& h1, const HI& h2 ) { return h1->mt_metric > h2->mt_metric; @@ -185,11 +184,11 @@ bool HypothesisCompareG(const HI& h1, const HI& h2 ) }; -void CuttingPlane(vector >* cur_c, bool* again, vector >& all_hyp, vector dense_weights) +void CuttingPlane(vector >* cur_c, bool* again, vector >& all_hyp, vector dense_weights) { bool DEBUG_CUT = false; - shared_ptr max_fear, max_fear_in_set; - vector >& cur_constraint = *cur_c; + boost::shared_ptr max_fear, max_fear_in_set; + vector >& cur_constraint = *cur_c; if(no_reweight) { @@ -235,9 +234,9 @@ void CuttingPlane(vector >* cur_c, bool* again, vecto } -double ComputeDelta(vector >* cur_p, double max_step_size,vector dense_weights ) +double ComputeDelta(vector >* cur_p, double max_step_size,vector dense_weights ) { - vector >& cur_pair = *cur_p; + vector >& cur_pair = *cur_p; double loss = cur_pair[0]->oracle_loss - cur_pair[1]->oracle_loss; double margin = -(cur_pair[0]->oracleN->features.dot(dense_weights)- cur_pair[0]->features.dot(dense_weights)) + (cur_pair[1]->oracleN->features.dot(dense_weights) - cur_pair[1]->features.dot(dense_weights)); @@ -261,12 +260,12 @@ double ComputeDelta(vector >* cur_p, double max_step_ } -vector > SelectPair(vector >* cur_c) +vector > SelectPair(vector >* cur_c) { bool DEBUG_SELECT= false; - vector >& cur_constraint = *cur_c; + vector >& cur_constraint = *cur_c; - vector > pair; + vector > pair; if (no_select || optimizer == 2){ //skip heuristic search and return oracle and fear for pa-mira @@ -278,7 +277,7 @@ vector > SelectPair(vector for(int u=0;u != cur_constraint.size();u++) { - shared_ptr max_fear; + boost::shared_ptr max_fear; if(DEBUG_SELECT) cerr<< "cur alpha " << u << " " << cur_constraint[u]->alpha; for(int i=0; i < cur_constraint.size();i++) //select maximal violator @@ -323,8 +322,8 @@ vector > SelectPair(vector } struct GoodBadOracle { - vector > good; - vector > bad; + vector > good; + vector > bad; }; struct BasicObserver: public DecoderObserver { @@ -367,8 +366,8 @@ struct TrainingObserver : public DecoderObserver { const DocScorer& ds; vector& corpus_bleu_sent_stats; vector& oracles; - vector > cur_best; - shared_ptr cur_oracle; + vector > cur_best; + boost::shared_ptr cur_oracle; const int kbest_size; Hypergraph forest; int cur_sent; @@ -386,7 +385,7 @@ struct TrainingObserver : public DecoderObserver { return *cur_best[0]; } - const vector > GetCurrentBest() const { + const vector > GetCurrentBest() const { return cur_best; } @@ -411,8 +410,8 @@ struct TrainingObserver : public DecoderObserver { } - shared_ptr MakeHypothesisInfo(const SparseVector& feats, const double score, const vector& hyp) { - shared_ptr h(new HypothesisInfo); + boost::shared_ptr MakeHypothesisInfo(const SparseVector& feats, const double score, const vector& hyp) { + boost::shared_ptr h(new HypothesisInfo); h->features = feats; h->mt_metric = score; h->hyp = hyp; @@ -424,14 +423,14 @@ struct TrainingObserver : public DecoderObserver { if (stream) sent_id = 0; bool PRINT_LIST= false; - vector >& cur_good = oracles[sent_id].good; - vector >& cur_bad = oracles[sent_id].bad; + vector >& cur_good = oracles[sent_id].good; + vector >& cur_bad = oracles[sent_id].bad; //TODO: look at keeping previous iterations hypothesis lists around cur_best.clear(); cur_good.clear(); cur_bad.clear(); - vector > all_hyp; + vector > all_hyp; typedef KBest::KBestDerivations, ESentenceTraversal,Filter> K; K kbest(forest,kbest_size); @@ -527,7 +526,7 @@ struct TrainingObserver : public DecoderObserver { if(PRINT_LIST) { cerr << "GOOD" << endl; for(int u=0;u!=cur_good.size();u++) cerr << cur_good[u]->mt_metric << " " << cur_good[u]->hope << endl;} //use hope for fear selection - shared_ptr& oracleN = cur_good[0]; + boost::shared_ptr& oracleN = cur_good[0]; if(fear_select == 1){ //compute fear hyps with model - bleu if (PRINT_LIST) cerr << "FEAR " << endl; @@ -663,13 +662,13 @@ int main(int argc, char** argv) { invert_score = false; } - shared_ptr ds; + boost::shared_ptr ds; //normal: load references, stream: start stream scorer if (stream) { - ds = shared_ptr(new DocStreamScorer(type, vector(0), "")); + ds = boost::shared_ptr(new DocStreamScorer(type, vector(0), "")); cerr << "Scoring doc stream with " << metric_name << endl; } else { - ds = shared_ptr(new DocScorer(type, conf["reference"].as >(), "")); + ds = boost::shared_ptr(new DocScorer(type, conf["reference"].as >(), "")); cerr << "Loaded " << ds->size() << " references for scoring with " << metric_name << endl; } vector corpus_bleu_sent_stats; @@ -774,9 +773,9 @@ int main(int argc, char** argv) { const HypothesisInfo& cur_good = *oracles[cur_sent].good[0]; const HypothesisInfo& cur_bad = *oracles[cur_sent].bad[0]; - vector >& cur_good_v = oracles[cur_sent].good; - vector >& cur_bad_v = oracles[cur_sent].bad; - vector > cur_best_v = observer.GetCurrentBest(); + vector >& cur_good_v = oracles[cur_sent].good; + vector >& cur_bad_v = oracles[cur_sent].bad; + vector > cur_best_v = observer.GetCurrentBest(); tot_loss += cur_hyp.mt_metric; @@ -824,13 +823,13 @@ int main(int argc, char** argv) { } else if(optimizer == 5) //full mira with n-best list of constraints from hope, fear, model best { - vector > cur_constraint; + vector > cur_constraint; cur_constraint.insert(cur_constraint.begin(), cur_bad_v.begin(), cur_bad_v.end()); cur_constraint.insert(cur_constraint.begin(), cur_best_v.begin(), cur_best_v.end()); cur_constraint.insert(cur_constraint.begin(), cur_good_v.begin(), cur_good_v.end()); bool optimize_again; - vector > cur_pair; + vector > cur_pair; //SMO for(int u=0;u!=cur_constraint.size();u++) cur_constraint[u]->alpha =0; @@ -879,7 +878,7 @@ int main(int argc, char** argv) { else if(optimizer == 2 || optimizer == 3) //PA and Cutting Plane MIRA update { bool DEBUG_SMO= true; - vector > cur_constraint; + vector > cur_constraint; cur_constraint.push_back(cur_good_v[0]); //add oracle to constraint set bool optimize_again = true; int cut_plane_calls = 0; @@ -919,7 +918,7 @@ int main(int argc, char** argv) { while (iter < smo_iter) { //select pair to optimize from constraint set - vector > cur_pair = SelectPair(&cur_constraint); + vector > cur_pair = SelectPair(&cur_constraint); if(cur_pair.empty()){ iter=MAX_SMO; -- cgit v1.2.3 From 1e9afb904a57ff0b03edd0e94d634ef98e7d4b2a Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 10 Nov 2013 01:46:28 -0500 Subject: fix for c++11 --- .gitignore | 2 +- decoder/apply_models.cc | 2 +- decoder/decoder.cc | 2 +- decoder/earley_composer.cc | 2 +- decoder/ff_source_syntax.cc | 2 +- decoder/ff_source_syntax2_p.cc | 2 +- decoder/ff_source_syntax_p.cc | 2 +- decoder/ff_wordalign.cc | 2 +- decoder/ff_wordalign.h | 2 +- decoder/ff_wordset.h | 2 +- decoder/grammar.cc | 2 +- decoder/hg_intersect.cc | 2 +- decoder/kbest.h | 2 +- decoder/maxtrans_blunsom.cc | 2 +- decoder/phrasebased_translator.cc | 2 +- python/cdec/sa/strmap.cc | 2 +- python/setup.py.in | 3 ++- training/latent_svm/latent_svm.cc | 13 ++++++------- training/mira/kbest_cut_mira.cc | 7 ------- training/utils/candidate_set.cc | 2 +- word-aligner/fast_align.cc | 2 +- word-aligner/ttables.h | 2 +- 22 files changed, 27 insertions(+), 34 deletions(-) (limited to 'training/mira/kbest_cut_mira.cc') diff --git a/.gitignore b/.gitignore index 697a1a9d..5f573137 100644 --- a/.gitignore +++ b/.gitignore @@ -103,7 +103,7 @@ jam-files/bjam jam-files/engine/bin.* jam-files/engine/bootstrap/ klm/lm/bin/ -klm/lm/builder/builder +klm/lm/builder/lmplz klm/lm/build_binary klm/lm/ngram_query klm/lm/query diff --git a/decoder/apply_models.cc b/decoder/apply_models.cc index 2e093d6a..4cd8b36f 100644 --- a/decoder/apply_models.cc +++ b/decoder/apply_models.cc @@ -8,7 +8,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include # include #else diff --git a/decoder/decoder.cc b/decoder/decoder.cc index 2c0e07b7..da65713a 100644 --- a/decoder/decoder.cc +++ b/decoder/decoder.cc @@ -1,6 +1,6 @@ #include "decoder.h" -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/earley_composer.cc b/decoder/earley_composer.cc index 32c387d3..d47a6969 100644 --- a/decoder/earley_composer.cc +++ b/decoder/earley_composer.cc @@ -4,7 +4,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include # include #else diff --git a/decoder/ff_source_syntax.cc b/decoder/ff_source_syntax.cc index 95709076..88f6714c 100644 --- a/decoder/ff_source_syntax.cc +++ b/decoder/ff_source_syntax.cc @@ -2,7 +2,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/ff_source_syntax2_p.cc b/decoder/ff_source_syntax2_p.cc index 130144fa..6a2ae742 100644 --- a/decoder/ff_source_syntax2_p.cc +++ b/decoder/ff_source_syntax2_p.cc @@ -3,7 +3,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/ff_source_syntax_p.cc b/decoder/ff_source_syntax_p.cc index 1d3dc497..c094de59 100644 --- a/decoder/ff_source_syntax_p.cc +++ b/decoder/ff_source_syntax_p.cc @@ -2,7 +2,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/ff_wordalign.cc b/decoder/ff_wordalign.cc index 8ed053c2..dcb80110 100644 --- a/decoder/ff_wordalign.cc +++ b/decoder/ff_wordalign.cc @@ -7,7 +7,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/ff_wordalign.h b/decoder/ff_wordalign.h index 50f0dafa..0161f603 100644 --- a/decoder/ff_wordalign.h +++ b/decoder/ff_wordalign.h @@ -9,7 +9,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/ff_wordset.h b/decoder/ff_wordset.h index affee2f4..e78cd2fb 100644 --- a/decoder/ff_wordset.h +++ b/decoder/ff_wordset.h @@ -9,7 +9,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/grammar.cc b/decoder/grammar.cc index f2530d35..160d00e6 100644 --- a/decoder/grammar.cc +++ b/decoder/grammar.cc @@ -3,7 +3,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include # include #else diff --git a/decoder/hg_intersect.cc b/decoder/hg_intersect.cc index c5f1cc91..31a9a1ce 100644 --- a/decoder/hg_intersect.cc +++ b/decoder/hg_intersect.cc @@ -1,7 +1,7 @@ #include "hg_intersect.h" #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/kbest.h b/decoder/kbest.h index cd386aef..c7194c7e 100644 --- a/decoder/kbest.h +++ b/decoder/kbest.h @@ -3,7 +3,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/decoder/maxtrans_blunsom.cc b/decoder/maxtrans_blunsom.cc index 8d1d471c..a9f65fab 100644 --- a/decoder/maxtrans_blunsom.cc +++ b/decoder/maxtrans_blunsom.cc @@ -2,7 +2,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include # include #else diff --git a/decoder/phrasebased_translator.cc b/decoder/phrasebased_translator.cc index 321fb286..04b3e5d2 100644 --- a/decoder/phrasebased_translator.cc +++ b/decoder/phrasebased_translator.cc @@ -2,7 +2,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include # include #else diff --git a/python/cdec/sa/strmap.cc b/python/cdec/sa/strmap.cc index d7c4f2a3..b6debfb0 100644 --- a/python/cdec/sa/strmap.cc +++ b/python/cdec/sa/strmap.cc @@ -4,7 +4,7 @@ #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/python/setup.py.in b/python/setup.py.in index ce1eb2ed..8ed0b100 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -21,7 +21,8 @@ ext_modules = [ extra_compile_args=CPPFLAGS, extra_link_args=LDFLAGS), Extension(name='cdec.sa._sa', - sources=['cdec/sa/_sa.c', 'cdec/sa/strmap.cc']) + sources=['cdec/sa/_sa.c', 'cdec/sa/strmap.cc'], + extra_compile_args=CPPFLAGS) ] setup( diff --git a/training/latent_svm/latent_svm.cc b/training/latent_svm/latent_svm.cc index ab9c1d5d..60e52550 100644 --- a/training/latent_svm/latent_svm.cc +++ b/training/latent_svm/latent_svm.cc @@ -32,7 +32,6 @@ total_loss and prev_loss actually refer not to loss, but the metric (usually BLE #include "sampler.h" using namespace std; -using boost::shared_ptr; namespace po = boost::program_options; bool invert_score; @@ -128,7 +127,7 @@ struct HypothesisInfo { }; struct GoodOracle { - shared_ptr good; + boost::shared_ptr good; }; struct TrainingObserver : public DecoderObserver { @@ -143,9 +142,9 @@ struct TrainingObserver : public DecoderObserver { const DocScorer& ds; const vector& feature_weights; vector& oracles; - shared_ptr cur_best; - shared_ptr cur_costaug_best; - shared_ptr cur_ref; + boost::shared_ptr cur_best; + boost::shared_ptr cur_costaug_best; + boost::shared_ptr cur_ref; const int kbest_size; const double mt_metric_scale; const double mu; @@ -168,8 +167,8 @@ struct TrainingObserver : public DecoderObserver { UpdateOracles(smeta.GetSentenceID(), *hg); } - shared_ptr MakeHypothesisInfo(const SparseVector& feats, const double metric) { - shared_ptr h(new HypothesisInfo); + boost::shared_ptr MakeHypothesisInfo(const SparseVector& feats, const double metric) { + boost::shared_ptr h(new HypothesisInfo); h->features = feats; h->mt_metric_score = metric; return h; diff --git a/training/mira/kbest_cut_mira.cc b/training/mira/kbest_cut_mira.cc index 3b1108e0..990609d7 100644 --- a/training/mira/kbest_cut_mira.cc +++ b/training/mira/kbest_cut_mira.cc @@ -49,13 +49,6 @@ bool sent_approx; bool checkloss; bool stream; -void SanityCheck(const vector& w) { - for (int i = 0; i < w.size(); ++i) { - assert(!isnan(w[i])); - assert(!isinf(w[i])); - } -} - struct FComp { const vector& w_; FComp(const vector& w) : w_(w) {} diff --git a/training/utils/candidate_set.cc b/training/utils/candidate_set.cc index 1dec9609..33dae9a3 100644 --- a/training/utils/candidate_set.cc +++ b/training/utils/candidate_set.cc @@ -1,6 +1,6 @@ #include "candidate_set.h" -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/word-aligner/fast_align.cc b/word-aligner/fast_align.cc index 589ca62d..f54233eb 100644 --- a/word-aligner/fast_align.cc +++ b/word-aligner/fast_align.cc @@ -1,7 +1,7 @@ #include #include #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include diff --git a/word-aligner/ttables.h b/word-aligner/ttables.h index 1785e064..d82aff72 100644 --- a/word-aligner/ttables.h +++ b/word-aligner/ttables.h @@ -2,7 +2,7 @@ #define _TTABLES_H_ #include -#ifdef HAVE_CXX11 +#ifndef HAVE_OLD_CPP # include #else # include -- cgit v1.2.3