Skip to content

Commit

Permalink
daily automatic beautifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mosesadmin committed Feb 1, 2017
1 parent aec2d51 commit adbb1c8
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 147 deletions.
2 changes: 1 addition & 1 deletion moses/Util.h
Expand Up @@ -428,7 +428,7 @@ inline float CalcTranslationScore(const std::vector<float> &probVector,
out << *this; \
return out.str(); \
} \

//! delete and remove every element of a collection object such as set, list etc
template<class COLL>
void RemoveAllInColl(COLL &coll)
Expand Down
136 changes: 67 additions & 69 deletions moses2/ArcLists.cpp
Expand Up @@ -19,110 +19,108 @@ namespace Moses2

ArcLists::ArcLists()
{
// TODO Auto-generated constructor stub
// TODO Auto-generated constructor stub

}

ArcLists::~ArcLists()
{
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
const ArcList *arcList = collPair.second;
delete arcList;
}
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
const ArcList *arcList = collPair.second;
delete arcList;
}
}

void ArcLists::AddArc(bool added, const HypothesisBase *currHypo,
const HypothesisBase *otherHypo)
const HypothesisBase *otherHypo)
{
//cerr << added << " " << currHypo << " " << otherHypo << endl;
ArcList *arcList;
if (added) {
// we're winners!
if (otherHypo) {
// there was a existing losing hypo
arcList = &GetAndDetachArcList(otherHypo);
}
else {
// there was no existing hypo
arcList = new ArcList;
}
m_coll[currHypo] = arcList;
}
else {
// we're losers!
// there should be a winner, we're not doing beam pruning
UTIL_THROW_IF2(otherHypo == NULL, "There must have been a winning hypo");
arcList = &GetArcList(otherHypo);
}

// in any case, add the curr hypo
arcList->push_back(currHypo);
//cerr << added << " " << currHypo << " " << otherHypo << endl;
ArcList *arcList;
if (added) {
// we're winners!
if (otherHypo) {
// there was a existing losing hypo
arcList = &GetAndDetachArcList(otherHypo);
} else {
// there was no existing hypo
arcList = new ArcList;
}
m_coll[currHypo] = arcList;
} else {
// we're losers!
// there should be a winner, we're not doing beam pruning
UTIL_THROW_IF2(otherHypo == NULL, "There must have been a winning hypo");
arcList = &GetArcList(otherHypo);
}

// in any case, add the curr hypo
arcList->push_back(currHypo);
}

ArcList &ArcLists::GetArcList(const HypothesisBase *hypo)
{
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList &arcList = *iter->second;
return arcList;
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList &arcList = *iter->second;
return arcList;
}

const ArcList &ArcLists::GetArcList(const HypothesisBase *hypo) const
{
Coll::const_iterator iter = m_coll.find(hypo);

if (iter == m_coll.end()) {
cerr << "looking for:" << hypo << " have " << m_coll.size() << " :";
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
const HypothesisBase *hypo = collPair.first;
cerr << hypo << " ";
}
}

UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list for " << hypo);
ArcList &arcList = *iter->second;
return arcList;
Coll::const_iterator iter = m_coll.find(hypo);

if (iter == m_coll.end()) {
cerr << "looking for:" << hypo << " have " << m_coll.size() << " :";
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
const HypothesisBase *hypo = collPair.first;
cerr << hypo << " ";
}
}

UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list for " << hypo);
ArcList &arcList = *iter->second;
return arcList;
}

ArcList &ArcLists::GetAndDetachArcList(const HypothesisBase *hypo)
{
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList &arcList = *iter->second;
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList &arcList = *iter->second;

m_coll.erase(iter);
m_coll.erase(iter);

return arcList;
return arcList;
}

void ArcLists::Sort()
{
BOOST_FOREACH(Coll::value_type &collPair, m_coll){
ArcList &list = *collPair.second;
std::sort(list.begin(), list.end(), HypothesisFutureScoreOrderer() );
}
BOOST_FOREACH(Coll::value_type &collPair, m_coll) {
ArcList &list = *collPair.second;
std::sort(list.begin(), list.end(), HypothesisFutureScoreOrderer() );
}
}

void ArcLists::Delete(const HypothesisBase *hypo)
{
//cerr << "hypo=" << hypo->Debug() << endl;
//cerr << "m_coll=" << m_coll.size() << endl;
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList *arcList = iter->second;

m_coll.erase(iter);
delete arcList;
//cerr << "hypo=" << hypo->Debug() << endl;
//cerr << "m_coll=" << m_coll.size() << endl;
Coll::iterator iter = m_coll.find(hypo);
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
ArcList *arcList = iter->second;

m_coll.erase(iter);
delete arcList;
}

std::string ArcLists::Debug(const System &system) const
{
stringstream strm;
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
const ArcList *arcList = collPair.second;
strm << arcList << "(" << arcList->size() << ") ";
}
return strm.str();
stringstream strm;
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
const ArcList *arcList = collPair.second;
strm << arcList << "(" << arcList->size() << ") ";
}
return strm.str();
}

}
Expand Down
2 changes: 1 addition & 1 deletion moses2/ArcLists.h
Expand Up @@ -23,7 +23,7 @@ class ArcLists
virtual ~ArcLists();

void AddArc(bool added, const HypothesisBase *currHypo,
const HypothesisBase *otherHypo);
const HypothesisBase *otherHypo);
void Sort();
void Delete(const HypothesisBase *hypo);

Expand Down
41 changes: 15 additions & 26 deletions moses2/Array.h
Expand Up @@ -13,26 +13,21 @@ class Array
typedef T* iterator;
typedef const T* const_iterator;
//! iterators
const_iterator begin() const
{
const_iterator begin() const {
return m_arr;
}
const_iterator end() const
{
const_iterator end() const {
return m_arr + m_size;
}

iterator begin()
{
iterator begin() {
return m_arr;
}
iterator end()
{
iterator end() {
return m_arr + m_size;
}

Array(MemPool &pool, size_t size = 0, const T &val = T())
{
Array(MemPool &pool, size_t size = 0, const T &val = T()) {
m_size = size;
m_maxSize = size;
m_arr = pool.Allocate<T>(size);
Expand All @@ -41,48 +36,42 @@ class Array
}
}

size_t size() const
{
size_t size() const {
return m_size;
}

const T& operator[](size_t ind) const
{
const T& operator[](size_t ind) const {
return m_arr[ind];
}

T& operator[](size_t ind)
{
T& operator[](size_t ind) {
return m_arr[ind];
}

T *GetArray()
{ return m_arr; }
T *GetArray() {
return m_arr;
}

size_t hash() const
{
size_t hash() const {
size_t seed = 0;
for (size_t i = 0; i < m_size; ++i) {
boost::hash_combine(seed, m_arr[i]);
}
return seed;
}

int Compare(const Array &compare) const
{
int Compare(const Array &compare) const {

int cmp = memcmp(m_arr, compare.m_arr, sizeof(T) * m_size);
return cmp;
}

bool operator==(const Array &compare) const
{
bool operator==(const Array &compare) const {
int cmp = Compare(compare);
return cmp == 0;
}

void resize(size_t newSize)
{
void resize(size_t newSize) {
assert(m_size < m_maxSize);
m_size = newSize;
}
Expand Down
4 changes: 2 additions & 2 deletions moses2/EstimatedScores.cpp
Expand Up @@ -99,8 +99,8 @@ float EstimatedScores::CalcEstimatedScore(Bitmap const &bitmap, size_t startPos,
}
// end of a gap?
else if (startGap != notInGap
&& (bitmap.GetValue(currPos) == true
|| (startPos <= currPos && currPos <= endPos))) {
&& (bitmap.GetValue(currPos) == true
|| (startPos <= currPos && currPos <= endPos))) {
estimatedScore += GetValue(startGap, currPos - 1);
startGap = notInGap;
}
Expand Down
6 changes: 2 additions & 4 deletions moses2/EstimatedScores.h
Expand Up @@ -36,17 +36,15 @@ class EstimatedScores: public Matrix<float>
{
public:
EstimatedScores(MemPool &pool, size_t size) :
Matrix<float>(pool, size, size)
{
Matrix<float>(pool, size, size) {
}

~EstimatedScores(); // not implemented

float CalcEstimatedScore(Bitmap const&) const;
float CalcEstimatedScore(Bitmap const&, size_t startPos, size_t endPos) const;

std::ostream &Debug(std::ostream &out, const System &system) const
{
std::ostream &Debug(std::ostream &out, const System &system) const {
for (size_t endPos = 0; endPos < GetSize(); endPos++) {
for (size_t startPos = 0; startPos < GetSize(); startPos++)
out << GetValue(startPos, endPos) << " ";
Expand Down

0 comments on commit adbb1c8

Please sign in to comment.