Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <boost/numpy.hpp>
00007
00008 namespace p = boost::python;
00009 namespace np = boost::numpy;
00010
00011 np::ndarray zeros(p::tuple shape, np::dtype dt) { return np::zeros(shape, dt);}
00012 np::ndarray array2(p::object obj, np::dtype dt) { return np::array(obj,dt);}
00013 np::ndarray array1(p::object obj) { return np::array(obj);}
00014 np::ndarray empty1(p::tuple shape, np::dtype dt) { return np::empty(shape,dt);}
00015
00016 np::ndarray c_empty(p::tuple shape, np::dtype dt)
00017 {
00018
00019
00020 unsigned len = p::len(shape);
00021 Py_intptr_t *c_shape = new Py_intptr_t[len];
00022 for (unsigned i = 0; i != len; ++i)
00023 c_shape[i] = p::extract<Py_intptr_t>(shape[i]);
00024 np::ndarray result = np::empty(len, c_shape, dt);
00025 delete [] c_shape;
00026 return result;
00027 }
00028
00029 np::ndarray transpose(np::ndarray arr) { return arr.transpose();}
00030 np::ndarray squeeze(np::ndarray arr) { return arr.squeeze();}
00031 np::ndarray reshape(np::ndarray arr,p::tuple tup) { return arr.reshape(tup);}
00032
00033 BOOST_PYTHON_MODULE(ndarray_mod)
00034 {
00035 np::initialize();
00036 p::def("zeros", zeros);
00037 p::def("zeros_matrix", zeros, np::as_matrix<>());
00038 p::def("array", array2);
00039 p::def("array", array1);
00040 p::def("empty", empty1);
00041 p::def("c_empty", c_empty);
00042 p::def("transpose", transpose);
00043 p::def("squeeze", squeeze);
00044 p::def("reshape", reshape);
00045 }