Merge branch 'master' of github.com:moses-smt/mosesdecoder

This commit is contained in:
Hieu Hoang 2015-05-19 22:19:19 +04:00
commit 90309aebfa
4 changed files with 134 additions and 43 deletions

View File

@ -389,7 +389,11 @@ StaticData
m_parameter->SetParameter<size_t>(m_timeout_threshold, "time-out", -1);
m_timeout = (GetTimeoutThreshold() == (size_t)-1) ? false : true;
m_threadCount = 1;
m_threadCount =
#ifdef WITH_THREADS
boost::thread::hardware_concurrency() ? boost::thread::hardware_concurrency() :
#endif
1;
params = m_parameter->GetParam("threads");
if (params && params->size()) {
if (params->at(0) == "all") {

View File

@ -26,43 +26,6 @@ namespace Moses
TO_STRING_BODY(WordsBitmap);
int WordsBitmap::GetFutureCosts(int lastPos) const
{
int sum=0;
bool aim1=0,ai=0,aip1=m_bitmap[0];
for(size_t i=0; i<m_size; ++i) {
aim1 = ai;
ai = aip1;
aip1 = (i+1==m_size || m_bitmap[i+1]);
#ifndef NDEBUG
if( i>0 ) {
assert( aim1==(i==0||m_bitmap[i-1]==1));
}
if( i+1<m_size ) {
assert( aip1==m_bitmap[i+1]);
}
#endif
if((i==0||aim1)&&ai==0) {
sum+=abs(lastPos-static_cast<int>(i)+1);
// sum+=getJumpCosts(lastPos,i,maxJumpWidth);
}
// if(sum>1e5) return sum;
if(i>0 && ai==0 && (i+1==m_size||aip1) )
lastPos = (int) (i+1);
}
// sum+=getJumpCosts(lastPos,as,maxJumpWidth);
sum+=abs(lastPos-static_cast<int>(m_size)+1); //getCosts(lastPos,as);
assert(sum>=0);
// TRACE_ERR(sum<<"\n");
return sum;
}
bool WordsBitmap::IsAdjacent(size_t startPos, size_t endPos) const
{
if (GetNumWordsCovered() == 0) {

View File

@ -54,7 +54,7 @@ protected:
}
//sets elements by vector
void Initialize(std::vector<bool> vector) {
void Initialize(const std::vector<bool>& vector) {
size_t vector_size = vector.size();
for (size_t pos = 0 ; pos < m_size ; pos++) {
if (pos < vector_size && vector[pos] == true) m_bitmap[pos] = true;
@ -65,7 +65,7 @@ protected:
public:
//! create WordsBitmap of length size and initialise with vector
WordsBitmap(size_t size, std::vector<bool> initialize_vector)
WordsBitmap(size_t size, const std::vector<bool>& initialize_vector)
:m_size (size) {
m_bitmap = (bool*) malloc(sizeof(bool) * size);
Initialize(initialize_vector);
@ -207,9 +207,6 @@ public:
}
//! TODO - ??? no idea
int GetFutureCosts(int lastPos) const ;
//! converts bitmap into an integer ID: it consists of two parts: the first 16 bit are the pattern between the first gap and the last word-1, the second 16 bit are the number of filled positions. enforces a sentence length limit of 65535 and a max distortion of 16
WordsBitmapID GetID() const {
assert(m_size < (1<<16));

127
moses/WordsBitmapTest.cpp Normal file
View File

@ -0,0 +1,127 @@
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2015- University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include <boost/test/unit_test.hpp>
#include <vector>
#include "WordsBitmap.h"
using namespace Moses;
using namespace std;
BOOST_AUTO_TEST_SUITE(bitmap)
BOOST_AUTO_TEST_CASE(initialise)
{
WordsBitmap wbm(5);
BOOST_CHECK_EQUAL(wbm.GetSize(),5);
for (size_t i = 0; i < 5; ++i) {
BOOST_CHECK_EQUAL(wbm.GetValue(i),false);
}
vector<bool> bitvec(10);
bitvec[2] = true;
bitvec[3] = true;
bitvec[7] = true;
WordsBitmap wbm2(7,bitvec);
BOOST_CHECK_EQUAL(wbm2.GetSize(),7);
for (size_t i = 0; i < 7; ++i) {
if (i != 2 && i != 3) {
BOOST_CHECK_EQUAL(wbm2.GetValue(i), false);
} else {
BOOST_CHECK_EQUAL(wbm2.GetValue(i), true);
}
}
}
BOOST_AUTO_TEST_CASE(getset)
{
WordsBitmap wbm(6);
wbm.SetValue(1,true);
BOOST_CHECK_EQUAL(wbm.GetValue(1),true);
BOOST_CHECK_EQUAL(wbm.GetValue(2),false);
wbm.SetValue(2,true);
BOOST_CHECK_EQUAL(wbm.GetValue(2),true);
wbm.SetValue(1,3,true);
BOOST_CHECK_EQUAL(wbm.GetValue(1),true);
BOOST_CHECK_EQUAL(wbm.GetValue(2),true);
BOOST_CHECK_EQUAL(wbm.GetValue(3),true);
BOOST_CHECK_EQUAL(wbm.GetValue(4),false);
WordsBitmap wbm2(6);
WordsRange wr(2,4);
wbm2.SetValue(wr,true);
BOOST_CHECK_EQUAL(wbm2.GetValue(2),true);
BOOST_CHECK_EQUAL(wbm2.GetValue(3),true);
BOOST_CHECK_EQUAL(wbm2.GetValue(4),true);
wbm2.SetValue(wr,false);
BOOST_CHECK_EQUAL(wbm2.GetValue(2),false);
BOOST_CHECK_EQUAL(wbm2.GetValue(3),false);
BOOST_CHECK_EQUAL(wbm2.GetValue(4),false);
}
BOOST_AUTO_TEST_CASE(covered)
{
WordsBitmap wbm(10);
BOOST_CHECK_EQUAL(wbm.GetNumWordsCovered(), 0);
wbm.SetValue(1,true);
wbm.SetValue(2,true);
BOOST_CHECK_EQUAL(wbm.GetNumWordsCovered(), 2);
wbm.SetValue(3,true);
wbm.SetValue(7,true);
BOOST_CHECK_EQUAL(wbm.GetNumWordsCovered(), 4);
wbm.SetValue(2,true);
BOOST_CHECK_EQUAL(wbm.GetNumWordsCovered(), 4);
wbm.SetValue(2,false);
BOOST_CHECK_EQUAL(wbm.GetNumWordsCovered(), 3);
}
BOOST_AUTO_TEST_CASE(positions)
{
WordsBitmap wbm(10);
wbm.SetValue(0,true);
wbm.SetValue(1,true);
wbm.SetValue(3,true);
wbm.SetValue(7,true);
BOOST_CHECK_EQUAL(wbm.GetFirstGapPos(), 2);
BOOST_CHECK_EQUAL(wbm.GetLastGapPos(), 9);
BOOST_CHECK_EQUAL(wbm.GetLastPos(), 7);
WordsBitmap wbm2(2);
wbm2.SetValue(0,true);
wbm2.SetValue(1,true);
BOOST_CHECK_EQUAL(wbm2.GetFirstGapPos(), NOT_FOUND);
WordsBitmap wbm3(5);
BOOST_CHECK_EQUAL(wbm3.GetFirstGapPos(), 0);
BOOST_CHECK_EQUAL(wbm3.GetLastGapPos(), 4);
BOOST_CHECK_EQUAL(wbm3.GetLastPos(), NOT_FOUND);
}
BOOST_AUTO_TEST_SUITE_END()