|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72686 - sandbox/numpy/libs/python/numpy/test
From: ankitdaf_at_[hidden]
Date: 2011-06-19 15:38:53
Author: ankitdaf
Date: 2011-06-19 15:38:51 EDT (Sun, 19 Jun 2011)
New Revision: 72686
URL: http://svn.boost.org/trac/boost/changeset/72686
Log:
Adding test for ndarray.Fails as of now.
Added:
sandbox/numpy/libs/python/numpy/test/ndarray.py (contents, props changed)
sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp (contents, props changed)
Added: sandbox/numpy/libs/python/numpy/test/ndarray.py
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/python/numpy/test/ndarray.py 2011-06-19 15:38:51 EDT (Sun, 19 Jun 2011)
@@ -0,0 +1,44 @@
+import ndarray_mod
+import unittest
+import numpy
+
+class TestNdarray(unittest.TestCase):
+
+ def testNdzeros(self):
+ for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
+ v = numpy.zeros(60, dtype=dtp)
+ dt = numpy.dtype(dtp)
+ for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)):
+ a1 = ndarray_mod.zeros(shape,dt)
+ a2 = v.reshape(a1.shape)
+ self.assertEqual(shape,a1.shape)
+ self.assert_((a1 == a2).all())
+
+ def testNdarray(self):
+ a = range(0,60)
+ for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
+ v = numpy.array(a, dtype=dtp)
+ dt = numpy.dtype(dtp)
+ a1 = ndarray_mod.array(a)
+ a2 = ndarray_mod.array(a,dt)
+ self.assert_((a1 == v).all())
+ self.assert_((a2 == v).all())
+ for shape in ((60,),(6,10),(4,3,5),(2,2,3,5)):
+ a1 = a1.reshape(shape)
+ self.assertEqual(shape,a1.shape)
+ a2 = a2.reshape(shape)
+ self.assertEqual(shape,a2.shape)
+
+ def testNdempty(self):
+ for dtp in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
+ 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))
+
+if __name__=="__main__":
+ unittest.main()
Added: sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/python/numpy/test/ndarray_mod.cpp 2011-06-19 15:38:51 EDT (Sun, 19 Jun 2011)
@@ -0,0 +1,34 @@
+#include <boost/python/numpy.hpp>
+
+namespace bp = boost::python;
+
+bp::numpy::ndarray zeros(bp::tuple shape, bp::numpy::dtype dt) {
+ return bp::numpy::zeros(shape, dt);
+}
+
+bp::numpy::ndarray array2(bp::object obj,bp::numpy::dtype dt) {
+ return bp::numpy::array(obj,dt);
+}
+
+bp::numpy::ndarray array1(bp::object obj) {
+ return bp::numpy::array(obj);
+}
+
+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<Py_intptr_t *>(c_tup);
+ return bp::numpy::empty(nd,c_shape,dt);
+}
+
+BOOST_PYTHON_MODULE(ndarray_mod) {
+ bp::numpy::initialize();
+ bp::def("zeros", &zeros);
+ bp::def("array",&array2);
+ bp::def("array",&array1);
+ bp::def("empty",&empty1);
+ bp::def("empty",&c_empty);
+}
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