Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72776 - sandbox/numpy/libs/python/numpy/test
From: seefeld_at_[hidden]
Date: 2011-06-27 10:07:55


Author: stefan
Date: 2011-06-27 10:07:54 EDT (Mon, 27 Jun 2011)
New Revision: 72776
URL: http://svn.boost.org/trac/boost/changeset/72776

Log:
Tidy indexing tests.
Text files modified:
   sandbox/numpy/libs/python/numpy/test/indexing.py | 34 ++++++++++++++--------------
   sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp | 48 +++++----------------------------------
   2 files changed, 24 insertions(+), 58 deletions(-)

Modified: sandbox/numpy/libs/python/numpy/test/indexing.py
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/indexing.py (original)
+++ sandbox/numpy/libs/python/numpy/test/indexing.py 2011-06-27 10:07:54 EDT (Mon, 27 Jun 2011)
@@ -4,24 +4,24 @@
 
 class TestIndexing(unittest.TestCase):
 
- def testSingle(self):
- x = numpy.arange(0,10)
- for i in range(0,10):
- indexing_mod.single(x,i,i)
- for i in range(-10,0):
- indexing_mod.single(x,i,10+i)
+ def testSingle(self):
+ x = numpy.arange(0,10)
+ for i in range(0,10):
+ numpy.testing.assert_equal(indexing_mod.single(x,i), i)
+ for i in range(-10,0):
+ numpy.testing.assert_equal(indexing_mod.single(x,i),10+i)
 
- def testSlice(self):
- x = numpy.arange(0,10)
- sl = slice(3,8)
- b = [3,4,5,6,7]
- indexing_mod.slice(x,sl,b)
+ def testSlice(self):
+ x = numpy.arange(0,10)
+ sl = slice(3,8)
+ b = [3,4,5,6,7]
+ numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
 
- def testStepSlice(self):
- x = numpy.arange(0,10)
- sl = slice(3,8,2)
- b = [3,5,7]
- indexing_mod.step_slice(x,sl,b)
+ def testStepSlice(self):
+ x = numpy.arange(0,10)
+ sl = slice(3,8,2)
+ b = [3,5,7]
+ numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
 
 if __name__=="__main__":
- unittest.main()
+ unittest.main()

Modified: sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp (original)
+++ sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp 2011-06-27 10:07:54 EDT (Mon, 27 Jun 2011)
@@ -1,48 +1,14 @@
 #include <boost/python/numpy.hpp>
-#include <assert.h>
 #include <boost/python/slice.hpp>
 
 namespace bp = boost::python;
 
-void single(bp::numpy::ndarray ndarr, int i,bp::object value) {
- bp::object element = bp::extract<bp::object>(ndarr[i]);
- assert(element == value);
-}
-
-
-void slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) {
- int start = bp::extract<int>(sl.start());
- int stop = bp::extract<int>(sl.stop());
- unsigned j=0;
- for (int i = start; i < stop; i++)
- {
- bp::object element = bp::extract<bp::object>(ndarr[i]);
- bp::object value = bp::extract<bp::object>(val[j]);
- assert(element == value);
- ++j;
- }
-}
-
+bp::object single(bp::numpy::ndarray ndarr, int i) { return ndarr[i];}
+bp::object slice(bp::numpy::ndarray ndarr, bp::slice sl) { return ndarr[sl];}
 
-void step_slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) {
- int start = bp::extract<int>(sl.start());
- int stop = bp::extract<int>(sl.stop());
- int step = bp::extract<int>(sl.step());
- unsigned j=0;
- for (int i = start; i < stop; i=i+step)
- {
- bp::object element = bp::extract<bp::object>(ndarr[i]);
- bp::object value = bp::extract<bp::object>(val[j]);
- assert(element == value);
- ++j;
- }
+BOOST_PYTHON_MODULE(indexing_mod)
+{
+ bp::numpy::initialize();
+ bp::def("single", single);
+ bp::def("slice", slice);
 }
-
-
-BOOST_PYTHON_MODULE(indexing_mod) {
- bp::numpy::initialize();
- bp::def("single",&single);
- bp::def("slice",&slice);
- bp::def("step_slice",&step_slice);
-}
-


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk