[mlpack] 288/324: Test sparse iterators, when we can.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:19 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 8ee1e454b699841cdf5a8c7cbe2ae1b377328111
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Tue Aug 5 15:34:20 2014 +0000

    Test sparse iterators, when we can.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16972 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/tests/arma_extend_test.cpp | 97 +++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/src/mlpack/tests/arma_extend_test.cpp b/src/mlpack/tests/arma_extend_test.cpp
index f523d4e..b3c6c69 100644
--- a/src/mlpack/tests/arma_extend_test.cpp
+++ b/src/mlpack/tests/arma_extend_test.cpp
@@ -145,4 +145,101 @@ BOOST_AUTO_TEST_CASE(RowColIteratorTest)
   it = X.begin_row(0);
 }
 
+// These tests don't work when the sparse iterators hold references and not
+// pointers internally because of the lack of default constructor.
+#if ARMA_VERSION_MAJOR > 4 || \
+    (ARMA_VERSION_MAJOR == 4 && ARMA_VERSION_MINOR > 320)
+
+/**
+ * Test sparse const_row_col_iterator for basic functionality.
+ */
+BOOST_AUTO_TEST_CASE(ConstSpRowColIteratorTest)
+{
+  sp_mat X(5, 5);
+  for (size_t i = 0; i < 5; ++i)
+    X.col(i) += i;
+
+  for (size_t i = 0; i < 5; ++i)
+    X.row(i) += 3 * i;
+
+  // Make sure default constructor works okay.
+  sp_mat::const_row_col_iterator it;
+  // Make sure ++ operator, operator* and comparison operators work fine.
+  size_t count = 1;
+  for (it = X.begin_row_col(); it != X.end_row_col(); it++)
+  {
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+
+    count++;
+  }
+  BOOST_REQUIRE_EQUAL(count, 25);
+  it = X.end_row_col();
+  do
+  {
+    it--;
+    count--;
+
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+  } while (it != X.begin_row_col());
+
+  BOOST_REQUIRE_EQUAL(count, 1);
+}
+
+/**
+ * Test sparse row_col_iterator for basic functionality.
+ */
+BOOST_AUTO_TEST_CASE(SpRowColIteratorTest)
+{
+  sp_mat X(5, 5);
+  for (size_t i = 0; i < 5; ++i)
+    X.col(i) += i;
+
+  for (size_t i = 0; i < 5; ++i)
+    X.row(i) += 3 * i;
+
+  // Make sure default constructor works okay.
+  sp_mat::row_col_iterator it;
+  // Make sure ++ operator, operator* and comparison operators work fine.
+  size_t count = 1;
+  for (it = X.begin_row_col(); it != X.end_row_col(); it++)
+  {
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+
+    count++;
+  }
+  BOOST_REQUIRE_EQUAL(count, 25);
+  it = X.end_row_col();
+  do
+  {
+    it--;
+    count--;
+
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+  } while (it != X.begin_row_col());
+
+  BOOST_REQUIRE_EQUAL(count, 1);
+}
+
+#endif
+
 BOOST_AUTO_TEST_SUITE_END();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list