diff --git a/libs/python/numpy/test/indexing.py b/libs/python/numpy/test/indexing.py index 0b4986c5..0515784d 100644 --- a/libs/python/numpy/test/indexing.py +++ b/libs/python/numpy/test/indexing.py @@ -17,5 +17,11 @@ class TestIndexing(unittest.TestCase): 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() diff --git a/libs/python/numpy/test/indexing_mod.cpp b/libs/python/numpy/test/indexing_mod.cpp index 9adf7674..c65f3e7e 100644 --- a/libs/python/numpy/test/indexing_mod.cpp +++ b/libs/python/numpy/test/indexing_mod.cpp @@ -11,7 +11,6 @@ void single(bp::numpy::ndarray ndarr, int i,bp::object value) { void slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) { -// bp::object element = bp::extract(ndarr[sl]); int start = bp::extract(sl.start()); int stop = bp::extract(sl.stop()); unsigned j=0; @@ -21,13 +20,29 @@ void slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) { bp::object value = bp::extract(val[j]); assert(element == value); ++j; - } - + } } + +void step_slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) { + int start = bp::extract(sl.start()); + int stop = bp::extract(sl.stop()); + int step = bp::extract(sl.step()); + unsigned j=0; + for (int i = start; i < stop; i=i+step) + { + bp::object element = bp::extract(ndarr[i]); + bp::object value = bp::extract(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); }