Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2016-08-05 15:25:46 +0300
committerHieu Hoang <hieuhoang@gmail.com>2016-08-05 15:25:46 +0300
commit0352c30ed4507763b6cd9c6f0d83a504696ca120 (patch)
tree98bf1e359a952f35ac7a51d2f78aad87b61a1ea8 /contrib/other-builds
parent512dd465cb1b330d93ca923f35fab4beb6ab1cc3 (diff)
leak
Diffstat (limited to 'contrib/other-builds')
-rw-r--r--contrib/other-builds/moses2/SCFG/KBestExtractor.cpp7
-rw-r--r--contrib/other-builds/moses2/SCFG/TrellisPath.cpp37
-rw-r--r--contrib/other-builds/moses2/SCFG/TrellisPath.h4
-rw-r--r--contrib/other-builds/moses2/TrellisPaths.h13
4 files changed, 43 insertions, 18 deletions
diff --git a/contrib/other-builds/moses2/SCFG/KBestExtractor.cpp b/contrib/other-builds/moses2/SCFG/KBestExtractor.cpp
index cc3305624..04f92d8f5 100644
--- a/contrib/other-builds/moses2/SCFG/KBestExtractor.cpp
+++ b/contrib/other-builds/moses2/SCFG/KBestExtractor.cpp
@@ -35,11 +35,11 @@ KBestExtractor::KBestExtractor(const SCFG::Manager &mgr)
contenders.Add(path);
}
- cerr << "nbest_size=" << mgr.system.options.nbest.nbest_size << endl;
+ //cerr << "nbest_size=" << mgr.system.options.nbest.nbest_size << endl;
size_t bestInd = 0;
while (bestInd < mgr.system.options.nbest.nbest_size && !contenders.empty()) {
SCFG::TrellisPath *path = contenders.Get();
- cerr << "bestInd=" << bestInd << endl;
+ //cerr << "bestInd=" << bestInd << endl;
//cerr << "currPath=" << path->Debug(m_mgr.system) << endl;
path->CreateDeviantPaths(contenders, mgr);
@@ -48,10 +48,13 @@ KBestExtractor::KBestExtractor(const SCFG::Manager &mgr)
++bestInd;
}
+ cerr << "contenders=" << contenders.GetSize() << endl;
}
KBestExtractor::~KBestExtractor()
{
+ cerr << "m_coll=" << m_coll.size() << endl;
+
BOOST_FOREACH(SCFG::TrellisPath *path, m_coll) {
delete path;
}
diff --git a/contrib/other-builds/moses2/SCFG/TrellisPath.cpp b/contrib/other-builds/moses2/SCFG/TrellisPath.cpp
index fa066dce0..1a70e26f2 100644
--- a/contrib/other-builds/moses2/SCFG/TrellisPath.cpp
+++ b/contrib/other-builds/moses2/SCFG/TrellisPath.cpp
@@ -22,7 +22,7 @@ namespace SCFG
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
:arcList(arcLists.GetArcList(&hypo))
,ind(0)
-,m_prevNodes(pool)
+//,m_prevNodes(pool)
{
UTIL_THROW_IF2(arcList.size() == 0, "Empty arclist");
@@ -32,7 +32,7 @@ TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const SCFG::Hy
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const ArcList &varcList, size_t vind)
:arcList(varcList)
,ind(vind)
-,m_prevNodes(pool)
+//,m_prevNodes(pool)
{
UTIL_THROW_IF2(vind >= arcList.size(), "arclist out of bound" << ind << " >= " << arcList.size());
const SCFG::Hypothesis &hypo = arcList[ind]->Cast<SCFG::Hypothesis>();
@@ -42,7 +42,7 @@ TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const ArcList
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange)
:arcList(orig.arcList)
,ind(orig.ind)
-,m_prevNodes(pool)
+//,m_prevNodes(pool)
{
const TrellisNode::Children &origChildren = orig.GetChildren();
m_prevNodes.resize(origChildren.size());
@@ -52,17 +52,25 @@ TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const TrellisN
const TrellisNode *origChild = origChildren[i];
if (origChild != &nodeToChange) {
// recurse
- newChild = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, *origChild, nodeToChange);
+ newChild = new TrellisNode(pool, arcLists, *origChild, nodeToChange);
}
else {
size_t nextInd = nodeToChange.ind + 1;
- newChild = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, nodeToChange.arcList, nextInd);
+ newChild = new TrellisNode(pool, arcLists, nodeToChange.arcList, nextInd);
}
m_prevNodes[i] = newChild;
}
}
+TrellisNode::~TrellisNode()
+{
+ BOOST_FOREACH(const TrellisNode *child, m_prevNodes) {
+ delete child;
+ }
+}
+
+
void TrellisNode::CreateTail(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
{
const Vector<const Hypothesis*> &prevHypos = hypo.GetPrevHypos();
@@ -70,7 +78,7 @@ void TrellisNode::CreateTail(MemPool &pool, const ArcLists &arcLists, const SCFG
for (size_t i = 0; i < hypo.GetPrevHypos().size(); ++i) {
const SCFG::Hypothesis &prevHypo = *prevHypos[i];
- TrellisNode *prevNode = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, prevHypo);
+ TrellisNode *prevNode = new TrellisNode(pool, arcLists, prevHypo);
m_prevNodes[i] = prevNode;
}
}
@@ -117,12 +125,13 @@ bool TrellisNode::HasMore() const
TrellisPath::TrellisPath(const SCFG::Manager &mgr, const SCFG::Hypothesis &hypo)
{
+ cerr << "create2 " << this << endl;
MemPool &pool = mgr.GetPool();
// 1st
m_scores = m_scores = new (pool.Allocate<Scores>())
Scores(mgr.system, pool, mgr.system.featureFunctions.GetNumScores(), hypo.GetScores());
- m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, hypo);
+ m_node = new TrellisNode(pool, mgr.arcLists, hypo);
m_prevNodeChanged = m_node;
}
@@ -131,6 +140,8 @@ TrellisPath::TrellisPath(const SCFG::Manager &mgr, const SCFG::TrellisPath &orig
,m_scores(NULL)
,m_prevNodeChanged(NULL)
{
+ cerr << "create1 " << this << endl;
+
MemPool &pool = mgr.GetPool();
// calc scores
@@ -142,16 +153,22 @@ TrellisPath::TrellisPath(const SCFG::Manager &mgr, const SCFG::TrellisPath &orig
m_scores->PlusEquals(mgr.system, nextHypo.GetScores());
if (origPath.m_node == &nodeToChange) {
- m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, nodeToChange.arcList, nodeToChange.ind + 1);
+ m_node = new TrellisNode(pool, mgr.arcLists, nodeToChange.arcList, nodeToChange.ind + 1);
m_prevNodeChanged= m_node;
}
else {
// recursively copy nodes until we find the node that needs to change
- m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, *origPath.m_node, nodeToChange);
+ m_node = new TrellisNode(pool, mgr.arcLists, *origPath.m_node, nodeToChange);
m_prevNodeChanged= m_node;
}
}
+TrellisPath::~TrellisPath()
+{
+ cerr << "delete " << this << endl;
+ delete m_node;
+}
+
std::string TrellisPath::Output() const
{
stringstream tmpStrm;
@@ -182,7 +199,7 @@ void TrellisPath::CreateDeviantPaths(TrellisPaths<SCFG::TrellisPath> &paths, con
}
// recursively wiggle all of it's child nodes
- CreateDeviantPaths(paths, mgr, *m_prevNodeChanged);
+ //CreateDeviantPaths(paths, mgr, *m_prevNodeChanged);
}
void TrellisPath::CreateDeviantPaths(
diff --git a/contrib/other-builds/moses2/SCFG/TrellisPath.h b/contrib/other-builds/moses2/SCFG/TrellisPath.h
index 20ec3c1a1..08d7ac842 100644
--- a/contrib/other-builds/moses2/SCFG/TrellisPath.h
+++ b/contrib/other-builds/moses2/SCFG/TrellisPath.h
@@ -26,7 +26,7 @@ class Hypothesis;
class TrellisNode
{
public:
- typedef Vector<const TrellisNode*> Children;
+ typedef std::vector<const TrellisNode*> Children;
const ArcList &arcList;
size_t ind;
@@ -35,6 +35,7 @@ public:
TrellisNode(MemPool &pool, const ArcLists &arcLists, const ArcList &varcList, size_t vind);
TrellisNode(MemPool &pool, const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange);
+ virtual ~TrellisNode();
const SCFG::Hypothesis &GetHypothesis() const;
bool HasMore() const;
@@ -56,6 +57,7 @@ public:
TrellisPath(const SCFG::Manager &mgr, const SCFG::Hypothesis &hypo); // create best path
TrellisPath(const SCFG::Manager &mgr, const SCFG::TrellisPath &origPath, const TrellisNode &nodeToChange); // create original path
+ ~TrellisPath();
std::string Output() const;
diff --git a/contrib/other-builds/moses2/TrellisPaths.h b/contrib/other-builds/moses2/TrellisPaths.h
index 1b459773f..3e2d9ab9a 100644
--- a/contrib/other-builds/moses2/TrellisPaths.h
+++ b/contrib/other-builds/moses2/TrellisPaths.h
@@ -38,28 +38,31 @@ public:
bool empty() const
{
- return m_collection.empty();
+ return m_coll.empty();
}
//! add a new entry into collection
void Add(T *trellisPath)
{
- m_collection.push(trellisPath);
+ m_coll.push(trellisPath);
}
T *Get()
{
- T *top = m_collection.top();
+ T *top = m_coll.top();
// Detach
- m_collection.pop();
+ m_coll.pop();
return top;
}
+ size_t GetSize() const
+ { return m_coll.size(); }
+
protected:
typedef std::priority_queue<T*, std::vector<T*>,
CompareTrellisPath<T> > CollectionType;
- CollectionType m_collection;
+ CollectionType m_coll;
};
} /* namespace Moses2 */