mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-08 04:27:53 +03:00
bitmap in mempool
This commit is contained in:
parent
0f7ce2e871
commit
747349b2ad
@ -38,6 +38,7 @@ Manager::~Manager() {
|
||||
|
||||
delete m_search;
|
||||
delete m_estimatedScores;
|
||||
delete m_bitmaps;
|
||||
|
||||
GetPool().Reset();
|
||||
GetHypoRecycle().Clear();
|
||||
@ -49,6 +50,7 @@ void Manager::Init()
|
||||
m_pool = &system.GetManagerPool();
|
||||
m_systemPool = &system.GetSystemPool();
|
||||
m_hypoRecycle = &system.GetHypoRecycler();
|
||||
m_bitmaps = new Bitmaps(GetPool());
|
||||
|
||||
m_initPhrase = new (GetPool().Allocate<TargetPhrase>()) TargetPhrase(GetPool(), system, 0);
|
||||
|
||||
@ -69,7 +71,7 @@ void Manager::Init()
|
||||
|
||||
CalcFutureScore();
|
||||
|
||||
m_bitmaps.Init(m_input->GetSize(), vector<bool>(0));
|
||||
m_bitmaps->Init(m_input->GetSize(), vector<bool>(0));
|
||||
|
||||
switch (system.searchAlgorithm) {
|
||||
case Normal:
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
{ return *m_hypoRecycle; }
|
||||
|
||||
Bitmaps &GetBitmaps()
|
||||
{ return m_bitmaps; }
|
||||
{ return *m_bitmaps; }
|
||||
|
||||
const Sentence &GetInput() const
|
||||
{ return *m_input; }
|
||||
@ -75,7 +75,7 @@ protected:
|
||||
long m_translationId;
|
||||
Sentence *m_input;
|
||||
InputPaths m_inputPaths;
|
||||
Bitmaps m_bitmaps;
|
||||
Bitmaps *m_bitmaps;
|
||||
SquareMatrix *m_estimatedScores;
|
||||
TargetPhrase *m_initPhrase;
|
||||
|
||||
|
@ -18,12 +18,11 @@ class Vector : public std::vector<T, MemPoolAllocator<T> >
|
||||
typedef std::vector<T, MemPoolAllocator<T> > Parent;
|
||||
|
||||
public:
|
||||
Vector(MemPool &pool, size_t size = 0)
|
||||
:Parent(size, T(), MemPoolAllocator<T>(pool) )
|
||||
Vector(MemPool &pool, size_t size = 0, const T &val = T())
|
||||
:Parent(size, val, MemPoolAllocator<T>(pool) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
@ -25,9 +25,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
Bitmap::Bitmap(size_t size, const std::vector<bool>& initializer)
|
||||
:m_bitmap(initializer.begin(), initializer.end())
|
||||
Bitmap::Bitmap(MemPool &pool, size_t size, const std::vector<bool>& initializer)
|
||||
:m_bitmap(pool, size, false)
|
||||
{
|
||||
for (size_t i = 0; i < initializer.size(); ++i) {
|
||||
m_bitmap[i] = initializer[i];
|
||||
}
|
||||
|
||||
// The initializer may not be of the same length. Change to the desired
|
||||
// length. If we need to add any elements, initialize them to false.
|
||||
@ -36,35 +39,21 @@ Bitmap::Bitmap(size_t size, const std::vector<bool>& initializer)
|
||||
m_numWordsCovered = std::count(m_bitmap.begin(), m_bitmap.end(), true);
|
||||
|
||||
// Find the first gap, and cache it.
|
||||
std::vector<char>::const_iterator first_gap = std::find(
|
||||
Vector<char>::const_iterator first_gap = std::find(
|
||||
m_bitmap.begin(), m_bitmap.end(), false);
|
||||
m_firstGap = (
|
||||
(first_gap == m_bitmap.end()) ?
|
||||
NOT_FOUND : first_gap - m_bitmap.begin());
|
||||
}
|
||||
|
||||
//! Create Bitmap of length size and initialise.
|
||||
Bitmap::Bitmap(size_t size)
|
||||
:m_bitmap(size, false)
|
||||
,m_firstGap(0)
|
||||
,m_numWordsCovered(0)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
//! Deep copy.
|
||||
Bitmap::Bitmap(const Bitmap ©)
|
||||
:m_bitmap(copy.m_bitmap)
|
||||
,m_firstGap(copy.m_firstGap)
|
||||
,m_numWordsCovered(copy.m_numWordsCovered)
|
||||
{
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(const Bitmap ©, const Range &range)
|
||||
:m_bitmap(copy.m_bitmap)
|
||||
Bitmap::Bitmap(MemPool &pool, const Bitmap ©, const Range &range)
|
||||
:m_bitmap(pool, copy.m_bitmap.size())
|
||||
,m_firstGap(copy.m_firstGap)
|
||||
,m_numWordsCovered(copy.m_numWordsCovered)
|
||||
{
|
||||
for (size_t i = 0; i < m_bitmap.size(); ++i) {
|
||||
m_bitmap[i] = copy.m_bitmap[i];
|
||||
}
|
||||
SetValueNonOverlap(range);
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include "Range.h"
|
||||
#include "../Vector.h"
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
class MemPool;
|
||||
|
||||
typedef unsigned long WordsBitmapID;
|
||||
|
||||
@ -50,7 +52,7 @@ class Bitmap
|
||||
{
|
||||
friend std::ostream& operator<<(std::ostream& out, const Bitmap& bitmap);
|
||||
private:
|
||||
std::vector<char> m_bitmap; //! Ticks of words in sentence that have been done.
|
||||
Vector<char> m_bitmap; //! Ticks of words in sentence that have been done.
|
||||
size_t m_firstGap; //! Cached position of first gap, or NOT_FOUND.
|
||||
size_t m_numWordsCovered;
|
||||
|
||||
@ -95,15 +97,9 @@ private:
|
||||
|
||||
public:
|
||||
//! Create Bitmap of length size, and initialise with vector.
|
||||
explicit Bitmap(size_t size, const std::vector<bool>& initializer);
|
||||
explicit Bitmap(MemPool &pool, size_t size, const std::vector<bool>& initializer);
|
||||
|
||||
//! Create Bitmap of length size and initialise.
|
||||
explicit Bitmap(size_t size);
|
||||
|
||||
//! Deep copy.
|
||||
explicit Bitmap(const Bitmap ©);
|
||||
|
||||
explicit Bitmap(const Bitmap ©, const Range &range);
|
||||
explicit Bitmap(MemPool &pool, const Bitmap ©, const Range &range);
|
||||
|
||||
//! Count of words translated.
|
||||
size_t GetNumWordsCovered() const {
|
||||
|
@ -7,31 +7,30 @@ using namespace std;
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
Bitmaps::Bitmaps()
|
||||
Bitmaps::Bitmaps(MemPool &pool)
|
||||
:m_pool(pool)
|
||||
{
|
||||
}
|
||||
|
||||
Bitmaps::~Bitmaps()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Bitmaps::Init(size_t inputSize, const std::vector<bool> &initSourceCompleted)
|
||||
{
|
||||
m_initBitmap = new Bitmap(inputSize, initSourceCompleted);
|
||||
m_initBitmap = new (m_pool.Allocate<Bitmap>()) Bitmap(m_pool, inputSize, initSourceCompleted);
|
||||
m_coll[m_initBitmap];
|
||||
}
|
||||
|
||||
const Bitmap &Bitmaps::GetNextBitmap(const Bitmap &bm, const Range &range)
|
||||
{
|
||||
Bitmap *newBM = new Bitmap(bm, range);
|
||||
Bitmap *newBM = new (m_pool.Allocate<Bitmap>()) Bitmap(m_pool, bm, range);
|
||||
|
||||
Coll::const_iterator iter = m_coll.find(newBM);
|
||||
if (iter == m_coll.end()) {
|
||||
m_coll[newBM] = NextBitmaps();
|
||||
return *newBM;
|
||||
} else {
|
||||
delete newBM;
|
||||
return *iter->first;
|
||||
}
|
||||
}
|
||||
@ -56,14 +55,5 @@ const Bitmap &Bitmaps::GetBitmap(const Bitmap &bm, const Range &range)
|
||||
return *newBM;
|
||||
}
|
||||
|
||||
void Bitmaps::Clear()
|
||||
{
|
||||
BOOST_FOREACH (const Coll::value_type& myPair, m_coll) {
|
||||
const Bitmap *bm = myPair.first;
|
||||
delete bm;
|
||||
}
|
||||
m_coll.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
class MemPool;
|
||||
|
||||
class Bitmaps
|
||||
{
|
||||
@ -17,9 +18,11 @@ class Bitmaps
|
||||
Coll m_coll;
|
||||
const Bitmap *m_initBitmap;
|
||||
|
||||
MemPool &m_pool;
|
||||
|
||||
const Bitmap &GetNextBitmap(const Bitmap &bm, const Range &range);
|
||||
public:
|
||||
Bitmaps();
|
||||
Bitmaps(MemPool &pool);
|
||||
virtual ~Bitmaps();
|
||||
void Init(size_t inputSize, const std::vector<bool> &initSourceCompleted);
|
||||
|
||||
@ -27,7 +30,6 @@ public:
|
||||
return *m_initBitmap;
|
||||
}
|
||||
const Bitmap &GetBitmap(const Bitmap &bm, const Range &range);
|
||||
void Clear();
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user