[mlpack-git] master: Handle loading and saving HDF5 datasets correctly. (5ca7299)

gitdub at mlpack.org gitdub at mlpack.org
Mon Mar 21 17:41:17 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/24a224ab0465e8185118ce4120441490a25ab7be...5ca72999bd92a7d0f89eaf072c499354d0e4c1ff

>---------------------------------------------------------------

commit 5ca72999bd92a7d0f89eaf072c499354d0e4c1ff
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Mar 21 17:41:17 2016 -0400

    Handle loading and saving HDF5 datasets correctly.


>---------------------------------------------------------------

5ca72999bd92a7d0f89eaf072c499354d0e4c1ff
 src/mlpack/core/data/load_impl.hpp |  7 ++++++-
 src/mlpack/core/data/save_impl.hpp | 12 ++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 4026bd9..bb96bce 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -261,7 +261,12 @@ bool Load(const std::string& filename,
     Log::Info << "Loading '" << filename << "' as " << stringType << ".  "
         << std::flush;
 
-  const bool success = matrix.load(stream, loadType);
+  // We can't use the stream if the type is HDF5.
+  bool success;
+  if (loadType != arma::hdf5_binary)
+    success = matrix.load(stream, loadType);
+  else
+    success = matrix.load(filename, loadType);
 
   if (!success)
   {
diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp
index 0dd302e..933d5a9 100644
--- a/src/mlpack/core/data/save_impl.hpp
+++ b/src/mlpack/core/data/save_impl.hpp
@@ -138,7 +138,11 @@ bool Save(const std::string& filename,
   {
     arma::Mat<eT> tmp = trans(matrix);
 
-    if (!tmp.quiet_save(stream, saveType))
+    // We can't save with streams for HDF5.
+    const bool success = (saveType == arma::hdf5_binary) ?
+        tmp.quiet_save(filename, saveType) :
+        tmp.quiet_save(stream, saveType);
+    if (!success)
     {
       Timer::Stop("saving_data");
       if (fatal)
@@ -151,7 +155,11 @@ bool Save(const std::string& filename,
   }
   else
   {
-    if (!matrix.quiet_save(stream, saveType))
+    // We can't save with streams for HDF5.
+    const bool success = (saveType == arma::hdf5_binary) ?
+        matrix.quiet_save(filename, saveType) :
+        matrix.quiet_save(stream, saveType);
+    if (!success)
     {
       Timer::Stop("saving_data");
       if (fatal)




More information about the mlpack-git mailing list