From 2d3948b98bb9e8c7bad60f1acd99ff0b42b3ae30 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/utils/candidate_set.cc | 11 ++++++++--- training/utils/online_optimizer.h | 8 ++++---- training/utils/optimize_test.cc | 6 ++---- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'training/utils') diff --git a/training/utils/candidate_set.cc b/training/utils/candidate_set.cc index 087efec3..1dec9609 100644 --- a/training/utils/candidate_set.cc +++ b/training/utils/candidate_set.cc @@ -1,6 +1,11 @@ #include "candidate_set.h" -#include +#ifdef HAVE_CXX11 +# include +#else +# include +namespace std { using std::tr1::unordered_set; } +#endif #include @@ -139,12 +144,12 @@ void CandidateSet::ReadFromFile(const string& file) { void CandidateSet::Dedup() { if(!SILENT) cerr << "Dedup in=" << cs.size(); - tr1::unordered_set u; + unordered_set u; while(cs.size() > 0) { u.insert(cs.back()); cs.pop_back(); } - tr1::unordered_set::iterator it = u.begin(); + unordered_set::iterator it = u.begin(); while (it != u.end()) { cs.push_back(*it); it = u.erase(it); diff --git a/training/utils/online_optimizer.h b/training/utils/online_optimizer.h index 28d89344..19223e9d 100644 --- a/training/utils/online_optimizer.h +++ b/training/utils/online_optimizer.h @@ -1,10 +1,10 @@ #ifndef _ONL_OPTIMIZE_H_ #define _ONL_OPTIMIZE_H_ -#include #include #include #include +#include #include "sparse_vector.h" struct LearningRateSchedule { @@ -56,7 +56,7 @@ struct ExponentialDecayLearningRate : public LearningRateSchedule { class OnlineOptimizer { public: virtual ~OnlineOptimizer(); - OnlineOptimizer(const std::tr1::shared_ptr& s, + OnlineOptimizer(const boost::shared_ptr& s, size_t batch_size, const std::vector& frozen_feats = std::vector()) : N_(batch_size),schedule_(s),k_() { @@ -77,13 +77,13 @@ class OnlineOptimizer { std::set frozen_; // frozen (non-optimizing) features private: - std::tr1::shared_ptr schedule_; + boost::shared_ptr schedule_; int k_; // iteration count }; class CumulativeL1OnlineOptimizer : public OnlineOptimizer { public: - CumulativeL1OnlineOptimizer(const std::tr1::shared_ptr& s, + CumulativeL1OnlineOptimizer(const boost::shared_ptr& s, size_t training_instances, double C, const std::vector& frozen) : OnlineOptimizer(s, training_instances, frozen), C_(C), u_() {} diff --git a/training/utils/optimize_test.cc b/training/utils/optimize_test.cc index bff2ca03..72fcef6d 100644 --- a/training/utils/optimize_test.cc +++ b/training/utils/optimize_test.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include "optimize.h" #include "online_optimizer.h" #include "sparse_vector.h" @@ -96,14 +97,11 @@ void TestOptimizerVariants(int num_vars) { cerr << oa.Name() << " SUCCESS\n"; } -using namespace std::tr1; - void TestOnline() { size_t N = 20; double C = 1.0; double eta0 = 0.2; - std::tr1::shared_ptr r(new ExponentialDecayLearningRate(N, eta0, 0.85)); - //shared_ptr r(new StandardLearningRate(N, eta0)); + boost::shared_ptr r(new ExponentialDecayLearningRate(N, eta0, 0.85)); CumulativeL1OnlineOptimizer opt(r, N, C, std::vector()); assert(r->eta(10) < r->eta(1)); } -- cgit v1.2.3 From f204210aee0748f5183c6f0c853be89266f4a651 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/utils') 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