From 36ee7d23f9e2073c8321f7287c27042a73f57ed4 Mon Sep 17 00:00:00 2001 From: Stefan Seefeld Date: Sun, 19 Jun 2011 20:08:48 +0000 Subject: [PATCH] Fix ndarray tests. --- libs/python/numpy/test/Jamfile | 3 ++- libs/python/numpy/test/ndarray.py | 10 +++++----- libs/python/numpy/test/ndarray_mod.cpp | 14 +++++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libs/python/numpy/test/Jamfile b/libs/python/numpy/test/Jamfile index fdd66c4b..9d335382 100644 --- a/libs/python/numpy/test/Jamfile +++ b/libs/python/numpy/test/Jamfile @@ -16,6 +16,7 @@ test-suite numpy [ numpy-test templates ] [ numpy-test ufunc ] - [ numpy-test shapes ] + [ numpy-test shapes ] + [ numpy-test ndarray ] ; diff --git a/libs/python/numpy/test/ndarray.py b/libs/python/numpy/test/ndarray.py index 905e7cab..8ec85a80 100644 --- a/libs/python/numpy/test/ndarray.py +++ b/libs/python/numpy/test/ndarray.py @@ -34,11 +34,11 @@ class TestNdarray(unittest.TestCase): dt = numpy.dtype(dtp) for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)): a1 = ndarray_mod.empty(shape,dt) - a2 = ndarray_mod.empty(len(shape),shape,dt) - self.assert_(shape,a1.shape) - self.assert_(type(a1),dtp) - self.assert_(shape,a2.shape) - self.assert_(dt,type(a2)) + a2 = ndarray_mod.c_empty(shape,dt) + self.assertEqual(shape,a1.shape) + #self.assert_(type(a1),dtp) + self.assertEqual(shape,a2.shape) + #self.assert_(dtp,type(a2)) if __name__=="__main__": unittest.main() diff --git a/libs/python/numpy/test/ndarray_mod.cpp b/libs/python/numpy/test/ndarray_mod.cpp index 9ec2a7a1..355fb18d 100644 --- a/libs/python/numpy/test/ndarray_mod.cpp +++ b/libs/python/numpy/test/ndarray_mod.cpp @@ -18,10 +18,14 @@ bp::numpy::ndarray empty1(bp::tuple shape, bp::numpy::dtype dt) { return bp::numpy::empty(shape,dt); } -bp::numpy::ndarray c_empty(int nd,bp::tuple shape, bp::numpy::dtype dt) { - bp::tuple c_tup = bp::make_tuple(shape); - Py_intptr_t* c_shape = bp::extract(c_tup); - return bp::numpy::empty(nd,c_shape,dt); +bp::numpy::ndarray c_empty(bp::tuple shape, bp::numpy::dtype dt) { + // convert 'shape' to a C array so we can test the corresponding + // version of the constructor + unsigned len = bp::len(shape); + Py_intptr_t *c_shape = new Py_intptr_t[len]; + for (unsigned i = 0; i != len; ++i) + c_shape[i] = bp::extract(shape[i]); + return bp::numpy::empty(len, c_shape, dt); } BOOST_PYTHON_MODULE(ndarray_mod) { @@ -30,5 +34,5 @@ BOOST_PYTHON_MODULE(ndarray_mod) { bp::def("array",&array2); bp::def("array",&array1); bp::def("empty",&empty1); - bp::def("empty",&c_empty); + bp::def("c_empty",&c_empty); }