mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-26 11:28:48 +03:00
replace nth_element() with macro that execute sort() instead for gcc 4.8.1 & 4.8.2
This commit is contained in:
parent
3d37a8ffda
commit
17887a2796
@ -31,6 +31,15 @@ namespace MosesTuning
|
|||||||
#define TRACE_ERR(str) { }
|
#define TRACE_ERR(str) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8 && (__GNUC_PATCHLEVEL__ == 1 || __GNUC_PATCHLEVEL__ == 2)
|
||||||
|
// gcc nth_element() bug
|
||||||
|
#define NTH_ELEMENT3(begin, middle, end) std::sort(begin, end)
|
||||||
|
#define NTH_ELEMENT4(begin, middle, end, orderer) std::sort(begin, end, orderer)
|
||||||
|
#else
|
||||||
|
#define NTH_ELEMENT3(begin, middle, end) std::nth_element(begin, middle, end)
|
||||||
|
#define NTH_ELEMENT4(begin, middle, end, orderer) std::nth_element(begin, middle, end, orderer)
|
||||||
|
#endif
|
||||||
|
|
||||||
const char kDefaultDelimiterSymbol[] = " ";
|
const char kDefaultDelimiterSymbol[] = " ";
|
||||||
|
|
||||||
int verboselevel();
|
int verboselevel();
|
||||||
|
@ -42,6 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||||||
#include "FeatureDataIterator.h"
|
#include "FeatureDataIterator.h"
|
||||||
#include "ScoreDataIterator.h"
|
#include "ScoreDataIterator.h"
|
||||||
#include "BleuScorer.h"
|
#include "BleuScorer.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MosesTuning;
|
using namespace MosesTuning;
|
||||||
@ -232,7 +233,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
float sample_threshold = -1.0;
|
float sample_threshold = -1.0;
|
||||||
if (samples.size() > n_samples) {
|
if (samples.size() > n_samples) {
|
||||||
nth_element(scores.begin(), scores.begin() + (n_samples-1), scores.end());
|
NTH_ELEMENT3(scores.begin(), scores.begin() + (n_samples-1), scores.end());
|
||||||
sample_threshold = 0.99999-scores[n_samples-1];
|
sample_threshold = 0.99999-scores[n_samples-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ void ChartHypothesis::CleanupArcList()
|
|||||||
|
|
||||||
if (!distinctNBest && m_arcList->size() > nBestSize) {
|
if (!distinctNBest && m_arcList->size() > nBestSize) {
|
||||||
// prune arc list only if there too many arcs
|
// prune arc list only if there too many arcs
|
||||||
nth_element(m_arcList->begin()
|
NTH_ELEMENT4(m_arcList->begin()
|
||||||
, m_arcList->begin() + nBestSize - 1
|
, m_arcList->begin() + nBestSize - 1
|
||||||
, m_arcList->end()
|
, m_arcList->end()
|
||||||
, CompareChartChartHypothesisTotalScore());
|
, CompareChartChartHypothesisTotalScore());
|
||||||
|
@ -102,7 +102,7 @@ void ChartTranslationOptionList::Add(const TargetPhraseCollection &tpc,
|
|||||||
|
|
||||||
// Prune if bursting
|
// Prune if bursting
|
||||||
if (m_size == m_ruleLimit * 2) {
|
if (m_size == m_ruleLimit * 2) {
|
||||||
std::nth_element(m_collection.begin(),
|
NTH_ELEMENT4(m_collection.begin(),
|
||||||
m_collection.begin() + m_ruleLimit - 1,
|
m_collection.begin() + m_ruleLimit - 1,
|
||||||
m_collection.begin() + m_size,
|
m_collection.begin() + m_size,
|
||||||
ChartTranslationOptionOrderer());
|
ChartTranslationOptionOrderer());
|
||||||
@ -128,7 +128,7 @@ void ChartTranslationOptionList::ApplyThreshold()
|
|||||||
assert(m_size < m_ruleLimit * 2);
|
assert(m_size < m_ruleLimit * 2);
|
||||||
// Reduce the list to the best m_ruleLimit options. The remaining
|
// Reduce the list to the best m_ruleLimit options. The remaining
|
||||||
// options can be overwritten on subsequent calls to Add().
|
// options can be overwritten on subsequent calls to Add().
|
||||||
std::nth_element(m_collection.begin(),
|
NTH_ELEMENT4(m_collection.begin(),
|
||||||
m_collection.begin()+m_ruleLimit,
|
m_collection.begin()+m_ruleLimit,
|
||||||
m_collection.begin()+m_size,
|
m_collection.begin()+m_size,
|
||||||
ChartTranslationOptionOrderer());
|
ChartTranslationOptionOrderer());
|
||||||
|
@ -335,7 +335,7 @@ void Hypothesis::CleanupArcList()
|
|||||||
|
|
||||||
if (!distinctNBest && m_arcList->size() > nBestSize * 5) {
|
if (!distinctNBest && m_arcList->size() > nBestSize * 5) {
|
||||||
// prune arc list only if there too many arcs
|
// prune arc list only if there too many arcs
|
||||||
nth_element(m_arcList->begin()
|
NTH_ELEMENT4(m_arcList->begin()
|
||||||
, m_arcList->begin() + nBestSize - 1
|
, m_arcList->begin() + nBestSize - 1
|
||||||
, m_arcList->end()
|
, m_arcList->end()
|
||||||
, CompareHypothesisTotalScore());
|
, CompareHypothesisTotalScore());
|
||||||
|
@ -324,7 +324,7 @@ public:
|
|||||||
m_obj->m_tableLimit : costs.size());
|
m_obj->m_tableLimit : costs.size());
|
||||||
|
|
||||||
// find the nth phrase according to future cost
|
// find the nth phrase according to future cost
|
||||||
std::nth_element(costs.begin(),nth ,costs.end());
|
NTH_ELEMENT3(costs.begin(),nth ,costs.end());
|
||||||
|
|
||||||
// add n top phrases to the return list
|
// add n top phrases to the return list
|
||||||
for(std::vector<std::pair<float,size_t> >::iterator
|
for(std::vector<std::pair<float,size_t> >::iterator
|
||||||
|
@ -82,7 +82,7 @@ void PartialTranslOptColl::Prune()
|
|||||||
// TRACE_ERR( "pruning partial translation options from size " << m_list.size() << std::endl);
|
// TRACE_ERR( "pruning partial translation options from size " << m_list.size() << std::endl);
|
||||||
|
|
||||||
// find nth element
|
// find nth element
|
||||||
nth_element(m_list.begin(),
|
NTH_ELEMENT4(m_list.begin(),
|
||||||
m_list.begin() + m_maxSize,
|
m_list.begin() + m_maxSize,
|
||||||
m_list.end(),
|
m_list.end(),
|
||||||
ComparePartialTranslationOption);
|
ComparePartialTranslationOption);
|
||||||
|
@ -58,7 +58,7 @@ void TargetPhraseCollection::NthElement(size_t tableLimit)
|
|||||||
nth = (tableLimit && tableLimit <= m_collection.size()
|
nth = (tableLimit && tableLimit <= m_collection.size()
|
||||||
? m_collection.begin() + tableLimit
|
? m_collection.begin() + tableLimit
|
||||||
: m_collection.end());
|
: m_collection.end());
|
||||||
std::nth_element(m_collection.begin(), nth, m_collection.end(), CompareTargetPhrase());
|
NTH_ELEMENT4(m_collection.begin(), nth, m_collection.end(), CompareTargetPhrase());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetPhraseCollection::Prune(bool adhereTableLimit, size_t tableLimit)
|
void TargetPhraseCollection::Prune(bool adhereTableLimit, size_t tableLimit)
|
||||||
|
@ -129,7 +129,7 @@ PhraseDictionaryCompact::GetTargetPhraseCollectionNonCacheLEGACY(const Phrase &s
|
|||||||
TargetPhraseVector::iterator nth =
|
TargetPhraseVector::iterator nth =
|
||||||
(m_tableLimit == 0 || tpv->size() < m_tableLimit) ?
|
(m_tableLimit == 0 || tpv->size() < m_tableLimit) ?
|
||||||
tpv->end() : tpv->begin() + m_tableLimit;
|
tpv->end() : tpv->begin() + m_tableLimit;
|
||||||
std::nth_element(tpv->begin(), nth, tpv->end(), CompareTargetPhrase());
|
NTH_ELEMENT4(tpv->begin(), nth, tpv->end(), CompareTargetPhrase());
|
||||||
for(TargetPhraseVector::iterator it = tpv->begin(); it != nth; it++) {
|
for(TargetPhraseVector::iterator it = tpv->begin(); it != nth; it++) {
|
||||||
TargetPhrase *tp = new TargetPhrase(*it);
|
TargetPhrase *tp = new TargetPhrase(*it);
|
||||||
phraseColl->Add(tp);
|
phraseColl->Add(tp);
|
||||||
|
@ -107,7 +107,7 @@ void TranslationOptionCollection::Prune()
|
|||||||
if (m_maxNoTransOptPerCoverage > 0 &&
|
if (m_maxNoTransOptPerCoverage > 0 &&
|
||||||
fullList.size() > m_maxNoTransOptPerCoverage) {
|
fullList.size() > m_maxNoTransOptPerCoverage) {
|
||||||
// sort in vector
|
// sort in vector
|
||||||
nth_element(fullList.begin(), fullList.begin() + m_maxNoTransOptPerCoverage, fullList.end(), CompareTranslationOption);
|
NTH_ELEMENT4(fullList.begin(), fullList.begin() + m_maxNoTransOptPerCoverage, fullList.end(), CompareTranslationOption);
|
||||||
totalPruned += fullList.size() - m_maxNoTransOptPerCoverage;
|
totalPruned += fullList.size() - m_maxNoTransOptPerCoverage;
|
||||||
|
|
||||||
// delete the rest
|
// delete the rest
|
||||||
|
@ -58,6 +58,15 @@ namespace Moses
|
|||||||
#define VERBOSE(level,str) { if (StaticData::Instance().GetVerboseLevel() >= level) { TRACE_ERR(str); } }
|
#define VERBOSE(level,str) { if (StaticData::Instance().GetVerboseLevel() >= level) { TRACE_ERR(str); } }
|
||||||
#define IFVERBOSE(level) if (StaticData::Instance().GetVerboseLevel() >= level)
|
#define IFVERBOSE(level) if (StaticData::Instance().GetVerboseLevel() >= level)
|
||||||
|
|
||||||
|
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8 && (__GNUC_PATCHLEVEL__ == 1 || __GNUC_PATCHLEVEL__ == 2)
|
||||||
|
// gcc nth_element() bug
|
||||||
|
#define NTH_ELEMENT3(begin, middle, end) std::sort(begin, end)
|
||||||
|
#define NTH_ELEMENT4(begin, middle, end, orderer) std::sort(begin, end, orderer)
|
||||||
|
#else
|
||||||
|
#define NTH_ELEMENT3(begin, middle, end) std::nth_element(begin, middle, end)
|
||||||
|
#define NTH_ELEMENT4(begin, middle, end, orderer) std::nth_element(begin, middle, end, orderer)
|
||||||
|
#endif
|
||||||
|
|
||||||
//! delete white spaces at beginning and end of string
|
//! delete white spaces at beginning and end of string
|
||||||
const std::string Trim(const std::string& str, const std::string dropChars = " \t\n\r");
|
const std::string Trim(const std::string& str, const std::string dropChars = " \t\n\r");
|
||||||
const std::string ToLower(const std::string& str);
|
const std::string ToLower(const std::string& str);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "search/nbest.hh"
|
#include "search/nbest.hh"
|
||||||
|
|
||||||
#include "util/pool.hh"
|
#include "util/pool.hh"
|
||||||
|
#include "moses/Util.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -16,7 +17,7 @@ NBestList::NBestList(std::vector<PartialEdge> &partials, util::Pool &entry_pool,
|
|||||||
std::vector<PartialEdge>::iterator end;
|
std::vector<PartialEdge>::iterator end;
|
||||||
if (partials.size() > keep) {
|
if (partials.size() > keep) {
|
||||||
end = partials.begin() + keep;
|
end = partials.begin() + keep;
|
||||||
std::nth_element(partials.begin(), end, partials.end(), std::greater<PartialEdge>());
|
NTH_ELEMENT4(partials.begin(), end, partials.end(), std::greater<PartialEdge>());
|
||||||
} else {
|
} else {
|
||||||
end = partials.end();
|
end = partials.end();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user