Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72808 - sandbox/numpy/libs/python/numpy/test
From: ankitdaf_at_[hidden]
Date: 2011-06-29 22:50:41


Author: ankitdaf
Date: 2011-06-29 22:50:40 EDT (Wed, 29 Jun 2011)
New Revision: 72808
URL: http://svn.boost.org/trac/boost/changeset/72808

Log:
Added index array and boolean tests
Text files modified:
   sandbox/numpy/libs/python/numpy/test/indexing.py | 59 +++++++++++++++++++++++++++------------
   sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp | 13 ++++++--
   2 files changed, 50 insertions(+), 22 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-29 22:50:40 EDT (Wed, 29 Jun 2011)
@@ -4,24 +4,45 @@
 
 class TestIndexing(unittest.TestCase):
 
- 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]
- 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]
- numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
+ 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]
+ 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]
+ numpy.testing.assert_equal(indexing_mod.slice(x,sl), b)
+
+ def testIndex(self):
+ x = numpy.arange(0,10)
+ chk = numpy.array([3,4,5,6])
+ numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
+ chk = numpy.array([[0,1],[2,3]])
+ numpy.testing.assert_equal(indexing_mod.indexarray(x,chk),chk)
+# x = numpy.arange(9).reshape(3,3)
+# y = numpy.array([0,1])
+# z = numpy.array([0,2])
+# chk = numpy.array([0,5])
+# numpy.testing.assert_equal(indexing_mod.indexarray(x,y,z),chk) # This throws an assertion error, indicates shape mismatch
+ x = numpy.arange(0,10)
+ b = x>4
+ chk = numpy.array([5,6,7,8,9])
+ numpy.testing.assert_equal(indexing_mod.indexarray(x,b),chk)
+ x = numpy.arange(9).reshape(3,3)
+ b = numpy.array([0,2])
+ sl = slice(0,2)
+ chk = numpy.array([[0,1,2],[6,7,8]])
+ numpy.testing.assert_equal(indexing_mod.indexslice(x,b,sl),chk)
 
 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-29 22:50:40 EDT (Wed, 29 Jun 2011)
@@ -5,10 +5,17 @@
 
 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];}
+bp::object indexarray(bp::numpy::ndarray ndarr, bp::numpy::ndarray d1) { return ndarr[d1];}
+bp::object indexarray_2d(bp::numpy::ndarray ndarr, bp::numpy::ndarray d1,bp::numpy::ndarray d2) { return ndarr[d1][d2];}
+bp::object indexslice(bp::numpy::ndarray ndarr, bp::numpy::ndarray d1,bp::slice sl) { return ndarr[d1][sl];}
 
 BOOST_PYTHON_MODULE(indexing_mod)
 {
- bp::numpy::initialize();
- bp::def("single", single);
- bp::def("slice", slice);
+ bp::numpy::initialize();
+ bp::def("single", &single);
+ bp::def("slice", &slice);
+ bp::def("indexarray", &indexarray);
+ bp::def("indexarray", &indexarray_2d);
+ bp::def("indexslice", &indexslice);
+
 }


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