load a serialized object into Matlab?
I am just looking into the serialization library. It seems really nice for archiving using C++. Is there a way to import an archive generated by that library into another language (e.g. matlab)? I guess that one would need the rules for IO that the serialization archives use? Thanks, James
Not having used the serialization library, the easiest way is probably
to write a MATLAB mex file that can open the file (or take a file
pointer) and deliver the data to matlab in a format it understands.
Best,
Dee
On Fri, Oct 22, 2010 at 04:29, James C. Sutherland
I am just looking into the serialization library. It seems really nice for archiving using C++.
Is there a way to import an archive generated by that library into another language (e.g. matlab)? I guess that one would need the rules for IO that the serialization archives use?
Thanks,
James
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I have the same kind of question, as I would like to read a boost
serialized archive
from Java, given that we have the corresponding classes in Java.
Is there a java package for this or can someone point us to the
specifications of
the binary or text archive format.
Thanks,
Gaëtan
2010/10/22 Diederick C. Niehorster
Not having used the serialization library, the easiest way is probably to write a MATLAB mex file that can open the file (or take a file pointer) and deliver the data to matlab in a format it understands.
Best, Dee
On Fri, Oct 22, 2010 at 04:29, James C. Sutherland
wrote: I am just looking into the serialization library. It seems really nice for archiving using C++.
Is there a way to import an archive generated by that library into another language (e.g. matlab)? I guess that one would need the rules for IO that the serialization archives use?
Thanks,
James
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
We have done quite a bit of this type of thing, serialising data from a 3D scanner and then reading back into Matlab for analysis. We did exactly what Diederick suggested, wrote mex files. We serialise out of the scanner with boost serialisation and unserialise in the mex files with boost serialiation. Then the problem is really just one of mapping your C++ data structure to an equivalent data structure in Matlab. The serialisation part is easy, the mex interface to matlab however is not so nice. On Fri, Oct 22, 2010 at 9:29 AM, James C. Sutherland < James.Sutherland@utah.edu> wrote:
I am just looking into the serialization library. It seems really nice for archiving using C++.
Is there a way to import an archive generated by that library into another language (e.g. matlab)? I guess that one would need the rules for IO that the serialization archives use?
Thanks,
James
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Fri, Oct 22, 2010 at 3:08 PM, Robert Valkenburg
We have done quite a bit of this type of thing, serialising data from a 3D scanner and then reading back into Matlab for analysis. We did exactly what Diederick suggested, wrote mex files. We serialise out of the scanner with boost serialisation and unserialise in the mex files with boost serialiation. Then the problem is really just one of mapping your C++ data structure to an equivalent data structure in Matlab.
The serialisation part is easy, the mex interface to matlab however is not so nice.
Would you be willing to share (on-list or off-list) some of the code that
you wrote to make this happen? I haven't done much with mex and frankly dread the thought. It would be great it I had an example to work from... Thanks, James
On Sat, Oct 23, 2010 at 2:41 PM, James C. Sutherland < James.Sutherland@utah.edu> wrote:
Would you be willing to share (on-list or off-list) some of the code that you wrote to make this happen? I haven't done much with mex and frankly dread the thought. It would be great it I had an example to work from...
Sure, I'm away from my work for a few days but will send you an example when i get back. I will send it off-list because its really more about Matlab mex than boost serialisation.
On Fri, Oct 22, 2010 at 8:18 PM, Robert Valkenburg
On Sat, Oct 23, 2010 at 2:41 PM, James C. Sutherland < James.Sutherland@utah.edu> wrote:
Would you be willing to share (on-list or off-list) some of the code that you wrote to make this happen? I haven't done much with mex and frankly dread the thought. It would be great it I had an example to work from...
Sure, I'm away from my work for a few days but will send you an example when i get back. I will send it off-list because its really more about Matlab mex than boost serialisation.
Thanks.
FWIW, I just hacked together a really simple test case that seems to work.
I will post here for the benefit of anyone who may be interested in the
future.
The serialization library is *really* nice!
Three files:
- Test.h
- Test_mex.cpp - creates a function that can be called from Matlab that
un-serializes the object
- Test.cpp - creates the archive.
=================
Isn't matlab capable of reading hdf5 files? That might be a reasonable target for boost::serialization. - Daniel
On Mon, Oct 25, 2010 at 3:27 PM, Daniel Herring
Isn't matlab capable of reading hdf5 files? That might be a reasonable target for boost::serialization.
True - Matlab has HDF5 IO support. However, HDF5 has a very poor c++ interface. While I would applaud a robust C++ interface for HDF5, I think that for boost to support it as an output target currently would be a painful endeavor. It is probably a better idea to build a MEX interface where the C++ classes are loaded natively and exported to Matlab. James
James C. Sutherland
On Mon, Oct 25, 2010 at 3:27 PM, Daniel Herring
wrote:Isn't matlab capable of reading hdf5 files? That might be a reasonable target for boost::serialization.
This was discussed briefly on the ublas list. Someone also told us that boost::serialization is really not meant for proprietary file formats.
endeavor.It is probably a better idea to build a MEX interface where the C++ classes are loaded natively and exported to Matlab.James
One approach is to wrap the MATIO library (which means the MEX wrappers is not necessary). I wrote upa mediocre and temporary version for loading/saving. Right now it only supports double values (and probably only compiles on win32) but you can see the coding approach and hack up the code at will. //////////////////////// The code looks like the following: matlab_iostream arch(boost::filesystem::path("...path...")); ublas::matrix<double> x_1(2,2); x_1 <<= 1.1, 2.1, 3.1, 4.1; arch << named("x_1_matlab", x_1); //Stores in the name "x_1_matlab" in matalb ublas::vector<double> x_2; arch >> named("x_1_matlab", x_2); //Loads from the archive into vector ///////////////////////////////// Here are a few links for the implementation (which supports ublas vectors, scalars, ublas matrices, and boost::multi_array): http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/named_v... ble.hpp http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/... ab_iostream.hpp http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/... ix.hpp http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/... ar.hpp http://econtoolkit.com/browser/libraries/trunk/etk/etk/serialization/matlab/... or.hpp The test suite is in: http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matla... st_matlab_archive.cpp http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matla... st_matlab_matrix.cpp http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matla... st_matlab_vector.cpp http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matla... st_matlab_multi_array.cpp http://econtoolkit.com/browser/libraries/trunk/etk/tests/serialization/matla... st_matlab_scalar.cpp -Jesse
On Tue, 26 Oct 2010, Jesse Perla wrote:
James C. Sutherland
writes: On Mon, Oct 25, 2010 at 3:27 PM, Daniel Herring
wrote:Isn't matlab capable of reading hdf5 files? That might be a reasonable target for boost::serialization. This was discussed briefly on the ublas list. Someone also told us that boost::serialization is really not meant for proprietary file formats.
While boost::serialization prefers its own file format, HDF5 is a very open standard. "The HDF5 data model, file format, API, library, and tools are open and distributed without charge." http://www.hdfgroup.org/HDF5/whatishdf5.html I understand that a full C++ object to HDF5 mapping is hard (I looked at the problem myself), but the format should not be dismissed lightly. In fact, I mentioned it as a possible format for matlab explicitly because it is a growing standard in scientific computing, whereas other matlab interfaces are vendor-specific. See for example http://www.hdfgroup.org/products/hdf5_tools/ The recent discussion about boost::mpi reawakened my interest in such a possibility... boost::hdf5? A full binding would be hard; but a binding sufficient for one or two datatype might not be. - Daniel
Daniel Herring
While boost::serialization prefers its own file format, HDF5 is a very open standard.
"The HDF5 data model, file format, API, library, and tools are open and distributed without charge." http://www.hdfgroup.org/HDF5/whatishdf5.html
I would love to see this kind of implementation, though I don't know much about the support for hdf5 in matlab. From a cursory review of the docs, it looks like it is pretty awful to work with in matlab. For better or worse, I think that most people end up using the 'save' function. I agree that matlab is proprietary and shouldn't be a core boost library, which means it probably should be in the numeric bindings. -Jesse
participants (6)
-
Daniel Herring
-
Diederick C. Niehorster
-
Gaetan Gaumer
-
James C. Sutherland
-
Jesse Perla
-
Robert Valkenburg