2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 05:42:30 +00:00

Added more tests for ndarray

This commit is contained in:
Ankit Daftery
2011-06-20 17:18:43 +00:00
parent 69d9f34f3e
commit 085f574d6e
2 changed files with 34 additions and 2 deletions

View File

@@ -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()

View File

@@ -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);
}