From 82c683758f82e6d21c39622b19d949b0431fb79b Mon Sep 17 00:00:00 2001 From: Tetsuo Kiso Date: Sun, 18 Mar 2012 12:32:11 +0900 Subject: [PATCH] Pass parameters by const reference. --- mert/Optimizer.cpp | 8 ++++---- mert/Optimizer.h | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mert/Optimizer.cpp b/mert/Optimizer.cpp index ca5af3736..6d35a3567 100644 --- a/mert/Optimizer.cpp +++ b/mert/Optimizer.cpp @@ -32,7 +32,7 @@ inline float intersect(float m1, float b1, float m2, float b2) } // namespace -Optimizer::Optimizer(unsigned Pd, vector i2O, vector start, unsigned int nrandom) +Optimizer::Optimizer(unsigned Pd, const vector& i2O, const vector& start, unsigned int nrandom) : m_scorer(NULL), m_feature_data(), m_num_random_directions(nrandom) { // Warning: the init vector is a full set of parameters, of dimension m_pdim! @@ -65,7 +65,7 @@ statscore_t Optimizer::GetStatScore(const Point& param) const return score; } -map::iterator AddThreshold(map& thresholdmap, float newt, pair newdiff) +map::iterator AddThreshold(map& thresholdmap, float newt, const pair& newdiff) { map::iterator it = thresholdmap.find(newt); if (it != thresholdmap.end()) { @@ -348,7 +348,7 @@ statscore_t Optimizer::Run(Point& P) const } -vector Optimizer::GetIncStatScore(vector thefirst, vector > > thediffs) const +vector Optimizer::GetIncStatScore(const vector& thefirst, const vector > >& thediffs) const { CHECK(m_scorer); @@ -495,7 +495,7 @@ OptimizerFactory::OptType OptimizerFactory::GetOType(const string& type) return((OptType)thetype); } -Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim, vector i2o, vector start, const string& type, unsigned int nrandom) +Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim, const vector& i2o, const vector& start, const string& type, unsigned int nrandom) { OptType T = GetOType(type); if (T == NOPTIMIZER) { diff --git a/mert/Optimizer.h b/mert/Optimizer.h index 519e9ecbc..78e07f819 100644 --- a/mert/Optimizer.h +++ b/mert/Optimizer.h @@ -10,8 +10,6 @@ using namespace std; -typedef float featurescore; - class Point; /** @@ -25,7 +23,7 @@ protected: unsigned int m_num_random_directions; public: - Optimizer(unsigned Pd, vector i2O, vector start, unsigned int nrandom); + Optimizer(unsigned Pd, const vector& i2O, const vector& start, unsigned int nrandom); void SetScorer(Scorer *scorer) { m_scorer = scorer; } void SetFeatureData(FeatureDataHandle feature_data) { m_feature_data = feature_data; } @@ -59,7 +57,7 @@ public: statscore_t GetStatScore(const Point& param) const; - vector GetIncStatScore(vector ref, vector > >) const; + vector GetIncStatScore(const vector& ref, const vector > >& diffs) const; /** * Get the optimal Lambda and the best score in a particular direction from a given Point. @@ -77,7 +75,7 @@ class SimpleOptimizer : public Optimizer private: const float kEPS; public: - SimpleOptimizer(unsigned dim, vector i2O, vector start, unsigned int nrandom) + SimpleOptimizer(unsigned dim, const vector& i2O, const vector& start, unsigned int nrandom) : Optimizer(dim, i2O, start,nrandom), kEPS(0.0001) {} virtual statscore_t TrueRun(Point&) const; }; @@ -90,7 +88,7 @@ class RandomDirectionOptimizer : public Optimizer private: const float kEPS; public: - RandomDirectionOptimizer(unsigned dim, vector i2O, vector start, unsigned int nrandom) + RandomDirectionOptimizer(unsigned dim, const vector& i2O, const vector& start, unsigned int nrandom) : Optimizer(dim, i2O, start, nrandom), kEPS(0.0001) {} virtual statscore_t TrueRun(Point&) const; }; @@ -101,7 +99,7 @@ public: class RandomOptimizer : public Optimizer { public: - RandomOptimizer(unsigned dim, vector i2O, vector start, unsigned int nrandom) + RandomOptimizer(unsigned dim, const vector& i2O, const vector& start, unsigned int nrandom) : Optimizer(dim, i2O, start, nrandom) {} virtual statscore_t TrueRun(Point&) const; }; @@ -110,7 +108,7 @@ class OptimizerFactory { public: static vector GetTypeNames(); - static Optimizer* BuildOptimizer(unsigned dim, vector tooptimize, vector start, const string& type, unsigned int nrandom); + static Optimizer* BuildOptimizer(unsigned dim, const vector& to_optimize, const vector& start, const string& type, unsigned int nrandom); private: OptimizerFactory() {}