diff --git a/libs/python/numpy/test/ndarray.py b/libs/python/numpy/test/ndarray.py index ebc032bd..c1f148b6 100644 --- a/libs/python/numpy/test/ndarray.py +++ b/libs/python/numpy/test/ndarray.py @@ -36,9 +36,27 @@ class TestNdarray(unittest.TestCase): 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() diff --git a/libs/python/numpy/test/ndarray_mod.cpp b/libs/python/numpy/test/ndarray_mod.cpp index f328060e..73a14c6a 100644 --- a/libs/python/numpy/test/ndarray_mod.cpp +++ b/libs/python/numpy/test/ndarray_mod.cpp @@ -30,6 +30,17 @@ bp::numpy::ndarray c_empty(bp::tuple shape, bp::numpy::dtype dt) { 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 @@ BOOST_PYTHON_MODULE(ndarray_mod) { 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); }