Boost logo

Ublas :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2006-08-22 03:22:54


The CVS version of Boost actually has much faster serialization of
contiguous arrays, using the array wrapper class, which can be used
here.

Matthias

On Aug 22, 2006, at 12:58 AM, Neal Becker wrote:

> Matthias Troyer wrote:
>
>>
>> On Aug 18, 2006, at 7:03 PM, Jerry Swan wrote:
>>
>>> If I'm correct in thinking that the boost serialization library
>>> doesn't support ublas,
>>
>> Actually this statement is not 100% correct. The right statement is:
>> "ublas doesn't support serialization". If we want serialization
>> support then ublas has to add serialize functions for the ublas
>> classes. Is anybody working on that?
>>
>
> Here are some pieces I use for vector (I haven't needed matrix yet):
>
> namespace boost {
> namespace serialization {
>
> template<class T>
> struct implementation_level<ublas::vector<T> >
> {
> typedef mpl::integral_c_tag tag;
> // typedef mpl::int_<primitive_type> type;
> typedef mpl::int_<object_serializable> type;
> BOOST_STATIC_CONSTANT(
> int,
> value = implementation_level::type::value
> );
> };
>
> }
> }
>
> template<class Archive, class U>
> inline void save (Archive &ar, const ublas::vector<U> &v, const
> unsigned int) {
> unsigned int count = v.size();
> ar << BOOST_SERIALIZATION_NVP (count);
> typename ublas::vector<U>::const_iterator it = v.begin();
> while (count-- > 0) {
> ar << boost::serialization::make_nvp ("item", *it++);
> }
> }
>
> template<class Archive, class U>
> inline void load (Archive &ar, ublas::vector<U> &v, const unsigned
> int) {
> unsigned int count;
> ar >> BOOST_SERIALIZATION_NVP (count);
> v.resize (count);
> typename ublas::vector<U>::iterator it = v.begin();
> while (count-- > 0) {
> ar >> boost::serialization::make_nvp ("item", *it++);
> }
> }
>
>
> namespace boost { namespace serialization {
> template<class Archive, class U>
> inline void serialize (Archive &ar, ublas::vector<U>& v, const
> unsigned int file_version) {
> boost::serialization::split_free (ar, v, file_version);
> }
> }
> }
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas