From 3db6b004ae1e2319f52862d428c20be5a1538993 Mon Sep 17 00:00:00 2001 From: redpony Date: Tue, 28 Sep 2010 17:06:08 +0000 Subject: use boost mpi, fix L1 stochastic optimizer git-svn-id: https://ws10smt.googlecode.com/svn/trunk@659 ec762483-ff6d-05da-a07a-a48fb63a330f --- utils/sparse_vector.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'utils/sparse_vector.h') diff --git a/utils/sparse_vector.h b/utils/sparse_vector.h index 5d0dac27..c5e18b96 100644 --- a/utils/sparse_vector.h +++ b/utils/sparse_vector.h @@ -56,6 +56,10 @@ TODO: specialize for int value types, where it probably makes sense to check if #include "small_vector.h" #include "string_to.h" +#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP +#include +#endif + template inline T & extend_vector(std::vector &v,int i) { if (i>=v.size()) @@ -510,6 +514,35 @@ public: private: MapType values_; + +#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP + friend class boost::serialization::access; + template + void save(Archive & ar, const unsigned int version) const { + (void) version; + int eff_size = values_.size(); + const_iterator it = this->begin(); + if (values_.find(0) != values_.end()) { ++it; --eff_size; } + ar & eff_size; + while (it != this->end()) { + const std::pair wire_pair(FD::Convert(it->first), it->second); + ar & wire_pair; + ++it; + } + } + template + void load(Archive & ar, const unsigned int version) { + (void) version; + this->clear(); + int sz; ar & sz; + for (int i = 0; i < sz; ++i) { + std::pair wire_pair; + ar & wire_pair; + this->set_value(FD::Convert(wire_pair.first), wire_pair.second); + } + } + BOOST_SERIALIZATION_SPLIT_MEMBER() +#endif }; template -- cgit v1.2.3