Re: [C++-sig] Stuck on accessing numpy.ndarray in c extension
My boost::python exporting code is as following: // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include "hello.c" // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ // Module ====================================================================== BOOST_PYTHON_MODULE(hello) { def("main", &main); def("testArray", &testArray); } -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601
Qinfeng(Javen) Shi writes:
My boost::python exporting code is as following:
// Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp>
// Includes ==================================================================== #include "hello.c" // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ // Module ====================================================================== BOOST_PYTHON_MODULE(hello) { def("main", &main); def("testArray", &testArray); }
You still have to initialize the function pointer array for the numpy interface using import_array(), just as you do with a C extension. For example, (using the boost::python::numeric): namespace ar=boost::python::numeric; namespace bp=boost::python; BOOST_PYTHON_MODULE(simple_ext) { import_array(); ar::array::set_module_and_type("numpy", "ndarray"); //global doc string bp::scope().attr("RCSID") = rcsid; std::string str1; str1="docstring for module\n"; bp::scope().attr("__doc__") = str1.c_str(); str1 = "Doc string for testToPython\n"; def("testToPython", testToPython,str1.c_str()); str1 = "Doc string for testFromPython\n"; def("testFromPython", testFromPython,str1.c_str()); }
participants (2)
-
Philip Austin -
Qinfeng(Javen) Shi