[mlpack-git] master: inpace transpoce moved to load_impl.cpp (73d5ff9)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:16:57 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 73d5ff9535d71c9580d6d13fd7e3bd5e33099a0b
Author: Vladimir Glazachev <glazachev.vladimir at gmail.com>
Date: Tue Feb 24 01:57:27 2015 +0400
inpace transpoce moved to load_impl.cpp
>---------------------------------------------------------------
73d5ff9535d71c9580d6d13fd7e3bd5e33099a0b
src/mlpack/core/arma_extend/CMakeLists.txt | 1 -
src/mlpack/core/arma_extend/arma_extend.hpp | 3 --
.../core/arma_extend/fn_inplace_transpose.hpp | 21 ---------
src/mlpack/core/data/load_impl.hpp | 17 ++++++-
src/mlpack/tests/arma_extend_test.cpp | 52 ----------------------
src/mlpack/tests/load_save_test.cpp | 26 +++++++++++
6 files changed, 42 insertions(+), 78 deletions(-)
diff --git a/src/mlpack/core/arma_extend/CMakeLists.txt b/src/mlpack/core/arma_extend/CMakeLists.txt
index 36b8593..43f6ee1 100644
--- a/src/mlpack/core/arma_extend/CMakeLists.txt
+++ b/src/mlpack/core/arma_extend/CMakeLists.txt
@@ -3,7 +3,6 @@
set(SOURCES
arma_extend.hpp
fn_ccov.hpp
- fn_inplace_transpose.hpp
glue_ccov_meat.hpp
glue_ccov_proto.hpp
hdf5_misc.hpp
diff --git a/src/mlpack/core/arma_extend/arma_extend.hpp b/src/mlpack/core/arma_extend/arma_extend.hpp
index c3c2d98..ec50735 100644
--- a/src/mlpack/core/arma_extend/arma_extend.hpp
+++ b/src/mlpack/core/arma_extend/arma_extend.hpp
@@ -47,9 +47,6 @@ namespace arma {
// unary minus for sparse matrices
#include "operator_minus.hpp"
-
- // inplace_transpose()
- #include "fn_inplace_transpose.hpp"
};
#endif
diff --git a/src/mlpack/core/arma_extend/fn_inplace_transpose.hpp b/src/mlpack/core/arma_extend/fn_inplace_transpose.hpp
deleted file mode 100644
index 83e8bec..0000000
--- a/src/mlpack/core/arma_extend/fn_inplace_transpose.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-
-/**
- * This method automatically selects the transpose method,
- * depending on available memory.
- */
-template<typename eT>
-bool
-inline
-inplace_transpose(Mat<eT>& X)
- {
- try
- {
- X = trans(X);
- return false;
- }
- catch (std::bad_alloc& exception)
- {
- inplace_trans(X, "lowmem");
- return true;
- }
- }
diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index fee0e65..eede8a3 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -17,6 +17,21 @@ namespace mlpack {
namespace data {
template<typename eT>
+bool inline inplace_transpose(arma::Mat<eT>& X)
+{
+ try
+ {
+ X = arma::trans(X);
+ return false;
+ }
+ catch (std::bad_alloc& exception)
+ {
+ arma::inplace_trans(X, "lowmem");
+ return true;
+ }
+}
+
+template<typename eT>
bool Load(const std::string& filename,
arma::Mat<eT>& matrix,
bool fatal,
@@ -221,7 +236,7 @@ bool Load(const std::string& filename,
// Now transpose the matrix, if necessary.
if (transpose)
{
- arma::inplace_transpose(matrix);
+ inplace_transpose(matrix);
}
Timer::Stop("loading_data");
diff --git a/src/mlpack/tests/arma_extend_test.cpp b/src/mlpack/tests/arma_extend_test.cpp
index 10d5af6..13c7246 100644
--- a/src/mlpack/tests/arma_extend_test.cpp
+++ b/src/mlpack/tests/arma_extend_test.cpp
@@ -49,58 +49,6 @@ BOOST_AUTO_TEST_CASE(InplaceReshapeMatrixTest)
}
/**
- * Make sure we can still transpose correct.
- */
-BOOST_AUTO_TEST_CASE(InplaceTransposeTest)
-{
- mat X;
- X.randu(2, 4);
-
- mat Y = X;
-
- BOOST_REQUIRE(arma::inplace_transpose(X) == false);
- BOOST_REQUIRE_EQUAL(X.n_rows, 4);
- BOOST_REQUIRE_EQUAL(X.n_cols, 2);
-
- for (size_t i = 0; i < X.n_rows; ++i)
- for (size_t j = 0; j < X.n_cols; ++j)
- BOOST_REQUIRE_CLOSE(X.at(i, j), Y.at(j, i), 1e-5);
-}
-
-/**
- * Try to transpose using low-mem method.
- */
-BOOST_AUTO_TEST_CASE(InplaceTransposeLowMemTest)
-{
- mat X;
-
- int width = 1000;
- int height = 50000;
-
- size_t n_iters = 50;
-
- for (size_t i = 0; i < n_iters; ++i)
- {
- try
- {
- X.zeros(height, width);
- if (inplace_transpose(X))
- {
- break;
- }
- }
- catch (std::bad_alloc& exception)
- {
- BOOST_FAIL("bad_alloc exception.");
- }
- height *= 2;
- }
-
- BOOST_REQUIRE_EQUAL(X.n_rows, width);
- BOOST_REQUIRE_EQUAL(X.n_cols, height);
-}
-
-/**
* Test const_row_col_iterator for basic functionality.
*/
BOOST_AUTO_TEST_CASE(ConstRowColIteratorTest)
diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp
index 8b27ea2..0cfd51f 100644
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@ -101,6 +101,32 @@ BOOST_AUTO_TEST_CASE(SaveCSVTest)
}
/**
+ * Make sure CSVs can be loaded in transposed form.
+ */
+BOOST_AUTO_TEST_CASE(LoadTransposedCSVTest)
+{
+ std::fstream f;
+ f.open("test_file.csv", std::fstream::out);
+
+ f << "1, 2, 3, 4" << std::endl;
+ f << "5, 6, 7, 8" << std::endl;
+
+ f.close();
+
+ arma::mat test;
+ BOOST_REQUIRE(data::Load("test_file.csv", test, false, true) == true);
+
+ BOOST_REQUIRE_EQUAL(test.n_cols, 2);
+ BOOST_REQUIRE_EQUAL(test.n_rows, 4);
+
+ for (size_t i = 0; i < 8; ++i)
+ BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5);
+
+ // Remove the file.
+ remove("test_file.csv");
+}
+
+/**
* Make sure CSVs can be loaded in non-transposed form.
*/
BOOST_AUTO_TEST_CASE(LoadNonTransposedCSVTest)
More information about the mlpack-git
mailing list