Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57932 - sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example
From: erwann.rogard_at_[hidden]
Date: 2009-11-25 19:05:05


Author: e_r
Date: 2009-11-25 19:05:05 EST (Wed, 25 Nov 2009)
New Revision: 57932
URL: http://svn.boost.org/trac/boost/changeset/57932

Log:
m
Text files modified:
   sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp | 107 ++++++++++++++++++++++++++++-----------
   1 files changed, 75 insertions(+), 32 deletions(-)

Modified: sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp
==============================================================================
--- sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp (original)
+++ sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp 2009-11-25 19:05:05 EST (Wed, 25 Nov 2009)
@@ -14,7 +14,7 @@
 #include <boost/serialization/serialization.hpp>
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>
-// #include <boost/serialization/vector.hpp>
+#include <boost/serialization/vector.hpp>
 #include <libs/statistics/detail/multi_array/example/serialize.h>
 
 void example_multi_array_serialize(std::ostream& os)
@@ -32,43 +32,86 @@
     typedef double val_;
     typedef std::vector<val_> vec_;
         typedef boost::multi_array<val_, 2> array_;
- typedef std::vector<array_> vec_array_;
+ typedef boost::multi_array<vec_,2> array_vec_;
     typedef boost::array<ma::multi_array_base::index,2> extents_;
- const unsigned int v = 0; // should call the overload (default is unsigned long)
- const unsigned n0 = 2;
- const unsigned n1 = 2;
- const str_ path = "./multi_array_serialization";
- {
- ofs_ ofs(path.c_str());
- oa_ oa(ofs);
- extents_ extents = {{n0,n1}};
- array_ a(extents);
- // vec_ vec;
- for(unsigned i = 0; i<n0; i++)
+ unsigned n0 = 2;
+ unsigned n1 = 2;
+ {
+ const str_ path = "./multi_array_serialization";
             {
- for(unsigned j = 0; j<n1; j++)
- {
- a[i][j] = i * n1 + j;
- }
+ ofs_ ofs(path.c_str());
+ oa_ oa(ofs);
+ extents_ extents = {{ n0, n1 }};
+ array_ a(extents);
+ // vec_ vec;
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ a[i][j] = i * n1 + j;
+ }
+ }
+ oa << a;
             }
- oa << a;
- }
- {
- ifs_ ifs(path.c_str());
- ia_ ia(ifs);
- array_ a;
- ia >> a;
- boost::serialization::load(ia,a,v);
- for(unsigned i = 0; i<n0; i++)
             {
- for(unsigned j = 0; j<n1; j++)
- {
- BOOST_ASSERT(a[i][j] == i * n1 + j);
- os << a[i][j] << ' ';
- }
+ ifs_ ifs(path.c_str());
+ ia_ ia(ifs);
+ array_ a;
+ ia >> a;
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ BOOST_ASSERT(a[i][j] == i * n1 + j);
+ os << a[i][j] << ' ';
+ }
+ }
             }
     }
+ {
+ const str_ path = "./multi_array_serialization2";
+ const unsigned v0 = 0;
+ const unsigned v1 = 1;
+ const unsigned v2 = 2;
+ {
+
+ ofs_ ofs(path.c_str());
+ oa_ oa(ofs);
+ extents_ extents = {{ n0, n1 }};
+ array_vec_ a(extents);
+ vec_ vec;
+ vec.push_back(v0);
+ vec.push_back(v1);
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ a[i][j] = vec;
+ a[i][j].resize(3);
+ a[i][j][0] = v0;
+ a[i][j][1] = v1;
+ a[i][j][2] = v2;
+ }
+ }
+ oa << a;
+ }
+ {
+ ifs_ ifs(path.c_str());
+ ia_ ia(ifs);
+ array_vec_ a;
+ ia >> a;
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ BOOST_ASSERT(a[i][j][0] == v0);
+ BOOST_ASSERT(a[i][j][1] == v1);
+ BOOST_ASSERT(a[i][j][2] == v2);
+ }
+ }
+ }
+ }
+
         os << "<-" << std::endl;
-
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk