[mlpack-svn] r13471 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Aug 29 11:31:20 EDT 2012
Author: rcurtin
Date: 2012-08-29 11:31:19 -0400 (Wed, 29 Aug 2012)
New Revision: 13471
Added:
mlpack/trunk/src/mlpack/tests/arma_extend_test.cpp
Modified:
mlpack/trunk/src/mlpack/tests/CMakeLists.txt
Log:
Add a test for inplace_reshape().
Modified: mlpack/trunk/src/mlpack/tests/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2012-08-29 15:31:05 UTC (rev 13470)
+++ mlpack/trunk/src/mlpack/tests/CMakeLists.txt 2012-08-29 15:31:19 UTC (rev 13471)
@@ -5,6 +5,7 @@
mlpack_test.cpp
allkfn_test.cpp
allknn_test.cpp
+ arma_extend_test.cpp
aug_lagrangian_test.cpp
cli_test.cpp
distribution_test.cpp
Added: mlpack/trunk/src/mlpack/tests/arma_extend_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/arma_extend_test.cpp (rev 0)
+++ mlpack/trunk/src/mlpack/tests/arma_extend_test.cpp 2012-08-29 15:31:19 UTC (rev 13471)
@@ -0,0 +1,50 @@
+/**
+ * @file arma_extend_test.cpp
+ * @author Ryan Curtin
+ *
+ * Test of the MLPACK extensions to Armadillo.
+ */
+
+#include <mlpack/core.hpp>
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+
+BOOST_AUTO_TEST_SUITE(ArmaExtendTest);
+
+/**
+ * Make sure we can reshape a matrix in-place without changing anything.
+ */
+BOOST_AUTO_TEST_CASE(InplaceReshapeColumnTest)
+{
+ arma::mat X;
+ X.randu(1, 10);
+ arma::mat oldX = X;
+
+ arma::inplace_reshape(X, 2, 5);
+
+ BOOST_REQUIRE_EQUAL(X.n_rows, 2);
+ BOOST_REQUIRE_EQUAL(X.n_cols, 5);
+ for (size_t i = 0; i < 10; ++i)
+ BOOST_REQUIRE_CLOSE(X[i], oldX[i], 1e-5); // Order should be preserved.
+}
+
+/**
+ * Make sure we can reshape a large matrix.
+ */
+BOOST_AUTO_TEST_CASE(InplaceReshapeMatrixTest)
+{
+ arma::mat X;
+ X.randu(8, 10);
+ arma::mat oldX = X;
+
+ arma::inplace_reshape(X, 10, 8);
+
+ BOOST_REQUIRE_EQUAL(X.n_rows, 10);
+ BOOST_REQUIRE_EQUAL(X.n_cols, 8);
+ for (size_t i = 0; i < 80; ++i)
+ BOOST_REQUIRE_CLOSE(X[i], oldX[i], 1e-5); // Order should be preserved.
+}
+
+BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list