diff options
author | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-01-15 19:16:37 +0400 |
---|---|---|
committer | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-01-15 19:16:37 +0400 |
commit | 47bece6eac17d537d443872ab014013bbd971fe8 (patch) | |
tree | ae8cdc3bb830703c22d3a2ac615b131d4df2ca9c /moses/Util.h | |
parent | c13bb8f8e88402ffa570c7f418e4a4e3238ca6bc (diff) | |
parent | 32ccbef3b91f667ab8e26c1ba6197d6f23c08695 (diff) |
code cleanup; fixings to others' code/test
Diffstat (limited to 'moses/Util.h')
-rw-r--r-- | moses/Util.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/moses/Util.h b/moses/Util.h index b5031b7a7..b4e750771 100644 --- a/moses/Util.h +++ b/moses/Util.h @@ -28,11 +28,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <string> #include <vector> #include <cmath> +#include <cassert> #include <limits> #include <map> #include <cstdlib> #include <cstring> -#include "util/check.hh" +#include "util/exception.hh" #include "TypeDef.h" namespace Moses @@ -58,6 +59,15 @@ namespace Moses #define VERBOSE(level,str) { if (StaticData::Instance().GetVerboseLevel() >= level) { TRACE_ERR(str); } } #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 const std::string Trim(const std::string& str, const std::string dropChars = " \t\n\r"); const std::string ToLower(const std::string& str); @@ -305,7 +315,8 @@ inline float FloorScore(float logScore) inline float CalcTranslationScore(const std::vector<float> &probVector, const std::vector<float> &weightT) { - CHECK(weightT.size()==probVector.size()); + UTIL_THROW_IF2(weightT.size() != probVector.size(), + "Weight and score vector sizes not the same"); float rv=0.0; for(float const *sb=&probVector[0],*se=sb+probVector.size(),*wb=&weightT[0]; sb!=se; ++sb, ++wb) @@ -362,7 +373,7 @@ inline void ShrinkToFit(T& v) { if(v.capacity()>v.size()) T(v).swap(v); - CHECK(v.capacity()==v.size()); + assert(v.capacity()==v.size()); } bool FileExists(const std::string& filePath); |