[mlpack-git] master, mlpack-1.0.x: Stop timers correctly when Log::Fatal is called (or when Load() or Save() return early). (2955359)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:44:32 EST 2015


Repository : https://github.com/mlpack/mlpack

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 29553593d3c6ed05468bdd3c7be7f1669a703788
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Feb 20 14:53:07 2014 +0000

    Stop timers correctly when Log::Fatal is called (or when Load() or Save() return
    early).


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

29553593d3c6ed05468bdd3c7be7f1669a703788
 src/mlpack/core/data/load_impl.hpp | 11 +++++++----
 src/mlpack/core/data/save_impl.hpp | 12 ++++++++----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 88c40c5..44f4e88 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -28,6 +28,7 @@ bool Load(const std::string& filename,
   size_t ext = filename.rfind('.');
   if (ext == std::string::npos)
   {
+    Timer::Stop("loading_data");
     if (fatal)
       Log::Fatal << "Cannot determine type of file '" << filename << "'; "
           << "no extension is present." << std::endl;
@@ -35,7 +36,6 @@ bool Load(const std::string& filename,
       Log::Warn << "Cannot determine type of file '" << filename << "'; "
           << "no extension is present.  Load failed." << std::endl;
 
-    Timer::Stop("loading_data");
     return false;
   }
 
@@ -50,13 +50,13 @@ bool Load(const std::string& filename,
 
   if (!stream.is_open())
   {
+    Timer::Stop("loading_data");
     if (fatal)
       Log::Fatal << "Cannot open file '" << filename << "'. " << std::endl;
     else
       Log::Warn << "Cannot open file '" << filename << "'; load failed."
           << std::endl;
 
-    Timer::Stop("loading_data");
     return false;
   }
 
@@ -143,6 +143,7 @@ bool Load(const std::string& filename,
     loadType = arma::hdf5_binary;
     stringType = "HDF5 data";
 #else
+    Timer::Stop("loading_data");
     if (fatal)
       Log::Fatal << "Attempted to load '" << filename << "' as HDF5 data, but "
           << "Armadillo was compiled without HDF5 support.  Load failed."
@@ -152,7 +153,6 @@ bool Load(const std::string& filename,
           << "Armadillo was compiled without HDF5 support.  Load failed."
           << std::endl;
 
-    Timer::Stop("loading_data");
     return false;
 #endif
   }
@@ -166,6 +166,7 @@ bool Load(const std::string& filename,
   // Provide error if we don't know the type.
   if (unknownType)
   {
+    Timer::Stop("loading_data");
     if (fatal)
       Log::Fatal << "Unable to detect type of '" << filename << "'; "
           << "incorrect extension?" << std::endl;
@@ -173,7 +174,6 @@ bool Load(const std::string& filename,
       Log::Warn << "Unable to detect type of '" << filename << "'; load failed."
           << " Incorrect extension?" << std::endl;
 
-    Timer::Stop("loading_data");
     return false;
   }
 
@@ -190,10 +190,13 @@ bool Load(const std::string& filename,
   if (!success)
   {
     Log::Info << std::endl;
+    Timer::Stop("loading_data");
     if (fatal)
       Log::Fatal << "Loading from '" << filename << "' failed." << std::endl;
     else
       Log::Warn << "Loading from '" << filename << "' failed." << std::endl;
+
+    return false;
   }
   else
     Log::Info << "Size is " << (transpose ? matrix.n_cols : matrix.n_rows)
diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp
index d41dfb7..2581e16 100644
--- a/src/mlpack/core/data/save_impl.hpp
+++ b/src/mlpack/core/data/save_impl.hpp
@@ -25,6 +25,7 @@ bool Save(const std::string& filename,
   size_t ext = filename.rfind('.');
   if (ext == std::string::npos)
   {
+    Timer::Stop("saving_data");
     if (fatal)
       Log::Fatal << "No extension given with filename '" << filename << "'; "
           << "type unknown.  Save failed." << std::endl;
@@ -44,6 +45,7 @@ bool Save(const std::string& filename,
 
   if (!stream.is_open())
   {
+    Timer::Stop("saving_data");
     if (fatal)
       Log::Fatal << "Cannot open file '" << filename << "' for writing. "
           << "Save failed." << std::endl;
@@ -51,7 +53,6 @@ bool Save(const std::string& filename,
       Log::Warn << "Cannot open file '" << filename << "' for writing; save "
           << "failed." << std::endl;
 
-    Timer::Stop("saving_data");
     return false;
   }
 
@@ -86,6 +87,7 @@ bool Save(const std::string& filename,
     saveType = arma::hdf5_binary;
     stringType = "HDF5 data";
 #else
+    Timer::Stop("saving_data");
     if (fatal)
       Log::Fatal << "Attempted to save HDF5 data to '" << filename << "', but "
           << "Armadillo was compiled without HDF5 support.  Save failed."
@@ -95,7 +97,6 @@ bool Save(const std::string& filename,
           << "Armadillo was compiled without HDF5 support.  Save failed."
           << std::endl;
 
-    Timer::Stop("saving_data");
     return false;
 #endif
   }
@@ -109,12 +110,15 @@ bool Save(const std::string& filename,
   // Provide error if we don't know the type.
   if (unknownType)
   {
+    Timer::Stop("saving_data");
     if (fatal)
       Log::Fatal << "Unable to determine format to save to from filename '"
           << filename << "'.  Save failed." << std::endl;
     else
       Log::Warn << "Unable to determine format to save to from filename '"
           << filename << "'.  Save failed." << std::endl;
+
+    return false;
   }
 
   // Try to save the file.
@@ -128,12 +132,12 @@ bool Save(const std::string& filename,
 
     if (!tmp.quiet_save(stream, saveType))
     {
+      Timer::Stop("saving_data");
       if (fatal)
         Log::Fatal << "Save to '" << filename << "' failed." << std::endl;
       else
         Log::Warn << "Save to '" << filename << "' failed." << std::endl;
 
-      Timer::Stop("saving_data");
       return false;
     }
   }
@@ -141,12 +145,12 @@ bool Save(const std::string& filename,
   {
     if (!matrix.quiet_save(stream, saveType))
     {
+      Timer::Stop("saving_data");
       if (fatal)
         Log::Fatal << "Save to '" << filename << "' failed." << std::endl;
       else
         Log::Warn << "Save to '" << filename << "' failed." << std::endl;
 
-      Timer::Stop("saving_data");
       return false;
     }
   }



More information about the mlpack-git mailing list