$include_dir="/home/hyper-archives/ublas/include"; include("$include_dir/msg-header.inc") ?>
From: John Alfred (inzesun_at_[hidden])
Date: 2008-08-27 10:30:13
Upping this old thread 
Janek Kozicki wrote:
> 
> in case anybody will need this when googling, the ugly looking method
> for boost serialization of ublas vector and matrix:
> 
> 	private :
> 		friend class boost::serialization::access;
> 		template<class Archive>
> 		void save(Archive & ar, const unsigned int version) const
> 		{
> 			std::vector<std::vector<double> > l; // copy here ublas vector
> 			std::vector<std::vector<std::vector<double> > > w; // copy here ublas
> matrix
> 
> 			l.resize(layers.size());
> 			for(int i=0 ; i<layers.size() ; ++i)
> 			{
> 				l[i].resize(layers[i].size());
> 				for(int j=0 ; j<layers[i].size() ; ++j)
> 					l[i][j] = layers[i](j);
> 			}
> 
> 			w.resize(weights.size());
> 			for(int i=0 ; i<weights.size() ; ++i)
> 			{
> 				w[i].resize(weights[i].size1());
> 				for(int j=0 ; j<weights[i].size1() ; ++j)
> 				{
> 					w[i][j].resize(weights[i].size2());
> 					for(int k=0 ; k<weights[i].size2() ; ++k)
> 						w[i][j][k] = weights[i](j,k);
> 				}
> 			}
> 			ar & l;
> 			ar & w;
> 		}
> 		template<class Archive>
> 		void load(Archive & ar, const unsigned int version)
> 		{
> 			std::vector<std::vector<double> > l;
> 			std::vector<std::vector<std::vector<double> > > w;
> 			
> 			ar & l;
> 			ar & w;
> 
> 			layers.resize(l.size());
> 			for(int i=0 ; i<layers.size() ; ++i)
> 			{
> 				layers[i].resize(l[i].size());
> 				for(int j=0 ; j<layers[i].size() ; ++j)
> 					layers[i](j) = l[i][j];
> 			}
> 
> 			weights.resize(w.size());
> 			for(int i=0 ; i<weights.size() ; ++i)
> 			{
> 				weights[i].resize(w[i].size(),w[i][0].size());
> 				for(int j=0 ; j<weights[i].size1() ; ++j)
> 					for(int k=0 ; k<weights[i].size2() ; ++k)
> 						weights[i](j,k) = w[i][j][k];
> 			}
> 		}
> 		BOOST_SERIALIZATION_SPLIT_MEMBER()
> 
> 
> -- 
> Janek Kozicki                                                         |
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://listarchives.boost.org/mailman/listinfo.cgi/ublas
> 
> 
Hello,
I am a new uBlas programmer.
After some research i found this thread. But as it is quite old now, I am
wondering whether there is a simpler way to serialize matrices & vectors in
the new releases?
Thanks
John
-- View this message in context: http://www.nabble.com/serialization-of-ublas-matrix-and-vector---tp3041156p19182220.html Sent from the Boost - uBLAS mailing list archive at Nabble.com.