Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72741 - sandbox/numpy/libs/python/numpy/test
From: ankitdaf_at_[hidden]
Date: 2011-06-24 08:58:57


Author: ankitdaf
Date: 2011-06-24 08:58:57 EDT (Fri, 24 Jun 2011)
New Revision: 72741
URL: http://svn.boost.org/trac/boost/changeset/72741

Log:
Added tests for indexing
Added:
   sandbox/numpy/libs/python/numpy/test/indexing.py (contents, props changed)
   sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp (contents, props changed)
Text files modified:
   sandbox/numpy/libs/python/numpy/test/Jamfile | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/numpy/libs/python/numpy/test/Jamfile
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/Jamfile (original)
+++ sandbox/numpy/libs/python/numpy/test/Jamfile 2011-06-24 08:58:57 EDT (Fri, 24 Jun 2011)
@@ -18,5 +18,6 @@
     [ numpy-test ufunc ]
     [ numpy-test shapes ]
     [ numpy-test ndarray ]
+ [ numpy-test indexing ]
 
   ;

Added: sandbox/numpy/libs/python/numpy/test/indexing.py
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/python/numpy/test/indexing.py 2011-06-24 08:58:57 EDT (Fri, 24 Jun 2011)
@@ -0,0 +1,21 @@
+import unittest
+import numpy
+import indexing_mod
+
+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 testSlice(self):
+ x = numpy.arange(0,10)
+ sl = slice(3,8)
+ b = [3,4,5,6,7]
+ indexing_mod.slice(x,sl,b)
+
+if __name__=="__main__":
+ unittest.main()

Added: sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/python/numpy/test/indexing_mod.cpp 2011-06-24 08:58:57 EDT (Fri, 24 Jun 2011)
@@ -0,0 +1,33 @@
+#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) {
+// 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;
+ 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;
+ }
+
+}
+
+BOOST_PYTHON_MODULE(indexing_mod) {
+ bp::numpy::initialize();
+ bp::def("single",&single);
+ bp::def("slice",&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