diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-30 18:11:09 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-30 18:11:09 +0400 |
commit | beb2256dbaf420ed525cc8354617ead0db315060 (patch) | |
tree | f5ef7deca385e984563e720f4ae2d7cd887018a3 /mert | |
parent | 01eb60f35031157b5a780e539473dfd88a7714d1 (diff) |
Move 'using namespace std' out from .h.
Add "std" to size_t, too.
Diffstat (limited to 'mert')
-rw-r--r-- | mert/HypPackEnumerator.h | 45 | ||||
-rw-r--r-- | mert/MiraFeatureVector.cpp | 6 | ||||
-rw-r--r-- | mert/MiraFeatureVector.h | 18 | ||||
-rw-r--r-- | mert/MiraWeightVector.cpp | 2 | ||||
-rw-r--r-- | mert/MiraWeightVector.h | 26 |
5 files changed, 48 insertions, 49 deletions
diff --git a/mert/HypPackEnumerator.h b/mert/HypPackEnumerator.h index 5d2a230a5..d878c2625 100644 --- a/mert/HypPackEnumerator.h +++ b/mert/HypPackEnumerator.h @@ -27,10 +27,10 @@ public: virtual bool finished() = 0; virtual void next() = 0; - virtual size_t cur_size() = 0; - virtual size_t num_dense() const = 0; - virtual const FeatureDataItem& featuresAt(size_t i) = 0; - virtual const ScoreDataItem& scoresAt(size_t i) = 0; + virtual std::size_t cur_size() = 0; + virtual std::size_t num_dense() const = 0; + virtual const FeatureDataItem& featuresAt(std::size_t i) = 0; + virtual const ScoreDataItem& scoresAt(std::size_t i) = 0; }; // Instantiation that streams from disk @@ -38,23 +38,22 @@ public: class StreamingHypPackEnumerator : public HypPackEnumerator { public: StreamingHypPackEnumerator(std::vector<std::string> const& featureFiles, - std::vector<std::string> const& scoreFiles - ); + std::vector<std::string> const& scoreFiles); + + virtual std::size_t num_dense() const; - virtual size_t num_dense() const; - virtual void reset(); virtual bool finished(); virtual void next(); - virtual size_t cur_size(); - virtual const FeatureDataItem& featuresAt(size_t i); - virtual const ScoreDataItem& scoresAt(size_t i); - + virtual std::size_t cur_size(); + virtual const FeatureDataItem& featuresAt(std::size_t i); + virtual const ScoreDataItem& scoresAt(std::size_t i); + private: void prime(); - size_t m_num_lists; - size_t m_sentenceId; + std::size_t m_num_lists; + std::size_t m_sentenceId; std::vector<std::string> m_featureFiles; std::vector<std::string> m_scoreFiles; @@ -62,7 +61,7 @@ private: int m_iNumDense; std::vector<FeatureDataIterator> m_featureDataIters; std::vector<ScoreDataIterator> m_scoreDataIters; - std::vector<std::pair<size_t,size_t> > m_current_indexes; + std::vector<std::pair<std::size_t,std::size_t> > m_current_indexes; }; // Instantiation that reads into memory @@ -74,21 +73,21 @@ public: std::vector<std::string> const& scoreFiles, bool no_shuffle); - virtual size_t num_dense() const; - + virtual std::size_t num_dense() const; + virtual void reset(); virtual bool finished(); virtual void next(); - virtual size_t cur_size(); - virtual const FeatureDataItem& featuresAt(size_t i); - virtual const ScoreDataItem& scoresAt(size_t i); + virtual std::size_t cur_size(); + virtual const FeatureDataItem& featuresAt(std::size_t i); + virtual const ScoreDataItem& scoresAt(std::size_t i); private: bool m_no_shuffle; - size_t m_cur_index; - size_t m_num_dense; - std::vector<size_t> m_indexes; + std::size_t m_cur_index; + std::size_t m_num_dense; + std::vector<std::size_t> m_indexes; std::vector<std::vector<FeatureDataItem> > m_features; std::vector<std::vector<ScoreDataItem> > m_scores; }; diff --git a/mert/MiraFeatureVector.cpp b/mert/MiraFeatureVector.cpp index 9636b2fcd..b72d29595 100644 --- a/mert/MiraFeatureVector.cpp +++ b/mert/MiraFeatureVector.cpp @@ -2,6 +2,8 @@ #include "MiraFeatureVector.h" +using namespace std; + MiraFeatureVector::MiraFeatureVector(const FeatureDataItem& vec) : m_dense(vec.dense) { @@ -97,7 +99,7 @@ MiraFeatureVector operator-(const MiraFeatureVector& a, const MiraFeatureVector& vector<ValType> sparseVals; vector<size_t> sparseFeats; while(i < a.m_sparseFeats.size() && j < b.m_sparseFeats.size()) { - + if(a.m_sparseFeats[i] < b.m_sparseFeats[j]) { sparseFeats.push_back(a.m_sparseFeats[i]); sparseVals.push_back(a.m_sparseVals[i]); @@ -136,7 +138,7 @@ MiraFeatureVector operator-(const MiraFeatureVector& a, const MiraFeatureVector& // Create and return vector return MiraFeatureVector(dense,sparseFeats,sparseVals); } - + // --Emacs trickery-- // Local Variables: // mode:c++ diff --git a/mert/MiraFeatureVector.h b/mert/MiraFeatureVector.h index 27a4510ad..31dd025c3 100644 --- a/mert/MiraFeatureVector.h +++ b/mert/MiraFeatureVector.h @@ -16,8 +16,6 @@ #include "FeatureDataIterator.h" -using namespace std; - typedef FeatureStatsType ValType; class MiraFeatureVector { @@ -25,20 +23,20 @@ public: MiraFeatureVector(const FeatureDataItem& vec); MiraFeatureVector(const MiraFeatureVector& other); MiraFeatureVector(const std::vector<ValType>& dense, - const std::vector<size_t>& sparseFeats, + const std::vector<std::size_t>& sparseFeats, const std::vector<ValType>& sparseVals); - - ValType val(size_t index) const; - size_t feat(size_t index) const; - size_t size() const; + + ValType val(std::size_t index) const; + std::size_t feat(std::size_t index) const; + std::size_t size() const; ValType sqrNorm() const; - + friend MiraFeatureVector operator-(const MiraFeatureVector& a, const MiraFeatureVector& b); - + private: std::vector<ValType> m_dense; - std::vector<size_t> m_sparseFeats; + std::vector<std::size_t> m_sparseFeats; std::vector<ValType> m_sparseVals; }; diff --git a/mert/MiraWeightVector.cpp b/mert/MiraWeightVector.cpp index 8b46044fa..7e17a2714 100644 --- a/mert/MiraWeightVector.cpp +++ b/mert/MiraWeightVector.cpp @@ -1,5 +1,7 @@ #include "MiraWeightVector.h" +using namespace std; + /** * Constructor, initializes to the zero vector */ diff --git a/mert/MiraWeightVector.h b/mert/MiraWeightVector.h index 375858634..65b374625 100644 --- a/mert/MiraWeightVector.h +++ b/mert/MiraWeightVector.h @@ -4,7 +4,7 @@ * * A self-averaging weight-vector. Good for * perceptron learning as well. - * + * */ #ifndef MERT_MIRA_WEIGHT_VECTOR_H @@ -14,8 +14,6 @@ #include "MiraFeatureVector.h" -using namespace std; - class AvgWeightVector; class MiraWeightVector { @@ -29,7 +27,7 @@ public: * Constructor with provided initial vector * \param init Initial feature values */ - MiraWeightVector(const vector<ValType>& init); + MiraWeightVector(const std::vector<ValType>& init); /** * Update a the model @@ -60,12 +58,12 @@ public: AvgWeightVector avg(); friend class AvgWeightVector; - + private: /** * Updates a weight and lazily updates its total */ - void update(size_t index, ValType delta); + void update(std::size_t index, ValType delta); /** * Make sure everyone's total is up-to-date @@ -75,12 +73,12 @@ private: /** * Helper to handle out-of-range weights */ - ValType weight(size_t index) const; - - vector<ValType> m_weights; - vector<ValType> m_totals; - vector<size_t> m_lastUpdated; - size_t m_numUpdates; + ValType weight(std::size_t index) const; + + std::vector<ValType> m_weights; + std::vector<ValType> m_totals; + std::vector<std::size_t> m_lastUpdated; + std::size_t m_numUpdates; }; /** @@ -90,8 +88,8 @@ class AvgWeightVector { public: AvgWeightVector(const MiraWeightVector& wv); ValType score(const MiraFeatureVector& fv) const; - ValType weight(size_t index) const; - size_t size() const; + ValType weight(std::size_t index) const; + std::size_t size() const; private: const MiraWeightVector& m_wv; }; |