2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 19:12:16 +00:00

Added test for slices with steps. Auto-detection of step not implemented yet

This commit is contained in:
Ankit Daftery
2011-06-27 04:09:12 +00:00
parent 419b6ec973
commit fa51b58cd6
2 changed files with 24 additions and 3 deletions

View File

@@ -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()

View File

@@ -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<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 @@ void slice(bp::numpy::ndarray ndarr, bp::slice sl,bp::object val) {
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);
}