[mlpack-git] master: The arma::hdf5_binary type already transposes on load and save. (501ffa5)

gitdub at mlpack.org gitdub at mlpack.org
Tue Mar 22 15:02:03 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/758d2773e4165530839dd72f2311943e13952b34...501ffa545b9b80e93603388b651d829ae5631dff

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

commit 501ffa545b9b80e93603388b651d829ae5631dff
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Mar 22 15:00:50 2016 -0400

    The arma::hdf5_binary type already transposes on load and save.
    
    In the future this will need to be changed, I think, because probably I will
    attempt to change this behavior in upstream Armadillo.


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

501ffa545b9b80e93603388b651d829ae5631dff
 src/mlpack/core/data/load_impl.hpp | 9 +++++++--
 src/mlpack/core/data/save_impl.hpp | 6 ++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index bb96bce..dd621b2 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -283,8 +283,13 @@ bool Load(const std::string& filename,
     Log::Info << "Size is " << (transpose ? matrix.n_cols : matrix.n_rows)
         << " x " << (transpose ? matrix.n_rows : matrix.n_cols) << ".\n";
 
-  // Now transpose the matrix, if necessary.
-  if (transpose)
+  // Now transpose the matrix, if necessary.  Armadillo loads HDF5 matrices
+  // transposed, so we have to work around that.
+  if (transpose && loadType != arma::hdf5_binary)
+  {
+    inplace_transpose(matrix);
+  }
+  else if (!transpose && loadType == arma::hdf5_binary)
   {
     inplace_transpose(matrix);
   }
diff --git a/src/mlpack/core/data/save_impl.hpp b/src/mlpack/core/data/save_impl.hpp
index 933d5a9..ef1f29d 100644
--- a/src/mlpack/core/data/save_impl.hpp
+++ b/src/mlpack/core/data/save_impl.hpp
@@ -133,8 +133,10 @@ bool Save(const std::string& filename,
   Log::Info << "Saving " << stringType << " to '" << filename << "'."
       << std::endl;
 
-  // Transpose the matrix.
-  if (transpose)
+  // Transpose the matrix.  If we are saving HDF5, Armadillo already transposes
+  // this on save, so we don't need to.
+  if ((transpose && loadType != arma::hdf5_binary) ||
+      (!transpose && loadType == arma::hdf5_binary))
   {
     arma::Mat<eT> tmp = trans(matrix);
 




More information about the mlpack-git mailing list