summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-20 00:11:45 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-20 00:11:45 +0000
commiteb0a8931eb835d8a23c939ef61867a08c19ebf6b (patch)
tree7112b6af490a04c8bfdc40eb88718702060823c7 /decoder
parentbcad98e114d468edf16369b3a30d98556a3d0e61 (diff)
Score::TimesEquals for vlad-mira, intrusive refcount for Score, shared_ptr compile fixes for decoder progs
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@331 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder')
-rwxr-xr-xdecoder/intrusive_refcount.hpp84
-rwxr-xr-xdecoder/oracle_bleu.h3
2 files changed, 86 insertions, 1 deletions
diff --git a/decoder/intrusive_refcount.hpp b/decoder/intrusive_refcount.hpp
new file mode 100755
index 00000000..4a4b0187
--- /dev/null
+++ b/decoder/intrusive_refcount.hpp
@@ -0,0 +1,84 @@
+#ifndef GRAEHL__SHARED__INTRUSIVE_REFCOUNT_HPP
+#define GRAEHL__SHARED__INTRUSIVE_REFCOUNT_HPP
+
+#include <boost/intrusive_ptr.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/detail/atomic_count.hpp>
+#include <cassert>
+
+/** usage:
+ struct mine : public boost::instrusive_refcount<mine> {};
+
+ boost::intrusive_ptr<mine> p(new mine());
+*/
+
+namespace boost {
+// note: the free functions need to be in boost namespace, OR namespace of involved type. this is the only way to do it.
+
+template <class T>
+class intrusive_refcount;
+
+template <class T>
+class atomic_intrusive_refcount;
+
+template<class T>
+void intrusive_ptr_add_ref(intrusive_refcount<T>* ptr)
+{
+ ++(ptr->refs);
+}
+
+template<class T>
+void intrusive_ptr_release(intrusive_refcount<T>* ptr)
+{
+ if (!--(ptr->refs)) delete static_cast<T*>(ptr);
+}
+
+
+//WARNING: only 2^32 (unsigned) refs allowed. hope that's ok :)
+template<class T>
+class intrusive_refcount : boost::noncopyable
+{
+ protected:
+// typedef intrusive_refcount<T> pointed_type;
+ friend void intrusive_ptr_add_ref<T>(intrusive_refcount<T>* ptr);
+ friend void intrusive_ptr_release<T>(intrusive_refcount<T>* ptr);
+// friend class intrusive_ptr<T>;
+
+ intrusive_refcount(): refs(0) {}
+ ~intrusive_refcount() { assert(refs==0); }
+
+private:
+ unsigned refs;
+};
+
+
+template<class T>
+void intrusive_ptr_add_ref(atomic_intrusive_refcount<T>* ptr)
+{
+ ++(ptr->refs);
+}
+
+template<class T>
+void intrusive_ptr_release(atomic_intrusive_refcount<T>* ptr)
+{
+ if(!--(ptr->refs)) delete static_cast<T*>(ptr);
+}
+
+template<class T>
+class atomic_intrusive_refcount : boost::noncopyable
+{
+ protected:
+ friend void intrusive_ptr_add_ref<T>(atomic_intrusive_refcount<T>* ptr);
+ friend void intrusive_ptr_release<T>(atomic_intrusive_refcount<T>* ptr);
+
+ atomic_intrusive_refcount(): refs(0) {}
+ ~atomic_intrusive_refcount() { assert(refs==0); }
+
+private:
+ boost::detail::atomic_count refs;
+};
+
+}
+
+
+#endif
diff --git a/decoder/oracle_bleu.h b/decoder/oracle_bleu.h
index 94548c18..2ccace61 100755
--- a/decoder/oracle_bleu.h
+++ b/decoder/oracle_bleu.h
@@ -231,7 +231,8 @@ struct OracleBleu {
void IncludeLastScore(std::ostream *out=0) {
double bleu_scale_ = doc_src_length * doc_score->ComputeScore();
- doc_score->PlusEquals(*sentscore, scale_oracle);
+ doc_score->PlusEquals(*sentscore);
+ doc_score->TimesEquals(scale_oracle);
sentscore.reset();
doc_src_length = (doc_src_length + tmp_src_length) * scale_oracle;
if (out) {