replace CHECK with UTIL_THROW_IF in Moses

This commit is contained in:
Hieu Hoang 2013-11-19 13:19:23 +00:00
parent 90d1154965
commit c2c86ce50d
15 changed files with 38 additions and 29 deletions

View File

@ -5,13 +5,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.162355801" moduleId="org.eclipse.cdt.core.settings" name="Debug"> <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.162355801" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/> <externalSettings/>
<extensions> <extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
@ -88,6 +88,7 @@
<listOptionValue builtIn="false" value="z"/> <listOptionValue builtIn="false" value="z"/>
<listOptionValue builtIn="false" value="bz2"/> <listOptionValue builtIn="false" value="bz2"/>
<listOptionValue builtIn="false" value="dl"/> <listOptionValue builtIn="false" value="dl"/>
<listOptionValue builtIn="false" value="rt"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.128214028" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.128214028" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
@ -107,13 +108,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.516628324" moduleId="org.eclipse.cdt.core.settings" name="Release"> <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.516628324" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/> <externalSettings/>
<extensions> <extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">

View File

@ -5,13 +5,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.461114338" moduleId="org.eclipse.cdt.core.settings" name="Debug"> <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.461114338" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/> <externalSettings/>
<extensions> <extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
@ -85,6 +85,7 @@
<listOptionValue builtIn="false" value="z"/> <listOptionValue builtIn="false" value="z"/>
<listOptionValue builtIn="false" value="bz2"/> <listOptionValue builtIn="false" value="bz2"/>
<listOptionValue builtIn="false" value="dl"/> <listOptionValue builtIn="false" value="dl"/>
<listOptionValue builtIn="false" value="rt"/>
</option> </option>
<option id="gnu.cpp.link.option.userobjs.1542590830" name="Other objects" superClass="gnu.cpp.link.option.userobjs"/> <option id="gnu.cpp.link.option.userobjs.1542590830" name="Other objects" superClass="gnu.cpp.link.option.userobjs"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.983725033" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.983725033" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
@ -108,13 +109,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.2121690436" moduleId="org.eclipse.cdt.core.settings" name="Release"> <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.2121690436" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/> <externalSettings/>
<extensions> <extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions> </extensions>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">

View File

@ -100,7 +100,7 @@ void ChartTranslationOptions::CreateSourceRuleFromInputPath()
} }
const InputPath *inputPath = m_collection.front()->GetInputPath(); const InputPath *inputPath = m_collection.front()->GetInputPath();
CHECK(inputPath); assert(inputPath);
std::vector<const Word*> &ruleSourceFromInputPath = inputPath->AddRuleSourceFromInputPath(); std::vector<const Word*> &ruleSourceFromInputPath = inputPath->AddRuleSourceFromInputPath();
size_t chartCellIndex = 0; size_t chartCellIndex = 0;

View File

@ -8,6 +8,7 @@
#include "Word.h" #include "Word.h"
#include "InputType.h" #include "InputType.h"
#include "NonTerminal.h" #include "NonTerminal.h"
#include "util/exception.hh"
namespace Moses namespace Moses
{ {
@ -43,7 +44,9 @@ public:
} }
const Column& GetColumn(size_t i) const { const Column& GetColumn(size_t i) const {
CHECK(i<data.size()); UTIL_THROW_IF(i >= data.size(),
util::Exception,
"Out of bounds. Trying to access " << i << " when vector only contains " << data.size());
return data[i]; return data[i];
} }
const Column& operator[](size_t i) const { const Column& operator[](size_t i) const {

View File

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef moses_DecodeGraph_h #ifndef moses_DecodeGraph_h
#define moses_DecodeGraph_h #define moses_DecodeGraph_h
#include "util/check.hh" #include "util/exception.hh"
#include <list> #include <list>
#include <iterator> #include <iterator>
#include "TypeDef.h" #include "TypeDef.h"
@ -78,7 +78,9 @@ public:
} }
size_t GetMaxChartSpan() const { size_t GetMaxChartSpan() const {
CHECK(m_maxChartSpan != NOT_FOUND); UTIL_THROW_IF(m_maxChartSpan == NOT_FOUND,
util::Exception,
"Max chart span not specified");
return m_maxChartSpan; return m_maxChartSpan;
} }

View File

@ -166,7 +166,7 @@ void DecodeStepTranslation::ProcessInitialTranslationLEGACY(
for (iterTargetPhrase = phraseColl->begin(), iterSourcePhrase = sourcePhrases.begin() for (iterTargetPhrase = phraseColl->begin(), iterSourcePhrase = sourcePhrases.begin()
; iterTargetPhrase != iterEnd ; iterTargetPhrase != iterEnd
; ++iterTargetPhrase, ++iterSourcePhrase) { ; ++iterTargetPhrase, ++iterSourcePhrase) {
CHECK(iterSourcePhrase != sourcePhrases.end()); assert(iterSourcePhrase != sourcePhrases.end());
const TargetPhrase &targetPhrase = **iterTargetPhrase; const TargetPhrase &targetPhrase = **iterTargetPhrase;
const Phrase &sourcePhrase = *iterSourcePhrase; const Phrase &sourcePhrase = *iterSourcePhrase;

View File

@ -792,7 +792,7 @@ FValue FVector::sum() const
FValue FVector::inner_product(const FVector& rhs) const FValue FVector::inner_product(const FVector& rhs) const
{ {
CHECK(m_coreFeatures.size() == rhs.m_coreFeatures.size()); assert(m_coreFeatures.size() == rhs.m_coreFeatures.size());
FValue product = 0.0; FValue product = 0.0;
for (const_iterator i = cbegin(); i != cend(); ++i) { for (const_iterator i = cbegin(); i != cend(); ++i) {
product += ((i->second)*(rhs.get(i->first))); product += ((i->second)*(rhs.get(i->first)));
@ -811,7 +811,7 @@ void FVector::merge(const FVector &other)
const FValue otherVal = other.m_coreFeatures[i]; const FValue otherVal = other.m_coreFeatures[i];
if (otherVal) { if (otherVal) {
CHECK(thisVal == 0 || thisVal == otherVal); assert(thisVal == 0 || thisVal == otherVal);
thisVal = otherVal; thisVal = otherVal;
} }
} }

View File

@ -44,7 +44,7 @@
#include <boost/thread/shared_mutex.hpp> #include <boost/thread/shared_mutex.hpp>
#endif #endif
#include "util/check.hh" #include "util/exception.hh"
#include "util/string_piece.hh" #include "util/string_piece.hh"
namespace Moses namespace Moses
@ -299,7 +299,7 @@ private:
ar >> names; ar >> names;
ar >> values; ar >> values;
ar >> m_coreFeatures; ar >> m_coreFeatures;
CHECK(names.size() == values.size()); UTIL_THROW_IF(names.size() != values.size(), util::Exception, "Error");
for (size_t i = 0; i < names.size(); ++i) { for (size_t i = 0; i < names.size(); ++i) {
set(FName(names[i]), values[i]); set(FName(names[i]), values[i]);
} }

View File

@ -10,7 +10,7 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "util/check.hh" #include "util/exception.hh"
#include "UserMessage.h" #include "UserMessage.h"
#include "TypeDef.h" #include "TypeDef.h"
#include "Util.h" #include "Util.h"
@ -161,7 +161,7 @@ inline FILE* fOpen(const char* fn,const char* m)
return f; return f;
else { else {
UserMessage::Add(std::string("ERROR: could not open file ") + fn + " with mode " + m + "\n"); UserMessage::Add(std::string("ERROR: could not open file ") + fn + " with mode " + m + "\n");
CHECK(false); UTIL_THROW(util::Exception, "Couldn't open file " << fn);
return NULL; return NULL;
} }
} }

View File

@ -1,4 +1,4 @@
#include "util/check.hh" #include "util/exception.hh"
#include <climits> #include <climits>
#include <vector> #include <vector>
@ -11,7 +11,7 @@ using namespace std;
// All-pairs shortest path algorithm // All-pairs shortest path algorithm
void floyd_warshall(const std::vector<std::vector<bool> >& edges, std::vector<std::vector<int> >& dist) void floyd_warshall(const std::vector<std::vector<bool> >& edges, std::vector<std::vector<int> >& dist)
{ {
CHECK(edges.size() == edges.front().size()); UTIL_THROW_IF(edges.size() != edges.front().size(), util::Exception, "Error");
dist.clear(); dist.clear();
dist.resize(edges.size(), std::vector<int>(edges.size(), 0)); dist.resize(edges.size(), std::vector<int>(edges.size(), 0));

View File

@ -97,7 +97,7 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo, const TranslationOption &tran
// assert that we are not extending our hypothesis by retranslating something // assert that we are not extending our hypothesis by retranslating something
// that this hypothesis has already translated! // that this hypothesis has already translated!
CHECK(!m_sourceCompleted.Overlap(m_currSourceWordsRange)); assert(!m_sourceCompleted.Overlap(m_currSourceWordsRange));
//_hash_computed = false; //_hash_computed = false;
m_sourceCompleted.SetValue(m_currSourceWordsRange.GetStartPos(), m_currSourceWordsRange.GetEndPos(), true); m_sourceCompleted.SetValue(m_currSourceWordsRange.GetStartPos(), m_currSourceWordsRange.GetEndPos(), true);

View File

@ -169,7 +169,7 @@ public:
const Hypothesis *hypo = this; const Hypothesis *hypo = this;
while (pos < hypo->GetCurrTargetWordsRange().GetStartPos()) { while (pos < hypo->GetCurrTargetWordsRange().GetStartPos()) {
hypo = hypo->GetPrevHypo(); hypo = hypo->GetPrevHypo();
CHECK(hypo != NULL); UTIL_THROW_IF(hypo == NULL, util::Exception, "Previous hypothesis should not be NULL");
} }
return hypo->GetCurrWord(pos - hypo->GetCurrTargetWordsRange().GetStartPos()); return hypo->GetCurrWord(pos - hypo->GetCurrTargetWordsRange().GetStartPos());
} }

View File

@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Util.h" #include "Util.h"
#include "StaticData.h" #include "StaticData.h"
#include "Manager.h" #include "Manager.h"
#include "util/exception.hh"
using namespace std; using namespace std;
@ -105,8 +106,8 @@ bool HypothesisStackCubePruning::AddPrune(Hypothesis *hypo)
// equiv hypo exists, recombine with other hypo // equiv hypo exists, recombine with other hypo
iterator &iterExisting = addRet.first; iterator &iterExisting = addRet.first;
assert(iterExisting != m_hypos.end());
Hypothesis *hypoExisting = *iterExisting; Hypothesis *hypoExisting = *iterExisting;
CHECK(iterExisting != m_hypos.end());
m_manager.GetSentenceStats().AddRecombination(*hypo, **iterExisting); m_manager.GetSentenceStats().AddRecombination(*hypo, **iterExisting);
@ -125,8 +126,7 @@ bool HypothesisStackCubePruning::AddPrune(Hypothesis *hypo)
bool added = Add(hypo).second; bool added = Add(hypo).second;
if (!added) { if (!added) {
iterExisting = m_hypos.find(hypo); iterExisting = m_hypos.find(hypo);
TRACE_ERR("Offending hypo = " << **iterExisting << endl); UTIL_THROW(util::Exception, "Should have added hypothesis " << **iterExisting);
CHECK(false);
} }
return false; return false;
} else { } else {
@ -144,7 +144,8 @@ bool HypothesisStackCubePruning::AddPrune(Hypothesis *hypo)
void HypothesisStackCubePruning::AddInitial(Hypothesis *hypo) void HypothesisStackCubePruning::AddInitial(Hypothesis *hypo)
{ {
std::pair<iterator, bool> addRet = Add(hypo); std::pair<iterator, bool> addRet = Add(hypo);
CHECK(addRet.second); UTIL_THROW_IF(!addRet.second, util::Exception,
"Should have added hypothesis " << *hypo);
const WordsBitmap &bitmap = hypo->GetWordsBitmap(); const WordsBitmap &bitmap = hypo->GetWordsBitmap();
m_bitmapAccessor[bitmap] = new BitmapContainer(bitmap, *this); m_bitmapAccessor[bitmap] = new BitmapContainer(bitmap, *this);

View File

@ -116,7 +116,7 @@ bool HypothesisStackNormal::AddPrune(Hypothesis *hypo)
// equiv hypo exists, recombine with other hypo // equiv hypo exists, recombine with other hypo
iterator &iterExisting = addRet.first; iterator &iterExisting = addRet.first;
Hypothesis *hypoExisting = *iterExisting; Hypothesis *hypoExisting = *iterExisting;
CHECK(iterExisting != m_hypos.end()); assert(iterExisting != m_hypos.end());
m_manager.GetSentenceStats().AddRecombination(*hypo, **iterExisting); m_manager.GetSentenceStats().AddRecombination(*hypo, **iterExisting);

View File

@ -156,7 +156,8 @@ template <class Model> void Fill<Model>::Add(const TargetPhraseCollection &targe
template <class Model> void Fill<Model>::AddPhraseOOV(TargetPhrase &phrase, std::list<TargetPhraseCollection*> &, const WordsRange &) template <class Model> void Fill<Model>::AddPhraseOOV(TargetPhrase &phrase, std::list<TargetPhraseCollection*> &, const WordsRange &)
{ {
std::vector<lm::WordIndex> words; std::vector<lm::WordIndex> words;
CHECK(phrase.GetSize() <= 1); UTIL_THROW_IF(phrase.GetSize() > 1, util::Exception,
"OOV target phrase should be 0 or 1 word in length");
if (phrase.GetSize()) if (phrase.GetSize())
words.push_back(Convert(phrase.GetWord(0))); words.push_back(Convert(phrase.GetWord(0)));