diff --git a/include/boost/numeric/ublas/matrix.hpp b/include/boost/numeric/ublas/matrix.hpp index b9b90942..b62f9aa4 100644 --- a/include/boost/numeric/ublas/matrix.hpp +++ b/include/boost/numeric/ublas/matrix.hpp @@ -1,6 +1,6 @@ // -// Copyright (c) 2000-2002 -// Joerg Walter, Mathias Koch +// Copyright (c) 2000-2007 +// Joerg Walter, Mathias Koch, Gunter Winkler // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, @@ -20,6 +20,8 @@ #include #include #include +#include +#include // Iterators based on ideas of Jeremy Siek @@ -945,6 +947,27 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("data",data_); + } + private: size_type size1_; size_type size2_; @@ -1964,6 +1987,27 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("data",data_); + } + private: size_type size1_; size_type size2_; @@ -2321,6 +2365,26 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + } + private: size_type size1_; size_type size2_; @@ -2701,6 +2765,27 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + size_common_ = ((std::min)(size1_, size2_)); + } + } + private: size_type size1_; size_type size2_; @@ -3140,6 +3225,28 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + + ar & serialization::make_nvp("value", value_); + } + private: size_type size1_; size_type size2_; @@ -4043,6 +4150,28 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + // could probably use make_array( &(data[0][0]), N*M ) + ar & serialization::make_array(data_, N); + } + private: size_type size1_; size_type size2_; diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index 77b51c8e..c3b4b5f4 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -1,6 +1,6 @@ // -// Copyright (c) 2000-2002 -// Joerg Walter, Mathias Koch +// Copyright (c) 2000-2007 +// Joerg Walter, Mathias Koch, Gunter Winkler // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, @@ -1295,6 +1295,20 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + ar & serialization::make_nvp("size1",s1); + ar & serialization::make_nvp("size2",s2); + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("data", data_); + } + private: size_type size1_; size_type size2_; @@ -2482,6 +2496,20 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + ar & serialization::make_nvp("size1",s1); + ar & serialization::make_nvp("size2",s2); + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("data", data_); + } + private: size_type size1_; size_type size2_; @@ -3815,6 +3843,26 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + ar & serialization::make_nvp("size1",s1); + ar & serialization::make_nvp("size2",s2); + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("capacity", capacity_); + ar & serialization::make_nvp("filled1", filled1_); + ar & serialization::make_nvp("filled2", filled2_); + ar & serialization::make_nvp("index1_data", index1_data_); + ar & serialization::make_nvp("index2_data", index2_data_); + ar & serialization::make_nvp("value_data", value_data_); + storage_invariants(); + } + private: void storage_invariants () const { BOOST_UBLAS_CHECK (layout_type::size_M (size1_, size2_) + 1 == index1_data_.size (), internal_logic ()); @@ -5159,6 +5207,27 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + ar & serialization::make_nvp("size1",s1); + ar & serialization::make_nvp("size2",s2); + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + ar & serialization::make_nvp("capacity", capacity_); + ar & serialization::make_nvp("filled", filled_); + ar & serialization::make_nvp("sorted_filled", sorted_filled_); + ar & serialization::make_nvp("sorted", sorted_); + ar & serialization::make_nvp("index1_data", index1_data_); + ar & serialization::make_nvp("index2_data", index2_data_); + ar & serialization::make_nvp("value_data", value_data_); + storage_invariants(); + } + private: void storage_invariants () const { diff --git a/include/boost/numeric/ublas/storage.hpp b/include/boost/numeric/ublas/storage.hpp index 340af68e..e2457754 100644 --- a/include/boost/numeric/ublas/storage.hpp +++ b/include/boost/numeric/ublas/storage.hpp @@ -22,6 +22,10 @@ #include #endif +#include +#include +#include + #include #include #include @@ -87,6 +91,7 @@ namespace boost { namespace numeric { namespace ublas { } BOOST_UBLAS_INLINE unbounded_array (const unbounded_array &c): + storage_array >(), alloc_ (c.alloc_), size_ (c.size_) { if (size_) { data_ = alloc_.allocate (size_); @@ -267,6 +272,21 @@ namespace boost { namespace numeric { namespace ublas { return alloc_; } + private: + friend class boost::serialization::access; + + // Serialization + template + void serialize(Archive & ar, const unsigned int version) + { + serialization::collection_size_type s(size_); + ar & serialization::make_nvp("size",s); + if ( Archive::is_loading::value ) { + resize(s); + } + ar & serialization::make_array(data_, s); + } + private: // Handle explict destroy on a (possibly indexed) iterator BOOST_UBLAS_INLINE @@ -430,6 +450,22 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + private: + // Serialization + friend class boost::serialization::access; + + template + void serialize(Archive & ar, const unsigned int version) + { + serialization::collection_size_type s(size_); + ar & serialization::make_nvp("size", s); + if ( Archive::is_loading::value ) { + if (s > N) bad_size("too large size in bounded_array::load()\n").raise(); + resize(s); + } + ar & serialization::make_array(data_, s); + } + private: size_type size_; BOOST_UBLAS_BOUNDED_ARRAY_ALIGN value_type data_ [N]; diff --git a/include/boost/numeric/ublas/storage_sparse.hpp b/include/boost/numeric/ublas/storage_sparse.hpp index efe7a108..92696208 100644 --- a/include/boost/numeric/ublas/storage_sparse.hpp +++ b/include/boost/numeric/ublas/storage_sparse.hpp @@ -18,6 +18,11 @@ #define _BOOST_UBLAS_STORAGE_SPARSE_ #include +#include +#include +#include +#include +#include #include @@ -197,8 +202,16 @@ namespace boost { namespace numeric { namespace ublas { // FIXME should use ALLOC for map but std::allocator of std::pair and std::pair fail to compile template class map_std : public std::map { + public: + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + ar & serialization::make_nvp("base", boost::serialization::base_object< std::map >(*this)); + } }; + + // Map array // Implementation requires pair allocator definition (without const) @@ -478,6 +491,17 @@ namespace boost { namespace numeric { namespace ublas { return alloc_; } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + resize(s); + } + ar & serialization::make_array(data_, s); + } + private: // Provide destroy as a non member function BOOST_UBLAS_INLINE diff --git a/include/boost/numeric/ublas/vector.hpp b/include/boost/numeric/ublas/vector.hpp index d7733c91..b640b7c6 100644 --- a/include/boost/numeric/ublas/vector.hpp +++ b/include/boost/numeric/ublas/vector.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include // Iterators based on ideas of Jeremy Siek @@ -509,6 +511,12 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + ar & serialization::make_nvp("data",data_); + } + private: array_type data_; }; @@ -752,6 +760,16 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + } + private: size_type size_; typedef const value_type const_value_type; @@ -962,6 +980,17 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + ar & serialization::make_nvp("index", index_); + } + private: size_type size_; size_type index_; @@ -1196,6 +1225,17 @@ namespace boost { namespace numeric { namespace ublas { return const_reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + ar & serialization::make_nvp("value", value_); + } + private: size_type size_; value_type value_; @@ -1678,6 +1718,21 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + + // copy the value back if loading + if (Archive::is_loading::value) { + if (s > N) bad_size("too large size in bounded_vector::load()\n").raise(); + size_ = s; + } + // ISSUE: this writes the full array + ar & serialization::make_nvp("data",data_); + } + private: size_type size_; array_type data_; diff --git a/include/boost/numeric/ublas/vector_of_vector.hpp b/include/boost/numeric/ublas/vector_of_vector.hpp index ef9d78fb..4f61349d 100644 --- a/include/boost/numeric/ublas/vector_of_vector.hpp +++ b/include/boost/numeric/ublas/vector_of_vector.hpp @@ -1217,6 +1217,30 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator2 (begin2 ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + + // we need to copy to a collection_size_type to get a portable + // and efficient serialization + serialization::collection_size_type s1 (size1_); + serialization::collection_size_type s2 (size2_); + + // serialize the sizes + ar & serialization::make_nvp("size1",s1) + & serialization::make_nvp("size2",s2); + + // copy the values back if loading + if (Archive::is_loading::value) { + size1_ = s1; + size2_ = s2; + } + + ar & serialization::make_nvp("data", data_); + + storage_invariants(); + } + private: void storage_invariants () const { diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index baa8e80d..1bc8e65c 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -738,6 +738,17 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + ar & serialization::make_nvp("data", data_); + } + private: size_type size_; array_type data_; @@ -1318,6 +1329,23 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + // ISSUE: filled may be much less than capacity + // ISSUE: index_data_ and value_data_ are undefined between filled and capacity (trouble with 'nan'-values) + ar & serialization::make_nvp("capacity", capacity_); + ar & serialization::make_nvp("filled", filled_); + ar & serialization::make_nvp("index_data", index_data_); + ar & serialization::make_nvp("value_data", value_data_); + storage_invariants(); + } + private: void storage_invariants () const { @@ -1981,6 +2009,25 @@ namespace boost { namespace numeric { namespace ublas { return reverse_iterator (begin ()); } + // Serialization + template + void serialize(Archive & ar, const unsigned int /* file_version */){ + serialization::collection_size_type s (size_); + ar & serialization::make_nvp("size",s); + if (Archive::is_loading::value) { + size_ = s; + } + // ISSUE: filled may be much less than capacity + // ISSUE: index_data_ and value_data_ are undefined between filled and capacity (trouble with 'nan'-values) + ar & serialization::make_nvp("capacity", capacity_); + ar & serialization::make_nvp("filled", filled_); + ar & serialization::make_nvp("sorted_filled", sorted_filled_); + ar & serialization::make_nvp("sorted", sorted_); + ar & serialization::make_nvp("index_data", index_data_); + ar & serialization::make_nvp("value_data", value_data_); + storage_invariants(); + } + private: void storage_invariants () const {