From f449a8a0a5642cb59eacffa9f02735cd86361339 Mon Sep 17 00:00:00 2001 From: Barry Haddow Date: Tue, 19 May 2015 15:24:37 +0000 Subject: [PATCH 1/2] Test for WordsBitmap, remove unused code, avoid copy. --- moses/WordsBitmap.cpp | 37 ----------- moses/WordsBitmap.h | 7 +-- moses/WordsBitmapTest.cpp | 127 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 42 deletions(-) create mode 100644 moses/WordsBitmapTest.cpp diff --git a/moses/WordsBitmap.cpp b/moses/WordsBitmap.cpp index 53c263cb5..4ac2625b9 100644 --- a/moses/WordsBitmap.cpp +++ b/moses/WordsBitmap.cpp @@ -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; i0 ) { - assert( aim1==(i==0||m_bitmap[i-1]==1)); - } - - if( i+1(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(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) { diff --git a/moses/WordsBitmap.h b/moses/WordsBitmap.h index 44cf147f4..bf417cdd0 100644 --- a/moses/WordsBitmap.h +++ b/moses/WordsBitmap.h @@ -54,7 +54,7 @@ protected: } //sets elements by vector - void Initialize(std::vector vector) { + void Initialize(const std::vector& 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 initialize_vector) + WordsBitmap(size_t size, const std::vector& 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)); diff --git a/moses/WordsBitmapTest.cpp b/moses/WordsBitmapTest.cpp new file mode 100644 index 000000000..3acd1351a --- /dev/null +++ b/moses/WordsBitmapTest.cpp @@ -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 + +#include + +#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 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() + From 6b1c7437113c722aa1ceb17190b8658fc9c0b953 Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Tue, 19 May 2015 13:53:20 -0400 Subject: [PATCH 2/2] Use all cores by default --- moses/StaticData.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index 9cf97657a..5d29eed2c 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -389,7 +389,11 @@ StaticData m_parameter->SetParameter(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") {