[mlpack-svn] r10063 - mlpack/trunk/src/mlpack/core/arma_extend
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Oct 28 21:51:10 EDT 2011
Author: rcurtin
Date: 2011-10-28 21:51:10 -0400 (Fri, 28 Oct 2011)
New Revision: 10063
Added:
mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_bones.hpp
mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_meat.hpp
Modified:
mlpack/trunk/src/mlpack/core/arma_extend/CMakeLists.txt
mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.h
Log:
Add extra Mat code to load a transposed matrix. The patch has not yet been
submitted to Conrad.
Modified: mlpack/trunk/src/mlpack/core/arma_extend/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/CMakeLists.txt 2011-10-28 22:39:15 UTC (rev 10062)
+++ mlpack/trunk/src/mlpack/core/arma_extend/CMakeLists.txt 2011-10-29 01:51:10 UTC (rev 10063)
@@ -3,6 +3,8 @@
# Define the files we need to compile.
# Anything not in this list will not be compiled into MLPACK.
set(SOURCES
+ Mat_extra_bones.hpp
+ Mat_extra_meat.hpp
arma_extend.h
fn_ccov.hpp
glue_ccov_meat.hpp
Added: mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_bones.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_bones.hpp (rev 0)
+++ mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_bones.hpp 2011-10-29 01:51:10 UTC (rev 10063)
@@ -0,0 +1,15 @@
+/**
+ * @file Mat_extra_bones.hpp
+ * @author Ryan Curtin
+ *
+ * Extra overload of load() and save() to allow transposition of matrix at load
+ * time and save time.
+ */
+
+inline bool load(const std::string name, const file_type type, const bool print_status, const bool transpose);
+
+inline bool load( std::istream& is, const file_type type, const bool print_status, const bool transpose);
+
+inline bool save(const std::string name, const file_type type, const bool print_status, const bool transpose);
+
+inline bool save( std::ostream& os, const file_type type, const bool print_status, const bool transpose);
Added: mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_meat.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_meat.hpp (rev 0)
+++ mlpack/trunk/src/mlpack/core/arma_extend/Mat_extra_meat.hpp 2011-10-29 01:51:10 UTC (rev 10063)
@@ -0,0 +1,74 @@
+/**
+ * @file Mat_extra_meat.hpp
+ * @author Ryan Curtin
+ *
+ * Extra overload of load() to allow transposition of matrix at load time.
+ */
+
+template<typename eT>
+inline
+bool
+Mat<eT>::load(const std::string name, const file_type type, const bool print_status, const bool transpose)
+ {
+ bool result = load(name, type, print_status);
+
+ if (transpose)
+ {
+ // Now transpose the matrix.
+ *this = trans(*this);
+ }
+
+ return result;
+ }
+
+template<typename eT>
+inline
+bool
+Mat<eT>::load(std::istream& is, const file_type type, const bool print_status, const bool transpose)
+ {
+ bool result = load(is, type, print_status);
+
+ if (transpose)
+ {
+ // Now transpose the matrix.
+ *this = trans(*this);
+ }
+
+ return result;
+ }
+
+template<typename eT>
+inline
+bool
+Mat<eT>::save(const std::string name, const file_type type, const bool print_status, const bool transpose)
+ {
+ if (transpose)
+ {
+ // Save a temporary matrix.
+ Mat<eT> tmp = trans(*this);
+
+ return tmp.save(name, type, print_status);
+ }
+ else
+ {
+ return save(name, type, print_status);
+ }
+ }
+
+template<typename eT>
+inline
+bool
+Mat<eT>::save(std::ostream& os, const file_type type, const bool print_status, const bool transpose)
+ {
+ if (transpose)
+ {
+ // Save a temporary matrix.
+ Mat<eT> tmp = trans(*this);
+
+ return tmp.save(os, type, print_status);
+ }
+ else
+ {
+ return save(os, type, print_status);
+ }
+ }
Modified: mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.h
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.h 2011-10-28 22:39:15 UTC (rev 10062)
+++ mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.h 2011-10-29 01:51:10 UTC (rev 10063)
@@ -7,18 +7,25 @@
* This will allow the use of the ccov() function (which performs the same
* function as cov(trans(X)) but without the cost of computing trans(X)).
*/
-
#ifndef __ARMA_EXTEND_H
#define __ARMA_EXTEND_H
-namespace arma {
- #include "typedef.hpp" // This has to come first.
-}
+// Define our own extensions. These will be included in Cube_bones.hpp (or
+// Cube_proto.hpp) and Mat_bones.hpp (or Mat_meat.hpp).
+#define ARMA_EXTRA_MAT_PROTO mlpack/core/arma_extend/Mat_extra_bones.hpp
+#define ARMA_EXTRA_MAT_PROTO mlpack/core/arma_extend/Mat_extra_bones.hpp
#include <armadillo>
+// To get CSV support on versions of Armadillo prior to 2.0.0, we'll do this. I
+// feel dirty, but I think it's the best we can do.
+#if (ARMA_VERSION_MAJOR < 2)
+ #define csv_ascii (ppm_binary + 1) // ppm_binary is the last in the old enums.
+#endif
+
namespace arma {
// 64-bit support
+ #include "typedef.hpp" // This has to come first.
#include "traits.hpp"
#include "promote_type.hpp"
@@ -28,6 +35,9 @@
#include "glue_ccov_proto.hpp"
#include "glue_ccov_meat.hpp"
#include "fn_ccov.hpp"
+
+ // Implementation of load and save functions allowing transposes.
+ #include "Mat_extra_meat.hpp"
};
#endif
More information about the mlpack-svn
mailing list