[mlpack-git] [mlpack] Serialize (#443)

Ryan Curtin notifications at github.com
Wed Jun 24 14:06:19 EDT 2015


This code is a start to the use of `boost::serialization` instead of the current `SaveRestoreUtility` mess.  If your mlpack class implements a `Serialize()` function, then you can use `boost::serialization` to save it:

```
MyClass myclass(...);
boost::archive::xml_oarchive oarch("my_file.xml"); // or binary_oarchive or text_oarchive
oarch << data::CreateNVP(myclass, "myclass"); // create a name-value pair for saving
```

and to load it:

```
MyClass myclass(...);
boost::archive::xml_iarchive iarch("my_file.xml"); // or binary_iarchive or text_iarchive
iarch >> data::CreateNVP(myclass, "myclass"); // use the same name-value pair as before
```

This involved writing a confusing, complex shim object so we could write `Serialize()` in accordance with the mlpack method naming guidelines instead of `serialize()`, for the sake of consistency.  Certainly there is more documentation to be done before a release; specifically, classes that use references are probably going to need some amount of refactoring (see what I had to do to `BinarySpaceTree`, for instance).

I've opened a PR instead of just merging it in, in order to give an opportunity to say "no, don't do it!".  I'll probably leave this open for a week or two before merging.
You can view, comment on, or merge this pull request online at:

  https://github.com/mlpack/mlpack/pull/443

-- Commit Summary --

  * Add wrapper for boost::serialization.
  * Add list of formats we can load.
  * Update CMakeLists.txt.
  * Convenience function for extracting extensions.
  * Add Load() and Save() for models.
  * Move serialization shim to data/.
  * Fix syntax and include errors.
  * Add boost::serialization to dependencies.
  * A few first tests for serialization.
  * Add serialization for arma::mat.
  * Add serialization for sparse matrices.
  * Refactor includes to include serialization code.
  * Add Serialize() to distributions.
  * Add tests for distribution Serialize().
  * Add Serialize() to kernels; not yet tested.
  * Add Range::Serialize().
  * Refactor and add Serialize().
  * Add Serialize() to MahalanobisDistance.
  * Clarify comments, fix accessors.
  * Add BallBound<>::Serialize().
  * Some serialization changes.
  * Allow serialization of linear regression.
  * Add shims for arrays.
  * Fix typo.
  * Comment out unused member.
  * Fix memory misuse.
  * Add shims for pointers.
  * Update comment for serialize() interception.
  * Add Serialize() for empty class.
  * Be safer with memory usage.
  * Add Serialize() for HRectBound<>.
  * Add some more tests.
  * A first pass at refactoring BinarySpaceTree.
  * Refactor tree test.
  * Merge branch 'master' into serialize
  * Refactor NeighborSearch internals to deal with the tree holding the dataset internally.
  * Refactor tests to deal with modified NeighborSearch.
  * Merge branch 'master' into serialize
  * Add serialization for statistic.
  * Fix memory leak when overwriting bounds.
  * Add BinarySpaceTree::Serialize() and tests.
  * Fix some style.
  * Remove unnecessary LastDistanceNode().
  * Add Serialize(); remove unnecessary LastDistanceNode().

-- File Changes --

    M CMakeLists.txt (1)
    M src/mlpack/core/arma_extend/Mat_extra_bones.hpp (4)
    M src/mlpack/core/arma_extend/Mat_extra_meat.hpp (32)
    M src/mlpack/core/arma_extend/SpMat_extra_bones.hpp (6)
    M src/mlpack/core/arma_extend/SpMat_extra_meat.hpp (34)
    M src/mlpack/core/arma_extend/arma_extend.hpp (5)
    M src/mlpack/core/data/CMakeLists.txt (3)
    A src/mlpack/core/data/extension.hpp (33)
    A src/mlpack/core/data/format.hpp (26)
    M src/mlpack/core/data/load.hpp (42)
    M src/mlpack/core/data/load_impl.hpp (109)
    M src/mlpack/core/data/save.hpp (40)
    M src/mlpack/core/data/save_impl.hpp (95)
    A src/mlpack/core/data/serialization_shim.hpp (575)
    M src/mlpack/core/dists/discrete_distribution.hpp (11)
    M src/mlpack/core/dists/gaussian_distribution.cpp (3)
    M src/mlpack/core/dists/gaussian_distribution.hpp (16)
    M src/mlpack/core/dists/laplace_distribution.hpp (10)
    M src/mlpack/core/dists/regression_distribution.hpp (23)
    M src/mlpack/core/kernels/cosine_distance.hpp (4)
    M src/mlpack/core/kernels/epanechnikov_kernel.hpp (6)
    M src/mlpack/core/kernels/epanechnikov_kernel_impl.hpp (9)
    M src/mlpack/core/kernels/example_kernel.hpp (7)
    M src/mlpack/core/kernels/gaussian_kernel.hpp (8)
    M src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp (8)
    M src/mlpack/core/kernels/laplacian_kernel.hpp (7)
    M src/mlpack/core/kernels/linear_kernel.hpp (4)
    M src/mlpack/core/kernels/polynomial_kernel.hpp (8)
    M src/mlpack/core/kernels/spherical_kernel.hpp (8)
    M src/mlpack/core/kernels/triangular_kernel.hpp (7)
    M src/mlpack/core/math/range.hpp (6)
    M src/mlpack/core/math/range_impl.hpp (8)
    M src/mlpack/core/metrics/ip_metric.hpp (16)
    M src/mlpack/core/metrics/ip_metric_impl.hpp (33)
    M src/mlpack/core/metrics/lmetric.hpp (4)
    M src/mlpack/core/metrics/mahalanobis_distance.hpp (4)
    M src/mlpack/core/metrics/mahalanobis_distance_impl.hpp (9)
    M src/mlpack/core/tree/ballbound.hpp (19)
    M src/mlpack/core/tree/ballbound_impl.hpp (21)
    M src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp (117)
    M src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp (229)
    M src/mlpack/core/tree/hrectbound.hpp (6)
    M src/mlpack/core/tree/hrectbound_impl.hpp (20)
    M src/mlpack/core/tree/statistic.hpp (8)
    M src/mlpack/core/util/sfinae_utility.hpp (1)
    M src/mlpack/methods/linear_regression/linear_regression.hpp (22)
    M src/mlpack/methods/neighbor_search/neighbor_search.hpp (11)
    M src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp (56)
    M src/mlpack/methods/neighbor_search/neighbor_search_stat.hpp (18)
    M src/mlpack/methods/range_search/range_search_stat.hpp (9)
    M src/mlpack/prereqs.hpp (5)
    M src/mlpack/tests/CMakeLists.txt (1)
    M src/mlpack/tests/allkfn_test.cpp (7)
    M src/mlpack/tests/allknn_test.cpp (7)
    M src/mlpack/tests/load_save_test.cpp (106)
    M src/mlpack/tests/range_search_test.cpp (1)
    A src/mlpack/tests/serialization_test.cpp (688)
    M src/mlpack/tests/tree_test.cpp (84)

-- Patch Links --

https://github.com/mlpack/mlpack/pull/443.patch
https://github.com/mlpack/mlpack/pull/443.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/443
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150624/30a0d58b/attachment.html>


More information about the mlpack-git mailing list