1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include "ug_bitext_pstats.h"
namespace Moses
{
namespace bitext
{
#if UG_BITEXT_TRACK_ACTIVE_THREADS
ThreadSafeCounter pstats::active;
#endif
pstats::
pstats() : raw_cnt(0), sample_cnt(0), good(0), sum_pairs(0), in_progress(0)
{
for (int i = 0; i <= Moses::LRModel::NONE; ++i)
ofwd[i] = obwd[i] = 0;
}
pstats::
~pstats()
{
#if UG_BITEXT_TRACK_ACTIVE_THREADS
// counter may not exist any more at destruction time, so try ... catch
try { --active; } catch (...) {}
#endif
}
void
pstats::
register_worker()
{
this->lock.lock();
++this->in_progress;
this->lock.unlock();
}
void
pstats::
release()
{
this->lock.lock();
if (this->in_progress-- == 1) // last one - >we're done
this->ready.notify_all();
this->lock.unlock();
}
void
pstats
::count_sample(int const docid, size_t const num_pairs,
int const po_fwd, int const po_bwd)
{
boost::lock_guard<boost::mutex> guard(lock);
++sample_cnt;
if (num_pairs == 0) return;
++good;
sum_pairs += num_pairs;
++ofwd[po_fwd];
++obwd[po_bwd];
if (docid >= 0)
{
while (int(indoc.size()) <= docid) indoc.push_back(0);
++indoc[docid];
}
}
bool
pstats::
add(uint64_t pid, float const w,
vector<uchar> const& a,
uint32_t const cnt2,
uint32_t fwd_o,
uint32_t bwd_o, int const docid)
{
boost::lock_guard<boost::mutex> guard(this->lock);
jstats& entry = this->trg[pid];
entry.add(w, a, cnt2, fwd_o, bwd_o, docid);
if (this->good < entry.rcnt())
{
UTIL_THROW(util::Exception, "more joint counts than good counts:"
<< entry.rcnt() << "/" << this->good << "!");
}
return true;
}
}
}
|