Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72694 - sandbox/numpy/libs/python/numpy/test
From: ankitdaf_at_[hidden]
Date: 2011-06-20 13:18:45


Author: ankitdaf
Date: 2011-06-20 13:18:43 EDT (Mon, 20 Jun 2011)
New Revision: 72694
URL: http://svn.boost.org/trac/boost/changeset/72694

Log:
Added more tests for ndarray
Text files modified:
   sandbox/numpy/libs/python/numpy/test/ndarray.py | 22 ++++++++++++++++++++--
   sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp | 14 ++++++++++++++
   2 files changed, 34 insertions(+), 2 deletions(-)

Modified: sandbox/numpy/libs/python/numpy/test/ndarray.py
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/ndarray.py (original)
+++ sandbox/numpy/libs/python/numpy/test/ndarray.py 2011-06-20 13:18:43 EDT (Mon, 20 Jun 2011)
@@ -36,9 +36,27 @@
                                 a1 = ndarray_mod.empty(shape,dt)
                                 a2 = ndarray_mod.c_empty(shape,dt)
                                 self.assertEqual(shape,a1.shape)
- #self.assert_(type(a1),dtp)
                                 self.assertEqual(shape,a2.shape)
- #self.assert_(dt,type(a2))
+
+ def testTranspose(self):
+ for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
+ dt = numpy.dtype(dtp)
+ for shape in ((6,10),(4,3,5),(2,2,3,5)):
+ a1 = numpy.empty(shape,dt)
+ a2 = a1.transpose()
+ a1 = ndarray_mod.transpose(a1)
+ self.assertEqual(a1.shape,a2.shape)
+
+ def testSqueeze(self):
+ a1 = numpy.array([[[3,4,5]]])
+ a2 = a1.squeeze()
+ a1 = ndarray_mod.squeeze(a1)
+ self.assertEqual(a1.shape,a2.shape)
+
+ def testReshape(self):
+ a1 = numpy.empty((2,2))
+ a2 = ndarray_mod.reshape(a1,(1,4))
+ self.assertEqual(a2.shape,(1,4))
 
 if __name__=="__main__":
         unittest.main()

Modified: sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp
==============================================================================
--- sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp (original)
+++ sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp 2011-06-20 13:18:43 EDT (Mon, 20 Jun 2011)
@@ -30,6 +30,17 @@
   return result;
 }
 
+bp::numpy::ndarray transpose(bp::numpy::ndarray arr) {
+ return arr.transpose();
+}
+
+bp::numpy::ndarray squeeze(bp::numpy::ndarray arr) {
+ return arr.squeeze();
+}
+
+bp::numpy::ndarray reshape(bp::numpy::ndarray arr,bp::tuple tup) {
+ return arr.reshape(tup);
+}
 BOOST_PYTHON_MODULE(ndarray_mod) {
         bp::numpy::initialize();
         bp::def("zeros", &zeros);
@@ -37,4 +48,7 @@
         bp::def("array",&array1);
         bp::def("empty",&empty1);
         bp::def("c_empty",&c_empty);
+ bp::def("transpose",&transpose);
+ bp::def("squeeze",&squeeze);
+ bp::def("reshape",&reshape);
 }


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