Re: void * C array to a Numpy array using Swig
- From: "Travis E. Oliphant" <oliphant.travis@xxxxxxxx>
- Date: Thu, 12 Jan 2006 16:26:28 -0700
Krish wrote:
Hello People
I hope I am On Topic. Anyways, here is my problem. Any insights would be really appreciated.
Posting to the numpy-discussion@xxxxxxxxxxxxxxxxxxxxx list would help generate more responses, I think.
I have wrapped a C IO module using SWIG -> Python Module. Suppose the name of the module is "imageio" and the reader function from the file is image_read() which returns an object ( "filled" C structure) with a lot of members.
Let
a = imageio.image_read("testfile.image")
Now a is the object which contains pointer to data of the image. ( void * pdata). ( a also contains the datatype which I need to typecast to get the data pointed by pdata). My question is how to access the data pointed by pdata in *Python*.
Yes, you are right that you need to use typemaps. It's been awhile since I did this kind of thing, but here are some pointers.
1) Look at Michael Sanner's typemaps at
http://www.scripps.edu/mb/olson/people/sanner/html/Python/NumericTypemaps/
Except for the CHAR version, these should work for NumPy by replacing Numeric/arrayobject.h with numpy/arrayobject.h
2) In full scipy there are typemaps for numpy arrays in cluster/src/swig_num.i
Look here...
http://projects.scipy.org/scipy/scipy/file/trunk/Lib/cluster/src/swig_num.i
This should help you get started with some examples. Typemaps can be a little confusing at first, but they do make your interface a bit nicer.
-Travis
.
- Follow-Ups:
- Re: void * C array to a Numpy array using Swig
- From: Philip Austin
- Re: void * C array to a Numpy array using Swig
- References:
- void * C array to a Numpy array using Swig
- From: Krish
- void * C array to a Numpy array using Swig
- Prev by Date: Re: How can I make a dictionary that marks itself when it's modified?
- Next by Date: Re: How can I make a dictionary that marks itself when it's modified?
- Previous by thread: Re: void * C array to a Numpy array using Swig
- Next by thread: Re: void * C array to a Numpy array using Swig
- Index(es):
Relevant Pages
|