diff options
author | bhaddow <bhaddow@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 00:32:37 +0400 |
---|---|---|
committer | bhaddow <bhaddow@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-16 00:32:37 +0400 |
commit | 1a6dcf5e36313919e5017cc7dcbf036765cb9872 (patch) | |
tree | 9a5a9baba34325e4554356934ee0e043f5f02c82 /mert | |
parent | 6112215974a1d36ada170a6032e4c51f5f27b5be (diff) |
remove buffers
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1715 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert')
-rw-r--r-- | mert/FeatureStats.cpp | 57 | ||||
-rw-r--r-- | mert/FeatureStats.h | 19 | ||||
-rw-r--r-- | mert/ScoreArray.cpp | 3 | ||||
-rw-r--r-- | mert/ScoreArray.h | 4 | ||||
-rw-r--r-- | mert/ScoreData.cpp | 11 | ||||
-rw-r--r-- | mert/ScoreData.h | 4 | ||||
-rw-r--r-- | mert/ScoreStats.cpp | 68 | ||||
-rw-r--r-- | mert/ScoreStats.h | 16 |
8 files changed, 15 insertions, 167 deletions
diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp index d042e56e7..5d85c5655 100644 --- a/mert/FeatureStats.cpp +++ b/mert/FeatureStats.cpp @@ -10,17 +10,14 @@ #include "FeatureStats.h" -FeatureStats::FeatureStats(): -bufLen_(0) +FeatureStats::FeatureStats() {}; FeatureStats::FeatureStats(const FeatureStats &stats): -array_(stats.array_), -bufLen_(0) +array_(stats.array_) {}; -FeatureStats::FeatureStats(const size_t size): -bufLen_(0) +FeatureStats::FeatureStats(const size_t size) { for(int i = 0; i < size; i++) array_.push_back(0); @@ -89,56 +86,8 @@ void FeatureStats::savetxt(std::ofstream& outFile) FeatureStats& FeatureStats::operator=(const FeatureStats &stats) { array_ = stats.array_; - bufLen_ = 0; return *this; } -void FeatureStats::setBuffer(char* buffer, size_t sz) -{ - memcpy(databuf_, (char *)buffer, sz); - - // Now pack the data into a single contiguous memory location for storage. - bufLen_ = 0; - - unpackVector(databuf_, bufLen_, array_); -} - -/* - * Marshalls this classes data members into a single - * contiguous memory location for the purpose of storing - * the data in a database. - */ -char *FeatureStats::getBuffer() -{ - // Zero out the buffer - memset(databuf_, 0, BUFSIZ); - - // Now pack the data into a single contiguous memory location for storage. - bufLen_ = 0; - - packVector(databuf_, bufLen_, array_); - return databuf_; -} - -int FeatureStats::pack(char *buffer, size_t &bufferlen) -{ - getBuffer(); - size_t size = packVariable(buffer, bufferlen, bufLen_); - memcpy(buffer + bufferlen, databuf_, bufLen_); - bufferlen += bufLen_; - - return size + bufLen_; -} - -int FeatureStats::unpack(char *buffer, size_t &bufferlen) -{ - size_t size = unpackVariable(buffer, bufferlen, bufLen_); - memcpy(databuf_, buffer + bufferlen, bufLen_); - bufferlen += bufLen_; - setBuffer(databuf_, bufLen_); - - return size + bufLen_; -} - diff --git a/mert/FeatureStats.h b/mert/FeatureStats.h index 6488b582f..b0e202712 100644 --- a/mert/FeatureStats.h +++ b/mert/FeatureStats.h @@ -28,8 +28,6 @@ protected: vector<FeatureStatsType> array_; private: - char databuf_[BUFSIZ]; - size_t bufLen_; public: FeatureStats(); @@ -51,8 +49,6 @@ public: inline size_t size(){ return array_.size(); } - inline size_t memsize(){ return bufLen_; } - void savetxt(const std::string &file); void savetxt(ofstream& outFile); inline void savetxt(){ savetxt("/dev/stdout"); } @@ -66,20 +62,7 @@ public: *i = 0; } - /* - * Marshalls this classes data members into a single - * contiguous memory location for the purpose of storing - * the data in a database. - */ - char *getBuffer(); - - void setBuffer(char* buffer, size_t sz); - - int pack(char *buffer, size_t &bufferlen); - - int unpack(char *buffer, size_t &bufferlen); - -}; + }; #endif diff --git a/mert/ScoreArray.cpp b/mert/ScoreArray.cpp index 4584a0c90..6c57adf7f 100644 --- a/mert/ScoreArray.cpp +++ b/mert/ScoreArray.cpp @@ -11,8 +11,7 @@ #include "Util.h" -ScoreArray::ScoreArray(): -bufLen_(0),idx(0) +ScoreArray::ScoreArray(): idx(0) {}; void ScoreArray::savetxt(std::ofstream& outFile) diff --git a/mert/ScoreArray.h b/mert/ScoreArray.h index fcaa6e2dc..63e95d960 100644 --- a/mert/ScoreArray.h +++ b/mert/ScoreArray.h @@ -30,8 +30,6 @@ protected: vector<ScoreStats> array_; private: - char databuf_[BUFSIZ]; - size_t bufLen_; int idx; // idx to identify the utterance, it can differ from the index inside the vector std::string score_type; @@ -53,8 +51,6 @@ public: inline size_t size(){ return array_.size(); } - inline size_t memsize(){ return bufLen_; } - void savetxt(ofstream& outFile); void savebin(ofstream& outFile); void save(ofstream& outFile, bool bin=false); diff --git a/mert/ScoreData.cpp b/mert/ScoreData.cpp index 9fc2b5e2c..0063bd8be 100644 --- a/mert/ScoreData.cpp +++ b/mert/ScoreData.cpp @@ -13,7 +13,7 @@ ScoreData::ScoreData(Scorer& ptr): -bufLen_(0), theScorer(&ptr) +theScorer(&ptr) { score_type = theScorer->getName(); TRACE_ERR("score_type:" << score_type << std::endl); @@ -90,7 +90,7 @@ void ScoreData::loadnbest(const std::string &file) while (!inFile.eof()){ std::string substring, subsubstring, stringBuf; - std::string theSentence, theStatistics; + std::string theSentence; std::string::size_type loc; std::getline(inFile, stringBuf); @@ -106,13 +106,7 @@ void ScoreData::loadnbest(const std::string &file) entry.clear(); -/* HERE IS THE SECTION TO COMPUTE STATISTICS FOR ERROR MEASURE - * theSentence contains the translation - * theStatistics will contain the statistics (as a string) - * coming from the actual Scorer - */ theScorer->prepareStats(sentence_index, theSentence,entry); - entry.set(theStatistics); add(entry,sentence_index); } @@ -125,7 +119,6 @@ void ScoreData::loadnbest(const std::string &file) void ScoreData::add(ScoreStats e, int sent_idx){ if (exists(sent_idx)){ array_.at(sent_idx).add(e); - ScoreArray a=get(sent_idx);; } else{ ScoreArray a; diff --git a/mert/ScoreData.h b/mert/ScoreData.h index 754e547d4..0943301d2 100644 --- a/mert/ScoreData.h +++ b/mert/ScoreData.h @@ -26,8 +26,6 @@ protected: vector<ScoreArray> array_; private: - char databuf_[BUFSIZ]; - size_t bufLen_; Scorer* theScorer; std::string score_type; @@ -50,8 +48,6 @@ public: inline size_t size(){ return array_.size(); } - inline size_t memsize(){ return bufLen_; } - void save(const std::string &file, bool bin=false); void save(ofstream& outFile, bool bin=false); inline void save(bool bin=false){ save("/dev/stdout", bin); } diff --git a/mert/ScoreStats.cpp b/mert/ScoreStats.cpp index 3afc3c479..8f571aac3 100644 --- a/mert/ScoreStats.cpp +++ b/mert/ScoreStats.cpp @@ -10,17 +10,14 @@ #include "ScoreStats.h" -ScoreStats::ScoreStats(): -bufLen_(0) +ScoreStats::ScoreStats() {}; ScoreStats::ScoreStats(const ScoreStats &stats): -array_(stats.array_), -bufLen_(0) +array_(stats.array_) {}; -ScoreStats::ScoreStats(const size_t size): -bufLen_(0) +ScoreStats::ScoreStats(const size_t size) { for(int i = 0; i < size; i++) array_.push_back(0); @@ -34,14 +31,14 @@ ScoreStats::ScoreStats(std::string &theString) void ScoreStats::set(std::string &theString) { - std::string substring, stringBuf; - std::string::size_type loc; + std::string substring, stringBuf; + std::string::size_type loc; int nextPound; ScoreStatsType sc; while (!theString.empty()){ - nextPound = getNextPound(theString, substring); - sc = ATOSST(substring.c_str()); - array_.push_back(sc); + nextPound = getNextPound(theString, substring); + sc = ATOSST(substring.c_str()); + array_.push_back(sc); } } @@ -90,56 +87,7 @@ void ScoreStats::savetxt(std::ofstream& outFile) ScoreStats& ScoreStats::operator=(const ScoreStats &stats) { array_ = stats.array_; - bufLen_ = 0; return *this; } -void ScoreStats::setBuffer(char* buffer, size_t sz) -{ - memcpy(databuf_, (char *)buffer, sz); - - // Now pack the data into a single contiguous memory location for storage. - bufLen_ = 0; - - unpackVector(databuf_, bufLen_, array_); -} - -/* - * Marshalls this classes data members into a single - * contiguous memory location for the purpose of storing - * the data in a database. - */ -char *ScoreStats::getBuffer() -{ - // Zero out the buffer - memset(databuf_, 0, BUFSIZ); - - // Now pack the data into a single contiguous memory location for storage. - bufLen_ = 0; - - packVector(databuf_, bufLen_, array_); - return databuf_; -} - -int ScoreStats::pack(char *buffer, size_t &bufferlen) -{ - getBuffer(); - size_t size = packVariable(buffer, bufferlen, bufLen_); - memcpy(buffer + bufferlen, databuf_, bufLen_); - bufferlen += bufLen_; - - return size + bufLen_; -} - -int ScoreStats::unpack(char *buffer, size_t &bufferlen) -{ - size_t size = unpackVariable(buffer, bufferlen, bufLen_); - memcpy(databuf_, buffer + bufferlen, bufLen_); - bufferlen += bufLen_; - setBuffer(databuf_, bufLen_); - - return size + bufLen_; -} - - diff --git a/mert/ScoreStats.h b/mert/ScoreStats.h index a6b44b8aa..327d8eb36 100644 --- a/mert/ScoreStats.h +++ b/mert/ScoreStats.h @@ -28,8 +28,6 @@ protected: vector<ScoreStatsType> array_; private: - char databuf_[BUFSIZ]; - size_t bufLen_; public: ScoreStats(); @@ -48,7 +46,6 @@ public: inline size_t size(){ return array_.size(); } - inline size_t memsize(){ return bufLen_; } void savetxt(const std::string &file); void savetxt(ofstream& outFile); @@ -62,19 +59,6 @@ public: for (vector<ScoreStatsType>::iterator i = array_.begin(); i != array_.end(); i++) *i = 0; } - - /* - * Marshalls this classes data members into a single - * contiguous memory location for the purpose of storing - * the data in a database. - */ - char *getBuffer(); - - void setBuffer(char* buffer, size_t sz); - - int pack(char *buffer, size_t &bufferlen); - - int unpack(char *buffer, size_t &bufferlen); }; |