[mlpack-git] master: added test for ind2sub and sub2ind (05fcf0b)
gitdub at mlpack.org
gitdub at mlpack.org
Tue Jun 7 16:00:53 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/630efbe8c55e9072cc2be03a8033199ed2836177...b29bad9f77af89306ba48fb918c7772b72f19eac
>---------------------------------------------------------------
commit 05fcf0bc43f6ee18cbccca8c5558197b2c50f511
Author: nilayjain <nilayjain13 at gmail.com>
Date: Tue Jun 7 20:00:53 2016 +0000
added test for ind2sub and sub2ind
>---------------------------------------------------------------
05fcf0bc43f6ee18cbccca8c5558197b2c50f511
src/mlpack/tests/ind2sub_test.cpp | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/mlpack/tests/ind2sub_test.cpp b/src/mlpack/tests/ind2sub_test.cpp
index 14baeba..aaf1e78 100644
--- a/src/mlpack/tests/ind2sub_test.cpp
+++ b/src/mlpack/tests/ind2sub_test.cpp
@@ -1,19 +1,23 @@
#include <mlpack/core.hpp>
-//#include <mlpack/methods/edge_boxes/structured_tree.hpp>
-
#include <boost/test/unit_test.hpp>
#include "old_boost_test_definitions.hpp"
BOOST_AUTO_TEST_SUITE(ind2sub_test);
/**
- * This tests handles the case wherein only one class exists in the input
- * labels. It checks whether the only class supplied was the only class
- * predicted.
+ * This test checks whether ind2sub and sub2ind are
+ * compiled successfully and that they function properly.
*/
BOOST_AUTO_TEST_CASE(ind2sub_test)
{
- arma::mat A = arma::randu(5,5);
- arma::uvec u = arma::ind2sub(arma::size(A), 3);
- u.print();
+ arma::mat A = arma::randu(4,5);
+ size_t index = 13;
+ arma::uvec u = arma::ind2sub(arma::size(A), index);
+
+ BOOST_REQUIRE_EQUAL(u(0), index % A.n_rows);
+ BOOST_REQUIRE_EQUAL(u(1), index / A.n_rows);
+
+ index = arma::sub2ind(arma::size(A), u(0), u(1));
+ BOOST_REQUIRE_EQUAL(index, u(0) + u(1) * A.n_rows);
}
BOOST_AUTO_TEST_SUITE_END();
+
More information about the mlpack-git
mailing list