[prev in list] [next in list] [prev in thread] [next in thread]
List: python-cpp-sig
Subject: [C++-sig] Stuck on accessing numpy.ndarray in c extension
From: paustin () eos ! ubc ! ca (Philip Austin)
Date: 2006-09-25 18:11:14
Message-ID: 17688.7106.337767.907995 () thrush ! eos ! ubc ! ca
[Download RAW message or body]
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());
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic