[mlpack-svn] r13854 - mlpack/trunk/src/mlpack/core/data

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Nov 7 18:15:50 EST 2012


Author: rcurtin
Date: 2012-11-07 18:15:50 -0500 (Wed, 07 Nov 2012)
New Revision: 13854

Modified:
   mlpack/trunk/src/mlpack/core/data/load.hpp
   mlpack/trunk/src/mlpack/core/data/load_impl.hpp
   mlpack/trunk/src/mlpack/core/data/save.hpp
   mlpack/trunk/src/mlpack/core/data/save_impl.hpp
Log:
Bake in support for HDF5 -- if Armadillo has it.


Modified: mlpack/trunk/src/mlpack/core/data/load.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/data/load.hpp	2012-11-07 23:14:58 UTC (rev 13853)
+++ mlpack/trunk/src/mlpack/core/data/load.hpp	2012-11-07 23:15:50 UTC (rev 13854)
@@ -30,6 +30,7 @@
  *  - PPM (ppm_binary), denoted by .ppm
  *  - Raw binary (raw_binary), denoted by .bin
  *  - Armadillo binary (arma_binary), denoted by .bin
+ *  - HDF5, denoted by .hdf, .hdf5, .h5, or .he5
  *
  * If the file extension is not one of those types, an error will be given.
  * This is preferable to Armadillo's default behavior of loading an unknown

Modified: mlpack/trunk/src/mlpack/core/data/load_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/data/load_impl.hpp	2012-11-07 23:14:58 UTC (rev 13853)
+++ mlpack/trunk/src/mlpack/core/data/load_impl.hpp	2012-11-07 23:15:50 UTC (rev 13854)
@@ -10,6 +10,7 @@
 // In case it hasn't already been included.
 #include "load.hpp"
 
+#include <algorithm>
 #include <mlpack/core/util/timers.hpp>
 
 namespace mlpack {
@@ -37,7 +38,10 @@
     return false;
   }
 
+  // Get the extension and force it to lowercase.
   std::string extension = filename.substr(ext + 1);
+  std::transform(extension.begin(), extension.end(), extension.begin(),
+      ::tolower);
 
   // Catch nonexistent files by opening the stream ourselves.
   std::fstream stream;
@@ -130,6 +134,25 @@
     loadType = arma::pgm_binary;
     stringType = "PGM data";
   }
+  else if (extension == "h5" || extension == "hdf5" || extension == "hdf" ||
+           extension == "he5")
+  {
+#ifdef ARMA_USE_HDF5
+    loadType = arma::hdf5_binary;
+    stringType = "HDF5 data";
+#else
+    if (fatal)
+      Log::Fatal << "Attempted to load '" << filename << "' as HDF5 data, but "
+          << "Armadillo was compiled without HDF5 support.  Load failed."
+          << std::endl;
+    else
+      Log::Warn << "Attempted to load '" << filename << "' as HDF5 data, but "
+          << "Armadillo was compiled without HDF5 support.  Load failed."
+          << std::endl;
+
+    return false;
+#endif
+  }
   else // Unknown extension...
   {
     unknownType = true;

Modified: mlpack/trunk/src/mlpack/core/data/save.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/data/save.hpp	2012-11-07 23:14:58 UTC (rev 13853)
+++ mlpack/trunk/src/mlpack/core/data/save.hpp	2012-11-07 23:15:50 UTC (rev 13854)
@@ -30,6 +30,7 @@
  *  - PPM (ppm_binary), denoted by .ppm
  *  - Raw binary (raw_binary), denoted by .bin
  *  - Armadillo binary (arma_binary), denoted by .bin
+ *  - HDF5 (hdf5_binary), denoted by .hdf5, .hdf, .h5, or .he5
  *
  * If the file extension is not one of those types, an error will be given.  If
  * the 'fatal' parameter is set to true, an error will cause the program to

Modified: mlpack/trunk/src/mlpack/core/data/save_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/data/save_impl.hpp	2012-11-07 23:14:58 UTC (rev 13853)
+++ mlpack/trunk/src/mlpack/core/data/save_impl.hpp	2012-11-07 23:15:50 UTC (rev 13854)
@@ -78,6 +78,25 @@
     saveType = arma::pgm_binary;
     stringType = "PGM data";
   }
+  else if (extension == "h5" || extension == "hdf5" || extension == "hdf" ||
+           extension == "he5")
+  {
+#ifdef ARMA_USE_HDF5
+    saveType = arma::hdf5_binary;
+    stringType = "HDF5 data";
+#else
+    if (fatal)
+      Log::Fatal << "Attempted to save HDF5 data to '" << filename << "', but "
+          << "Armadillo was compiled without HDF5 support.  Save failed."
+          << std::endl;
+    else
+      Log::Warn << "Attempted to save HDF5 data to '" << filename << "', but "
+          << "Armadillo was compiled without HDF5 support.  Save failed."
+          << std::endl;
+
+    return false;
+#endif
+  }
   else
   {
     unknownType = true;




More information about the mlpack-svn mailing list