summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
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) {