Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72772 - sandbox/numpy/libs/python/numpy/test
From: ankitdaf_at_[hidden]
Date: 2011-06-27 00:09:13


Author: ankitdaf
Date: 2011-06-27 00:09:12 EDT (Mon, 27 Jun 2011)
New Revision: 72772
URL: http://svn.boost.org/trac/boost/changeset/72772

Log:
Added test for slices with steps. Auto-detection of step not implemented yet
Text files modified:
   sandbox/numpy/libs/python/numpy/test/indexing.py | 6 ++++++
   sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp | 19 +++++++++++++++++--
   2 files changed, 23 insertions(+), 2 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 00:09:12 EDT (Mon, 27 Jun 2011)
@@ -17,5 +17,11 @@
                 b = [3,4,5,6,7]
                 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)
+
 if __name__=="__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 00:09:12 EDT (Mon, 27 Jun 2011)
@@ -11,7 +11,6 @@
 
 
 void slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) {
-// bp::object element = bp::extract<bp::object>(ndarr[sl]);
         int start = bp::extract<int>(sl.start());
         int stop = bp::extract<int>(sl.stop());
         unsigned j=0;
@@ -21,13 +20,29 @@
                         bp::object value = bp::extract<bp::object>(val[j]);
                         assert(element == value);
                         ++j;
- }
+ }
+}
+
 
+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);
+ 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